import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.auth.github.GsonRepositoryPermissions;
-import org.sonar.db.provisioning.GithubPermissionsMappingDto;
+import org.sonar.db.provisioning.DevOpsPermissionsMappingDto;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
.collect(toMap(identity(), sonarqubeRoles::contains));
}
- public Set<String> toSonarqubeRolesWithFallbackOnRepositoryPermissions(Set<GithubPermissionsMappingDto> allPermissionsMappings,
+ public Set<String> toSonarqubeRolesWithFallbackOnRepositoryPermissions(Set<DevOpsPermissionsMappingDto> allPermissionsMappings,
String githubRoleOrPermission, GsonRepositoryPermissions repositoryPermissions) {
String roleName = toRoleName(githubRoleOrPermission);
return toSonarqubeRoles(allPermissionsMappings, roleName, repositoryPermissions);
return GITHUB_GROUP_PERMISSION_TO_ROLE_NAME.getOrDefault(permission, permission);
}
- public Set<String> toSonarqubeRolesForDefaultRepositoryPermission(Set<GithubPermissionsMappingDto> allPermissionsMappings, String roleName) {
+ public Set<String> toSonarqubeRolesForDefaultRepositoryPermission(Set<DevOpsPermissionsMappingDto> allPermissionsMappings, String roleName) {
return toSonarqubeRoles(allPermissionsMappings, roleName, null);
}
- private static Set<String> toSonarqubeRoles(Set<GithubPermissionsMappingDto> allPermissionsMappings, String githubRoleName,
+ private static Set<String> toSonarqubeRoles(Set<DevOpsPermissionsMappingDto> allPermissionsMappings, String githubRoleName,
@Nullable GsonRepositoryPermissions repositoryPermissions) {
- Map<String, List<GithubPermissionsMappingDto>> permissionMappings = allPermissionsMappings.stream()
- .collect(Collectors.groupingBy(GithubPermissionsMappingDto::githubRole));
+ Map<String, List<DevOpsPermissionsMappingDto>> permissionMappings = allPermissionsMappings.stream()
+ .collect(Collectors.groupingBy(DevOpsPermissionsMappingDto::role));
Set<String> sonarqubePermissions = Optional.ofNullable(permissionMappings.get(githubRoleName))
.orElse(GithubPermissionConverter.computeBaseRoleAndGetSqPermissions(permissionMappings, repositoryPermissions))
.stream()
- .map(GithubPermissionsMappingDto::sonarqubePermission)
+ .map(DevOpsPermissionsMappingDto::sonarqubePermission)
.collect(Collectors.toSet());
if (sonarqubePermissions.isEmpty()) {
return sonarqubePermissions;
}
- private static List<GithubPermissionsMappingDto> computeBaseRoleAndGetSqPermissions(Map<String, List<GithubPermissionsMappingDto>> permissionMappings,
+ private static List<DevOpsPermissionsMappingDto> computeBaseRoleAndGetSqPermissions(Map<String, List<DevOpsPermissionsMappingDto>> permissionMappings,
@Nullable GsonRepositoryPermissions repositoryPermissions) {
return Optional.ofNullable(repositoryPermissions)
.map(GITHUB_PERMISSION_TO_GITHUB_BASE_ROLE::get)
import org.junit.runners.Parameterized;
import org.junit.runners.Suite;
import org.sonar.auth.github.GsonRepositoryPermissions;
-import org.sonar.db.provisioning.GithubPermissionsMappingDto;
+import org.sonar.db.provisioning.DevOpsPermissionsMappingDto;
import static org.assertj.core.api.Assertions.assertThat;
})
public class GithubPermissionConverterTest {
- private static final Set<GithubPermissionsMappingDto> ALL_PERMISSIONS_MAPPING_FROM_DB = Set.of(
- new GithubPermissionsMappingDto("uuid1", "read", "roleRead"),
- new GithubPermissionsMappingDto("uuid2", "triage", "roleTriage"),
- new GithubPermissionsMappingDto("uuid3", "write", "roleWrite"),
- new GithubPermissionsMappingDto("uuid4", "maintain", "roleMaintain"),
- new GithubPermissionsMappingDto("uuid5", "admin", "roleAdmin")
+ private static final Set<DevOpsPermissionsMappingDto> ALL_PERMISSIONS_MAPPING_FROM_DB = Set.of(
+ new DevOpsPermissionsMappingDto("uuid1", "github", "read", "roleRead"),
+ new DevOpsPermissionsMappingDto("uuid2", "github", "triage", "roleTriage"),
+ new DevOpsPermissionsMappingDto("uuid3", "github", "write", "roleWrite"),
+ new DevOpsPermissionsMappingDto("uuid4", "github", "maintain", "roleMaintain"),
+ new DevOpsPermissionsMappingDto("uuid5", "github", "admin", "roleAdmin")
) ;
private static final GsonRepositoryPermissions NO_PERMS = new GsonRepositoryPermissions(false, false, false, false, false);
"components",
"default_qprofiles",
"deprecated_rule_keys",
+ "devops_perms_mapping",
"duplications_index",
"es_queue",
"events",
"external_groups",
"file_sources",
"github_orgs_groups",
- "github_perms_mapping",
"groups",
"groups_users",
"group_roles",
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.provisioning;
+
+import java.util.List;
+import java.util.Set;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.mockito.ArgumentCaptor;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.verify;
+import static org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue.ALL_PERMISSIONS;
+
+class DevOpsPermissionsMappingDaoIT {
+
+ private static final String MAPPING_UUID = "uuid";
+ protected static final String DEV_OPS_PLATFORM = "github";
+
+ private final AuditPersister auditPersister = mock();
+
+ @RegisterExtension
+ private final DbTester db = DbTester.create(auditPersister);
+
+ private final ArgumentCaptor<DevOpsPermissionsMappingNewValue> newValueCaptor =
+ ArgumentCaptor.forClass(DevOpsPermissionsMappingNewValue.class);
+
+ private final DbSession dbSession = db.getSession();
+
+ private final DevOpsPermissionsMappingDao underTest = db.getDbClient().githubPermissionsMappingDao();
+
+ @BeforeEach
+ public void setUp() {
+ List<DevOpsPermissionsMappingDto> role1Mappings = List.of(
+ new DevOpsPermissionsMappingDto("otherDop1", DEV_OPS_PLATFORM + "2", "GH_role_1", "SQ_role_1"),
+ new DevOpsPermissionsMappingDto("otherDop2", DEV_OPS_PLATFORM + "2", "GH_role_2", "SQ_role_2"),
+ new DevOpsPermissionsMappingDto("otherDop3", DEV_OPS_PLATFORM + "2", "GH_role_3", "SQ_role_3"));
+
+ role1Mappings.forEach(mapping -> underTest.insert(dbSession, mapping));
+ reset(auditPersister);
+ }
+
+ @Test
+ void insert_savesGithubPermissionsMappingDto() {
+ DevOpsPermissionsMappingDto devOpsPermissionsMappingDto = new DevOpsPermissionsMappingDto(MAPPING_UUID, DEV_OPS_PLATFORM, "GH_role", "SQ_role");
+
+ underTest.insert(dbSession, devOpsPermissionsMappingDto);
+
+ Set<DevOpsPermissionsMappingDto> savedGithubPermissionsMappings = underTest.findAll(dbSession, DEV_OPS_PLATFORM);
+ assertThat(savedGithubPermissionsMappings).hasSize(1);
+ DevOpsPermissionsMappingDto savedMapping = savedGithubPermissionsMappings.iterator().next();
+ assertThat(savedMapping.uuid()).isEqualTo(devOpsPermissionsMappingDto.uuid());
+ assertThat(savedMapping.role()).isEqualTo(devOpsPermissionsMappingDto.role());
+ assertThat(savedMapping.sonarqubePermission()).isEqualTo(devOpsPermissionsMappingDto.sonarqubePermission());
+
+ verify(auditPersister).addDevOpsPermissionsMapping(eq(dbSession), newValueCaptor.capture());
+ assertThat(newValueCaptor.getValue().getDevOpsPlatform()).isEqualTo(DEV_OPS_PLATFORM);
+ assertThat(newValueCaptor.getValue().getGithubRole()).isEqualTo(devOpsPermissionsMappingDto.role());
+ assertThat(newValueCaptor.getValue().getSonarqubePermission()).isEqualTo(devOpsPermissionsMappingDto.sonarqubePermission());
+ }
+
+ @Test
+ void delete_deletesGithubPermissionsMappingDto() {
+ DevOpsPermissionsMappingDto devOpsPermissionsMappingDto = new DevOpsPermissionsMappingDto(MAPPING_UUID, DEV_OPS_PLATFORM, "GH_role", "SQ_role");
+
+ underTest.insert(dbSession, devOpsPermissionsMappingDto);
+ underTest.delete(dbSession, DEV_OPS_PLATFORM, "GH_role", "SQ_role");
+
+ Set<DevOpsPermissionsMappingDto> savedGithubPermissionsMappings = underTest.findAll(dbSession, DEV_OPS_PLATFORM);
+ assertThat(savedGithubPermissionsMappings).isEmpty();
+
+ verify(auditPersister).deleteDevOpsPermissionsMapping(eq(dbSession), newValueCaptor.capture());
+ assertThat(newValueCaptor.getValue().getDevOpsPlatform()).isEqualTo(DEV_OPS_PLATFORM);
+ assertThat(newValueCaptor.getValue().getGithubRole()).isEqualTo("GH_role");
+ assertThat(newValueCaptor.getValue().getSonarqubePermission()).isEqualTo("SQ_role");
+ }
+
+ @Test
+ void deleteAllPermissionsForRole_deletesGithubPermissionsMappingDto() {
+ List<DevOpsPermissionsMappingDto> role1Mappings = List.of(
+ new DevOpsPermissionsMappingDto("1", DEV_OPS_PLATFORM, "GH_role_1", "SQ_role_1"),
+ new DevOpsPermissionsMappingDto("2", DEV_OPS_PLATFORM, "GH_role_1", "SQ_role_2"),
+ new DevOpsPermissionsMappingDto("3", DEV_OPS_PLATFORM, "GH_role_1", "SQ_role_3"));
+
+ List<DevOpsPermissionsMappingDto> role2Mappings = List.of(
+ new DevOpsPermissionsMappingDto("4", DEV_OPS_PLATFORM, "GH_role_2", "SQ_role_1"),
+ new DevOpsPermissionsMappingDto("5", DEV_OPS_PLATFORM, "GH_role_2", "SQ_role_2"));
+
+ role1Mappings.forEach(mapping -> underTest.insert(dbSession, mapping));
+ role2Mappings.forEach(mapping -> underTest.insert(dbSession, mapping));
+
+ underTest.deleteAllPermissionsForRole(dbSession, DEV_OPS_PLATFORM, "GH_role_1");
+
+ Set<DevOpsPermissionsMappingDto> savedGithubPermissionsMappings = underTest.findAll(dbSession, DEV_OPS_PLATFORM);
+ assertThat(savedGithubPermissionsMappings).containsExactlyInAnyOrderElementsOf(role2Mappings);
+
+ verify(auditPersister).deleteDevOpsPermissionsMapping(eq(dbSession), newValueCaptor.capture());
+ assertThat(newValueCaptor.getValue().getDevOpsPlatform()).isEqualTo(DEV_OPS_PLATFORM);
+ assertThat(newValueCaptor.getValue().getGithubRole()).isEqualTo("GH_role_1");
+ assertThat(newValueCaptor.getValue().getSonarqubePermission()).isEqualTo(ALL_PERMISSIONS);
+ }
+
+ @Test
+ void findAll_shouldReturnAllDevOpsPermissionMappingOfDevOpsPlatform() {
+ DevOpsPermissionsMappingDto mapping1 = new DevOpsPermissionsMappingDto(MAPPING_UUID, DEV_OPS_PLATFORM, "GH_role", "SQ_role");
+ DevOpsPermissionsMappingDto mapping2 = new DevOpsPermissionsMappingDto(MAPPING_UUID + "2", DEV_OPS_PLATFORM, "GH_role2", "SQ_role");
+ DevOpsPermissionsMappingDto mapping3 = new DevOpsPermissionsMappingDto(MAPPING_UUID + "3", DEV_OPS_PLATFORM + "2", "GH_role2", "SQ_role");
+
+ underTest.insert(dbSession, mapping1);
+ underTest.insert(dbSession, mapping2);
+ underTest.insert(dbSession, mapping3);
+
+ Set<DevOpsPermissionsMappingDto> all = underTest.findAll(dbSession, DEV_OPS_PLATFORM);
+
+ assertThat(all).hasSize(2)
+ .containsExactlyInAnyOrder(
+ mapping1,
+ mapping2);
+ }
+
+ @Test
+ void findAllForGithubRole_shouldReturnPermissionsForTheRole() {
+ DevOpsPermissionsMappingDto mapping1 = new DevOpsPermissionsMappingDto(MAPPING_UUID, DEV_OPS_PLATFORM, "GH_role", "SQ_role");
+ DevOpsPermissionsMappingDto mapping2 = new DevOpsPermissionsMappingDto(MAPPING_UUID + "2", DEV_OPS_PLATFORM, "GH_role2", "SQ_role");
+ DevOpsPermissionsMappingDto mapping3 = new DevOpsPermissionsMappingDto(MAPPING_UUID + "3", DEV_OPS_PLATFORM, "GH_role2", "SQ_role2");
+ underTest.insert(dbSession, mapping1);
+ underTest.insert(dbSession, mapping2);
+ underTest.insert(dbSession, mapping3);
+
+ Set<DevOpsPermissionsMappingDto> forRole2 = underTest.findAllForRole(dbSession, DEV_OPS_PLATFORM, "GH_role2");
+ assertThat(forRole2).hasSize(2)
+ .containsExactlyInAnyOrder(mapping2, mapping3);
+
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.provisioning;
-
-import java.util.List;
-import java.util.Set;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-import org.mockito.ArgumentCaptor;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.audit.AuditPersister;
-import org.sonar.db.audit.model.GithubPermissionsMappingNewValue;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.sonar.db.audit.model.GithubPermissionsMappingNewValue.ALL_PERMISSIONS;
-
-class GithubPermissionsMappingDaoIT {
-
- private static final String MAPPING_UUID = "uuid";
-
- private final AuditPersister auditPersister = mock();
-
- @RegisterExtension
- private final DbTester db = DbTester.create(auditPersister);
-
- private final ArgumentCaptor<GithubPermissionsMappingNewValue> newValueCaptor =
- ArgumentCaptor.forClass(GithubPermissionsMappingNewValue.class);
-
- private final DbSession dbSession = db.getSession();
-
- private final GithubPermissionsMappingDao underTest = db.getDbClient().githubPermissionsMappingDao();
-
- @Test
- void insert_savesGithubPermissionsMappingDto() {
- GithubPermissionsMappingDto githubPermissionsMappingDto = new GithubPermissionsMappingDto(MAPPING_UUID, "GH_role", "SQ_role");
-
- underTest.insert(dbSession, githubPermissionsMappingDto);
-
- Set<GithubPermissionsMappingDto> savedGithubPermissionsMappings = underTest.findAll(dbSession);
- assertThat(savedGithubPermissionsMappings).hasSize(1);
- GithubPermissionsMappingDto savedMapping = savedGithubPermissionsMappings.iterator().next();
- assertThat(savedMapping.uuid()).isEqualTo(githubPermissionsMappingDto.uuid());
- assertThat(savedMapping.githubRole()).isEqualTo(githubPermissionsMappingDto.githubRole());
- assertThat(savedMapping.sonarqubePermission()).isEqualTo(githubPermissionsMappingDto.sonarqubePermission());
-
- verify(auditPersister).addGithubPermissionsMapping(eq(dbSession), newValueCaptor.capture());
- assertThat(newValueCaptor.getValue().getGithubRole()).isEqualTo(githubPermissionsMappingDto.githubRole());
- assertThat(newValueCaptor.getValue().getSonarqubePermission()).isEqualTo(githubPermissionsMappingDto.sonarqubePermission());
- }
-
- @Test
- void delete_deletesGithubPermissionsMappingDto() {
- GithubPermissionsMappingDto githubPermissionsMappingDto = new GithubPermissionsMappingDto(MAPPING_UUID, "GH_role", "SQ_role");
-
- underTest.insert(dbSession, githubPermissionsMappingDto);
- underTest.delete(dbSession, "GH_role", "SQ_role");
-
- Set<GithubPermissionsMappingDto> savedGithubPermissionsMappings = underTest.findAll(dbSession);
- assertThat(savedGithubPermissionsMappings).isEmpty();
-
- verify(auditPersister).deleteGithubPermissionsMapping(eq(dbSession), newValueCaptor.capture());
- assertThat(newValueCaptor.getValue().getGithubRole()).isEqualTo("GH_role");
- assertThat(newValueCaptor.getValue().getSonarqubePermission()).isEqualTo("SQ_role");
- }
-
- @Test
- void deleteAllPermissionsForRole_deletesGithubPermissionsMappingDto() {
- List<GithubPermissionsMappingDto> role1Mappings = List.of(
- new GithubPermissionsMappingDto("1", "GH_role_1", "SQ_role_1"),
- new GithubPermissionsMappingDto("2", "GH_role_1", "SQ_role_2"),
- new GithubPermissionsMappingDto("3", "GH_role_1", "SQ_role_3"));
-
- List<GithubPermissionsMappingDto> role2Mappings = List.of(
- new GithubPermissionsMappingDto("4", "GH_role_2", "SQ_role_1"),
- new GithubPermissionsMappingDto("5", "GH_role_2", "SQ_role_2"));
-
- role1Mappings.forEach(mapping -> underTest.insert(dbSession, mapping));
- role2Mappings.forEach(mapping -> underTest.insert(dbSession, mapping));
-
- underTest.deleteAllPermissionsForRole(dbSession, "GH_role_1");
-
- Set<GithubPermissionsMappingDto> savedGithubPermissionsMappings = underTest.findAll(dbSession);
- assertThat(savedGithubPermissionsMappings).containsExactlyInAnyOrderElementsOf(role2Mappings);
-
- verify(auditPersister).deleteGithubPermissionsMapping(eq(dbSession), newValueCaptor.capture());
- assertThat(newValueCaptor.getValue().getGithubRole()).isEqualTo("GH_role_1");
- assertThat(newValueCaptor.getValue().getSonarqubePermission()).isEqualTo(ALL_PERMISSIONS);
- }
-
- @Test
- void findAll_shouldReturnAllGithubOrganizationGroup() {
- GithubPermissionsMappingDto mapping1 = new GithubPermissionsMappingDto(MAPPING_UUID, "GH_role", "SQ_role");
- GithubPermissionsMappingDto mapping2 = new GithubPermissionsMappingDto(MAPPING_UUID + "2", "GH_role2", "SQ_role");
-
- underTest.insert(dbSession, mapping1);
- underTest.insert(dbSession, mapping2);
-
- Set<GithubPermissionsMappingDto> all = underTest.findAll(dbSession);
-
- assertThat(all).hasSize(2)
- .containsExactlyInAnyOrder(
- mapping1,
- mapping2);
- }
-
- @Test
- void findAllForGithubRole_shouldReturnPermissionsForTheRole() {
- GithubPermissionsMappingDto mapping1 = new GithubPermissionsMappingDto(MAPPING_UUID, "GH_role", "SQ_role");
- GithubPermissionsMappingDto mapping2 = new GithubPermissionsMappingDto(MAPPING_UUID + "2", "GH_role2", "SQ_role");
- GithubPermissionsMappingDto mapping3 = new GithubPermissionsMappingDto(MAPPING_UUID + "3", "GH_role2", "SQ_role2");
- underTest.insert(dbSession, mapping1);
- underTest.insert(dbSession, mapping2);
- underTest.insert(dbSession, mapping3);
-
- Set<GithubPermissionsMappingDto> forRole2 = underTest.findAllForGithubRole(dbSession, "GH_role2");
- assertThat(forRole2).hasSize(2)
- .containsExactlyInAnyOrder(mapping2, mapping3);
-
- }
-
-}
import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.property.PropertiesDao;
import org.sonar.db.provisioning.GithubOrganizationGroupDao;
-import org.sonar.db.provisioning.GithubPermissionsMappingDao;
+import org.sonar.db.provisioning.DevOpsPermissionsMappingDao;
import org.sonar.db.purge.PurgeDao;
import org.sonar.db.pushevent.PushEventDao;
import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
ComponentDao.class,
ComponentKeyUpdaterDao.class,
DefaultQProfileDao.class,
+ DevOpsPermissionsMappingDao.class,
DuplicationDao.class,
EntityDao.class,
EsQueueDao.class,
EventDao.class,
EventComponentChangeDao.class,
GithubOrganizationGroupDao.class,
- GithubPermissionsMappingDao.class,
ExternalGroupDao.class,
FileSourceDao.class,
GroupDao.class,
import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.property.PropertiesDao;
import org.sonar.db.provisioning.GithubOrganizationGroupDao;
-import org.sonar.db.provisioning.GithubPermissionsMappingDao;
+import org.sonar.db.provisioning.DevOpsPermissionsMappingDao;
import org.sonar.db.purge.PurgeDao;
import org.sonar.db.pushevent.PushEventDao;
import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
private final ReportScheduleDao reportScheduleDao;
private final ReportSubscriptionDao reportSubscriptionDao;
private final GithubOrganizationGroupDao githubOrganizationGroupDao;
- private final GithubPermissionsMappingDao githubPermissionsMappingDao;
+ private final DevOpsPermissionsMappingDao devopsPermissionsMappingDao;
private final RuleChangeDao ruleChangeDao;
private final ProjectExportDao projectExportDao;
private final IssueFixedDao issueFixedDao;
metricDao = getDao(map, MetricDao.class);
groupDao = getDao(map, GroupDao.class);
githubOrganizationGroupDao = getDao(map, GithubOrganizationGroupDao.class);
- githubPermissionsMappingDao = getDao(map, GithubPermissionsMappingDao.class);
+ devopsPermissionsMappingDao = getDao(map, DevOpsPermissionsMappingDao.class);
externalGroupDao = getDao(map, ExternalGroupDao.class);
ruleDao = getDao(map, RuleDao.class);
ruleRepositoryDao = getDao(map, RuleRepositoryDao.class);
return githubOrganizationGroupDao;
}
- public GithubPermissionsMappingDao githubPermissionsMappingDao() {
- return githubPermissionsMappingDao;
+ public DevOpsPermissionsMappingDao githubPermissionsMappingDao() {
+ return devopsPermissionsMappingDao;
}
public ExternalGroupDao externalGroupDao() {
import org.sonar.db.property.ScrapPropertyDto;
import org.sonar.db.provisioning.GithubOrganizationGroupDto;
import org.sonar.db.provisioning.GithubOrganizationGroupMapper;
-import org.sonar.db.provisioning.GithubPermissionsMappingDto;
-import org.sonar.db.provisioning.GithubPermissionsMappingMapper;
+import org.sonar.db.provisioning.DevOpsPermissionsMappingDto;
+import org.sonar.db.provisioning.DevOpsPermissionsMappingMapper;
import org.sonar.db.purge.PurgeMapper;
import org.sonar.db.purge.PurgeableAnalysisDto;
import org.sonar.db.pushevent.PushEventDto;
confBuilder.loadAlias("AnticipatedTransition", AnticipatedTransitionDto.class);
confBuilder.loadAlias("CeTaskCharacteristic", CeTaskCharacteristicDto.class);
confBuilder.loadAlias("Component", ComponentDto.class);
+ confBuilder.loadAlias("DevOpsPermissionsMapping", DevOpsPermissionsMappingDto.class);
confBuilder.loadAlias("DuplicationUnit", DuplicationUnitDto.class);
confBuilder.loadAlias("Entity", EntityDto.class);
confBuilder.loadAlias("Event", EventDto.class);
confBuilder.loadAlias("ExternalGroup", ExternalGroupDto.class);
confBuilder.loadAlias("GithubOrganizationGroup", GithubOrganizationGroupDto.class);
- confBuilder.loadAlias("GithubPermissionsMapping", GithubPermissionsMappingDto.class);
confBuilder.loadAlias("FilePathWithHash", FilePathWithHashDto.class);
confBuilder.loadAlias("KeyWithUuid", KeyWithUuidDto.class);
confBuilder.loadAlias("Group", GroupDto.class);
EventMapper.class,
EventComponentChangeMapper.class,
GithubOrganizationGroupMapper.class,
- GithubPermissionsMappingMapper.class,
+ DevOpsPermissionsMappingMapper.class,
ExternalGroupMapper.class,
FileSourceMapper.class,
GroupMapper.class,
import org.sonar.db.audit.model.ComponentKeyNewValue;
import org.sonar.db.audit.model.ComponentNewValue;
import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
-import org.sonar.db.audit.model.GithubPermissionsMappingNewValue;
+import org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue;
import org.sonar.db.audit.model.GroupPermissionNewValue;
import org.sonar.db.audit.model.LicenseNewValue;
import org.sonar.db.audit.model.PermissionTemplateNewValue;
void deleteGroupFromPermissionTemplate(DbSession dbSession, PermissionTemplateNewValue newValue);
- void addGithubPermissionsMapping(DbSession dbSession, GithubPermissionsMappingNewValue newValue);
+ void addDevOpsPermissionsMapping(DbSession dbSession, DevOpsPermissionsMappingNewValue newValue);
- void deleteGithubPermissionsMapping(DbSession dbSession, GithubPermissionsMappingNewValue deletedValue);
+ void deleteDevOpsPermissionsMapping(DbSession dbSession, DevOpsPermissionsMappingNewValue deletedValue);
void addQualityGateEditor(DbSession dbSession, AbstractEditorNewValue newValue);
import org.sonar.db.audit.model.ComponentNewValue;
import org.sonar.db.audit.model.DevOpsPlatformSettingNewValue;
import org.sonar.db.audit.model.AbstractEditorNewValue;
-import org.sonar.db.audit.model.GithubPermissionsMappingNewValue;
+import org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue;
import org.sonar.db.audit.model.GroupPermissionNewValue;
import org.sonar.db.audit.model.LicenseNewValue;
import org.sonar.db.audit.model.PermissionTemplateNewValue;
}
@Override
- public void addGithubPermissionsMapping(DbSession dbSession, GithubPermissionsMappingNewValue newValue) {
+ public void addDevOpsPermissionsMapping(DbSession dbSession, DevOpsPermissionsMappingNewValue newValue) {
// no op
}
@Override
- public void deleteGithubPermissionsMapping(DbSession dbSession, GithubPermissionsMappingNewValue deletedValue) {
+ public void deleteDevOpsPermissionsMapping(DbSession dbSession, DevOpsPermissionsMappingNewValue deletedValue) {
// no op
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.audit.model;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class DevOpsPermissionsMappingNewValue extends NewValue {
+
+ @VisibleForTesting
+ public static final String ALL_PERMISSIONS = "all";
+ private final String devOpsPlatform;
+ private final String githubRole;
+ private final String sonarqubePermission;
+
+ public DevOpsPermissionsMappingNewValue(String devOpsPlatform, String githubRole, String sonarqubePermission) {
+ this.devOpsPlatform = devOpsPlatform;
+ this.githubRole = githubRole;
+ this.sonarqubePermission = sonarqubePermission;
+ }
+
+ public static DevOpsPermissionsMappingNewValue withAllPermissions(String devOpsPlatform, String githubRole) {
+ return new DevOpsPermissionsMappingNewValue(devOpsPlatform, githubRole, ALL_PERMISSIONS);
+ }
+
+ @VisibleForTesting
+ public String getGithubRole() {
+ return githubRole;
+ }
+
+ @VisibleForTesting
+ public String getSonarqubePermission() {
+ return sonarqubePermission;
+ }
+
+ @VisibleForTesting
+ public String getDevOpsPlatform() {
+ return devOpsPlatform;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ addField(sb, "\"devOpsPlatform\": ", this.devOpsPlatform, true);
+ addField(sb, "\"devOpsRole\": ", this.githubRole, true);
+ addField(sb, "\"sonarqubePermissions\": ", this.sonarqubePermission, true);
+ endString(sb);
+ return sb.toString();
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.audit.model;
-
-import com.google.common.annotations.VisibleForTesting;
-
-public class GithubPermissionsMappingNewValue extends NewValue {
-
- @VisibleForTesting
- public static final String ALL_PERMISSIONS = "all";
- private final String githubRole;
- private final String sonarqubePermission;
-
- public GithubPermissionsMappingNewValue(String githubRole, String sonarqubePermission) {
- this.githubRole = githubRole;
- this.sonarqubePermission = sonarqubePermission;
- }
-
- public static GithubPermissionsMappingNewValue withAllPermissions(String githubRole) {
- return new GithubPermissionsMappingNewValue(githubRole, ALL_PERMISSIONS);
- }
-
- @VisibleForTesting
- public String getGithubRole() {
- return githubRole;
- }
-
- public String getSonarqubePermission() {
- return sonarqubePermission;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("{");
- addField(sb, "\"githubRole\": ", this.githubRole, true);
- addField(sb, "\"sonarqubePermissions\": ", this.sonarqubePermission, true);
- endString(sb);
- return sb.toString();
- }
-
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.provisioning;
+
+import java.util.Set;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+import org.sonar.db.audit.AuditPersister;
+import org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue;
+
+public class DevOpsPermissionsMappingDao implements Dao {
+
+ private final AuditPersister auditPersister;
+
+ public DevOpsPermissionsMappingDao(AuditPersister auditPersister) {
+ this.auditPersister = auditPersister;
+ }
+
+ public Set<DevOpsPermissionsMappingDto> findAll(DbSession dbSession, String devOpsPlatform) {
+ return mapper(dbSession).selectAll(devOpsPlatform);
+ }
+
+ public Set<DevOpsPermissionsMappingDto> findAllForRole(DbSession dbSession, String devOpsPlatform, String role) {
+ return mapper(dbSession).selectAllForRole(devOpsPlatform, role);
+ }
+
+ public void insert(DbSession dbSession, DevOpsPermissionsMappingDto devOpsPermissionsMappingDto) {
+ mapper(dbSession).insert(devOpsPermissionsMappingDto);
+ DevOpsPermissionsMappingNewValue newValueForAuditLogs = toNewValueForAuditLogs(
+ devOpsPermissionsMappingDto.devOpsPlatform(),
+ devOpsPermissionsMappingDto.role(),
+ devOpsPermissionsMappingDto.sonarqubePermission()
+ );
+ auditPersister.addDevOpsPermissionsMapping(dbSession, newValueForAuditLogs);
+ }
+
+ public void delete(DbSession dbSession, String devOpsPlatform, String role, String sonarqubePermission) {
+ mapper(dbSession).delete(devOpsPlatform, role, sonarqubePermission);
+ auditPersister.deleteDevOpsPermissionsMapping(dbSession, toNewValueForAuditLogs(devOpsPlatform, role, sonarqubePermission));
+ }
+
+ public void deleteAllPermissionsForRole(DbSession dbSession, String devOpsPlatform, String role) {
+ mapper(dbSession).deleteAllPermissionsForRole(devOpsPlatform, role);
+ auditPersister.deleteDevOpsPermissionsMapping(dbSession, DevOpsPermissionsMappingNewValue.withAllPermissions(devOpsPlatform, role));
+ }
+
+ private static DevOpsPermissionsMappingNewValue toNewValueForAuditLogs(String devOpsPlatform, String role, String sonarqubePermission) {
+ return new DevOpsPermissionsMappingNewValue(devOpsPlatform, role, sonarqubePermission);
+ }
+
+ private static DevOpsPermissionsMappingMapper mapper(DbSession session) {
+ return session.getMapper(DevOpsPermissionsMappingMapper.class);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.provisioning;
+
+public record DevOpsPermissionsMappingDto(String uuid, String devOpsPlatform, String role, String sonarqubePermission) {
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.db.provisioning;
+
+import java.util.Set;
+import org.apache.ibatis.annotations.Param;
+
+public interface DevOpsPermissionsMappingMapper {
+
+ Set<DevOpsPermissionsMappingDto> selectAll(@Param("devOpsPlatform") String devOpsPlatform);
+
+ Set<DevOpsPermissionsMappingDto> selectAllForRole(@Param("devOpsPlatform") String devOpsPlatform, @Param("role") String role);
+
+ void insert(DevOpsPermissionsMappingDto devOpsPermissionsMappingDto);
+
+ void delete(@Param("devOpsPlatform") String devOpsPlatform, @Param("role") String role, @Param("sonarqubePermission") String sonarqubePermission);
+
+ void deleteAllPermissionsForRole(@Param("devOpsPlatform") String devOpsPlatform, @Param("role") String role);
+}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.provisioning;
-
-import java.util.Set;
-import org.sonar.db.Dao;
-import org.sonar.db.DbSession;
-import org.sonar.db.audit.AuditPersister;
-import org.sonar.db.audit.model.GithubPermissionsMappingNewValue;
-
-public class GithubPermissionsMappingDao implements Dao {
-
- private final AuditPersister auditPersister;
-
- public GithubPermissionsMappingDao(AuditPersister auditPersister) {
- this.auditPersister = auditPersister;
- }
-
- public Set<GithubPermissionsMappingDto> findAll(DbSession dbSession) {
- return mapper(dbSession).selectAll();
- }
-
- public Set<GithubPermissionsMappingDto> findAllForGithubRole(DbSession dbSession, String githubRole) {
- return mapper(dbSession).selectAllForGithubRole(githubRole);
- }
-
- public void insert(DbSession dbSession, GithubPermissionsMappingDto githubPermissionsMappingDto) {
- mapper(dbSession).insert(githubPermissionsMappingDto);
- auditPersister.addGithubPermissionsMapping(dbSession, toNewValueForAuditLogs(githubPermissionsMappingDto.githubRole(), githubPermissionsMappingDto.sonarqubePermission()));
- }
-
- public void delete(DbSession dbSession, String githubRole, String sonarqubePermission) {
- mapper(dbSession).delete(githubRole, sonarqubePermission);
- auditPersister.deleteGithubPermissionsMapping(dbSession, toNewValueForAuditLogs(githubRole, sonarqubePermission));
- }
-
- public void deleteAllPermissionsForRole(DbSession dbSession, String githubRole) {
- mapper(dbSession).deleteAllPermissionsForRole(githubRole);
- auditPersister.deleteGithubPermissionsMapping(dbSession, GithubPermissionsMappingNewValue.withAllPermissions(githubRole));
- }
-
- private static GithubPermissionsMappingNewValue toNewValueForAuditLogs(String githubRole, String sonarqubePermission) {
- return new GithubPermissionsMappingNewValue(githubRole, sonarqubePermission);
- }
-
- private static GithubPermissionsMappingMapper mapper(DbSession session) {
- return session.getMapper(GithubPermissionsMappingMapper.class);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.provisioning;
-
-public record GithubPermissionsMappingDto(String uuid, String githubRole, String sonarqubePermission) {
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2024 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.provisioning;
-
-import java.util.Set;
-import org.apache.ibatis.annotations.Param;
-
-public interface GithubPermissionsMappingMapper {
-
- Set<GithubPermissionsMappingDto> selectAll();
-
- Set<GithubPermissionsMappingDto> selectAllForGithubRole(String githubRole);
-
- void insert(GithubPermissionsMappingDto githubPermissionsMappingDto);
-
- void delete(@Param("githubRole") String githubRole, @Param("sonarqubePermission") String sonarqubePermission);
-
- void deleteAllPermissionsForRole(String githubRole);
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.db.provisioning.DevOpsPermissionsMappingMapper">
+
+ <sql id="devOpsPermissionsMappingColumns">
+ dpm.uuid as uuid,
+ dpm.devops_platform as devOpsPlatform,
+ dpm.devops_platform_role as role,
+ dpm.sonarqube_permission as sonarqubePermission
+ </sql>
+
+ <insert id="insert" useGeneratedKeys="false" parameterType="DevOpsPermissionsMapping">
+ insert into devops_perms_mapping (
+ uuid,
+ devops_platform,
+ devops_platform_role,
+ sonarqube_permission
+ ) values (
+ #{uuid,jdbcType=VARCHAR},
+ #{devOpsPlatform,jdbcType=VARCHAR},
+ #{role,jdbcType=VARCHAR},
+ #{sonarqubePermission,jdbcType=VARCHAR}
+ )
+ </insert>
+
+ <delete id="delete" parameterType="DevOpsPermissionsMapping">
+ delete from devops_perms_mapping
+ where devops_platform = #{devOpsPlatform,jdbcType=VARCHAR} AND
+ devops_platform_role = #{role,jdbcType=VARCHAR} AND
+ sonarqube_permission = #{sonarqubePermission,jdbcType=VARCHAR}
+ </delete>
+
+ <delete id="deleteAllPermissionsForRole" parameterType="DevOpsPermissionsMapping">
+ delete from devops_perms_mapping
+ where devops_platform = #{devOpsPlatform,jdbcType=VARCHAR} AND devops_platform_role = #{role,jdbcType=VARCHAR}
+ </delete>
+
+ <select id="selectAll" resultType="DevOpsPermissionsMapping">
+ SELECT
+ <include refid="devOpsPermissionsMappingColumns"/>
+ FROM devops_perms_mapping dpm
+ where devops_platform = #{devOpsPlatform,jdbcType=VARCHAR}
+ </select>
+
+ <select id="selectAllForRole" resultType="DevOpsPermissionsMapping">
+ SELECT
+ <include refid="devOpsPermissionsMappingColumns"/>
+ FROM devops_perms_mapping dpm
+ WHERE
+ devops_platform = #{devOpsPlatform,jdbcType=VARCHAR} AND
+ dpm.devops_platform_role = #{role,jdbcType=VARCHAR}
+ </select>
+
+</mapper>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.provisioning.GithubPermissionsMappingMapper">
-
- <sql id="githubPermissionsMappingColumns">
- gpm.uuid as uuid,
- gpm.github_role as githubRole,
- gpm.sonarqube_permission as sonarqubePermission
- </sql>
-
- <insert id="insert" useGeneratedKeys="false" parameterType="GithubPermissionsMapping">
- insert into github_perms_mapping (
- uuid,
- github_role,
- sonarqube_permission
- ) values (
- #{uuid,jdbcType=VARCHAR},
- #{githubRole,jdbcType=VARCHAR},
- #{sonarqubePermission,jdbcType=VARCHAR}
- )
- </insert>
-
- <delete id="delete" parameterType="GithubPermissionsMapping">
- delete from github_perms_mapping
- where github_role = #{githubRole,jdbcType=VARCHAR} AND sonarqube_permission = #{sonarqubePermission,jdbcType=VARCHAR}
- </delete>
-
- <delete id="deleteAllPermissionsForRole" parameterType="GithubPermissionsMapping">
- delete from github_perms_mapping
- where github_role = #{githubRole,jdbcType=VARCHAR}
- </delete>
-
- <select id="selectAll" resultType="GithubPermissionsMapping">
- SELECT
- <include refid="githubPermissionsMappingColumns"/>
- FROM github_perms_mapping gpm
- </select>
-
- <select id="selectAllForGithubRole" resultType="GithubPermissionsMapping">
- SELECT
- <include refid="githubPermissionsMappingColumns"/>
- FROM github_perms_mapping gpm
- WHERE gpm.github_role = #{githubRole,jdbcType=VARCHAR}
- </select>
-
-</mapper>
import org.sonar.auth.github.GsonRepositoryTeam;
import org.sonar.auth.github.client.GithubApplicationClient;
import org.sonar.db.DbClient;
-import org.sonar.db.provisioning.GithubPermissionsMappingDto;
+import org.sonar.db.provisioning.DevOpsPermissionsMappingDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.common.almintegration.ProjectKeyGenerator;
import org.sonar.server.common.almsettings.DefaultDevOpsProjectCreator;
String organization = orgaAndRepoTokenified[0];
String repository = orgaAndRepoTokenified[1];
- Set<GithubPermissionsMappingDto> permissionsMappingDtos = dbClient.githubPermissionsMappingDao().findAll(dbClient.openSession(false));
+ Set<DevOpsPermissionsMappingDto> permissionsMappingDtos = dbClient.githubPermissionsMappingDao().findAll(dbClient.openSession(false), devOpsPlatformSettings.getDevOpsPlatform());
boolean userHasDirectAccessToRepo = doesUserHaveScanPermission(organization, repository, permissionsMappingDtos);
if (userHasDirectAccessToRepo) {
return doesUserBelongToAGroupWithScanPermission(organization, repository, permissionsMappingDtos);
}
- private boolean doesUserHaveScanPermission(String organization, String repository, Set<GithubPermissionsMappingDto> permissionsMappingDtos) {
+ private boolean doesUserHaveScanPermission(String organization, String repository, Set<DevOpsPermissionsMappingDto> permissionsMappingDtos) {
String url = requireNonNull(devOpsProjectCreationContext.almSettingDto().getUrl(), "GitHub url not defined");
Set<GsonRepositoryCollaborator> repositoryCollaborators = githubApplicationClient.getRepositoryCollaborators(url, authAppInstallationToken, organization, repository);
}
private boolean doesUserBelongToAGroupWithScanPermission(String organization, String repository,
- Set<GithubPermissionsMappingDto> permissionsMappingDtos) {
+ Set<DevOpsPermissionsMappingDto> permissionsMappingDtos) {
String url = requireNonNull(devOpsProjectCreationContext.almSettingDto().getUrl(), "GitHub url not defined");
Set<GsonRepositoryTeam> repositoryTeams = githubApplicationClient.getRepositoryTeams(url, authAppInstallationToken, organization, repository);
.collect(toSet());
}
- private boolean hasScanPermission(Set<GithubPermissionsMappingDto> permissionsMappingDtos, String role, GsonRepositoryPermissions permissions) {
+ private boolean hasScanPermission(Set<DevOpsPermissionsMappingDto> permissionsMappingDtos, String role, GsonRepositoryPermissions permissions) {
Set<String> sonarqubePermissions = githubPermissionConverter.toSonarqubeRolesWithFallbackOnRepositoryPermissions(permissionsMappingDtos,
role, permissions);
return sonarqubePermissions.contains(UserRole.SCAN);
import org.sonar.db.DbClient;
import org.sonar.db.alm.setting.ALM;
import org.sonar.db.alm.setting.AlmSettingDto;
-import org.sonar.db.provisioning.GithubPermissionsMappingDto;
+import org.sonar.db.provisioning.DevOpsPermissionsMappingDto;
import org.sonar.db.user.GroupDto;
import org.sonar.server.common.almintegration.ProjectKeyGenerator;
import org.sonar.server.common.almsettings.DevOpsProjectCreationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.server.user.UserSession.IdentityProvider.GITHUB;
@ExtendWith(MockitoExtension.class)
class GithubProjectCreatorTest {
lenient().when(devOpsProjectCreationContext.fullName()).thenReturn(ORGANIZATION_NAME + "/" + REPOSITORY_NAME);
lenient().when(devOpsProjectCreationContext.defaultBranchName()).thenReturn(MAIN_BRANCH_NAME);
+ when(gitHubSettings.getDevOpsPlatform()).thenReturn(GITHUB.getKey());
+
ProjectCreator projectCreator = new ProjectCreator(userSession, projectDefaultVisibility, componentUpdater);
githubProjectCreator = new GithubProjectCreator(dbClient, devOpsProjectCreationContext, projectKeyGenerator, gitHubSettings, projectCreator, permissionService, permissionUpdater,
managedProjectService, githubApplicationClient, githubPermissionConverter, authAppInstallationToken);
}
private void mockPermissionsConversion(GsonRepositoryCollaborator collaborator, String... sqPermissions) {
- Set<GithubPermissionsMappingDto> githubPermissionsMappingDtos = mockPermissionsMappingsDtos();
- lenient().when(githubPermissionConverter.toSonarqubeRolesWithFallbackOnRepositoryPermissions(githubPermissionsMappingDtos, collaborator.roleName(), collaborator.permissions()))
+ Set<DevOpsPermissionsMappingDto> devOpsPermissionsMappingDtos = mockPermissionsMappingsDtos();
+ lenient().when(githubPermissionConverter.toSonarqubeRolesWithFallbackOnRepositoryPermissions(devOpsPermissionsMappingDtos, collaborator.roleName(), collaborator.permissions()))
.thenReturn(Arrays.stream(sqPermissions).collect(toSet()));
}
private void mockPermissionsConversion(GsonRepositoryTeam team, String... sqPermissions) {
- Set<GithubPermissionsMappingDto> githubPermissionsMappingDtos = mockPermissionsMappingsDtos();
- lenient().when(githubPermissionConverter.toSonarqubeRolesWithFallbackOnRepositoryPermissions(githubPermissionsMappingDtos, team.permission(), team.permissions()))
+ Set<DevOpsPermissionsMappingDto> devOpsPermissionsMappingDtos = mockPermissionsMappingsDtos();
+ lenient().when(githubPermissionConverter.toSonarqubeRolesWithFallbackOnRepositoryPermissions(devOpsPermissionsMappingDtos, team.permission(), team.permissions()))
.thenReturn(Arrays.stream(sqPermissions).collect(toSet()));
}
- private Set<GithubPermissionsMappingDto> mockPermissionsMappingsDtos() {
- Set<GithubPermissionsMappingDto> githubPermissionsMappingDtos = Set.of(mock(GithubPermissionsMappingDto.class));
- when(dbClient.githubPermissionsMappingDao().findAll(any())).thenReturn(githubPermissionsMappingDtos);
- return githubPermissionsMappingDtos;
+ private Set<DevOpsPermissionsMappingDto> mockPermissionsMappingsDtos() {
+ Set<DevOpsPermissionsMappingDto> devOpsPermissionsMappingDtos = Set.of(mock(DevOpsPermissionsMappingDto.class));
+ when(dbClient.githubPermissionsMappingDao().findAll(any(), eq(GITHUB.getKey()))).thenReturn(devOpsPermissionsMappingDtos);
+ return devOpsPermissionsMappingDtos;
}
private void bindGroupsToUser(String... groupNames) {