From 6206c40f5a8b6115f3605d18a045e144caaf5d99 Mon Sep 17 00:00:00 2001 From: Aurelien Poscia Date: Wed, 14 Aug 2024 14:24:00 +0200 Subject: [PATCH] SONAR-22559 Refactor submission of project permissions sync tasks --- .../main/java/org/sonar/auth/DevOpsPlatformSettings.java | 2 ++ .../it/java/org/sonar/auth/github/GitHubSettingsIT.java | 7 +++++++ .../main/java/org/sonar/auth/github/GitHubSettings.java | 6 ++++++ .../main/java/org/sonar/auth/gitlab/GitLabSettings.java | 6 ++++++ .../java/org/sonar/auth/gitlab/GitLabSettingsTest.java | 6 ++++++ 5 files changed, 27 insertions(+) diff --git a/server/sonar-auth-common/src/main/java/org/sonar/auth/DevOpsPlatformSettings.java b/server/sonar-auth-common/src/main/java/org/sonar/auth/DevOpsPlatformSettings.java index 3c5b74fcb60..42b4ae0cf3c 100644 --- a/server/sonar-auth-common/src/main/java/org/sonar/auth/DevOpsPlatformSettings.java +++ b/server/sonar-auth-common/src/main/java/org/sonar/auth/DevOpsPlatformSettings.java @@ -29,4 +29,6 @@ public interface DevOpsPlatformSettings { boolean isUserConsentRequiredAfterUpgrade(); + String getProjectsPermissionsProvisioningTaskName(); + } diff --git a/server/sonar-auth-github/src/it/java/org/sonar/auth/github/GitHubSettingsIT.java b/server/sonar-auth-github/src/it/java/org/sonar/auth/github/GitHubSettingsIT.java index eab5384f3aa..25b54b74705 100644 --- a/server/sonar-auth-github/src/it/java/org/sonar/auth/github/GitHubSettingsIT.java +++ b/server/sonar-auth-github/src/it/java/org/sonar/auth/github/GitHubSettingsIT.java @@ -39,6 +39,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.sonar.auth.github.GitHubSettings.GITHUB_PROVISION_PROJECT_VISIBILITY; import static org.sonar.auth.github.GitHubSettings.GITHUB_USER_CONSENT_FOR_PERMISSIONS_REQUIRED_AFTER_UPGRADE; +import static org.sonar.db.ce.CeTaskTypes.GITHUB_PROJECT_PERMISSIONS_PROVISIONING; public class GitHubSettingsIT { @Rule @@ -313,4 +314,10 @@ public class GitHubSettingsIT { settings.setProperty("sonar.auth.github.appId", "id"); settings.setProperty("sonar.auth.github.privateKey.secured", "secret"); } + + @Test + public void getProjectsPermissionsProvisioningTaskName_returnsCorrectTaskName() { + assertThat(underTest.getProjectsPermissionsProvisioningTaskName()).isEqualTo(GITHUB_PROJECT_PERMISSIONS_PROVISIONING); + } + } diff --git a/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java b/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java index e98af18b583..a5b3e0b4d81 100644 --- a/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java +++ b/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java @@ -42,6 +42,7 @@ import static org.sonar.api.PropertyType.BOOLEAN; import static org.sonar.api.PropertyType.PASSWORD; import static org.sonar.api.PropertyType.STRING; import static org.sonar.api.utils.Preconditions.checkState; +import static org.sonar.db.ce.CeTaskTypes.GITHUB_PROJECT_PERMISSIONS_PROVISIONING; @ServerSide @ComputeEngineSide @@ -173,6 +174,11 @@ public class GitHubSettings implements DevOpsPlatformSettings { return configuration.get(GITHUB_USER_CONSENT_FOR_PERMISSIONS_REQUIRED_AFTER_UPGRADE).isPresent(); } + @Override + public String getProjectsPermissionsProvisioningTaskName() { + return GITHUB_PROJECT_PERMISSIONS_PROVISIONING; + } + @Override public boolean isProjectVisibilitySynchronizationActivated() { return configuration.getBoolean(GITHUB_PROVISION_PROJECT_VISIBILITY).orElse(true); diff --git a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java index 5a14cb14fde..d94d4a238bc 100644 --- a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java +++ b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java @@ -33,6 +33,7 @@ import org.sonar.db.alm.setting.ALM; import static java.lang.String.valueOf; import static org.sonar.api.PropertyType.BOOLEAN; import static org.sonar.api.PropertyType.PASSWORD; +import static org.sonar.db.ce.CeTaskTypes.GITLAB_PROJECT_PERMISSIONS_PROVISIONING; @ComputeEngineSide public class GitLabSettings implements DevOpsPlatformSettings { @@ -117,6 +118,11 @@ public class GitLabSettings implements DevOpsPlatformSettings { return configuration.getBoolean(GITLAB_USER_CONSENT_FOR_PERMISSION_PROVISIONING_REQUIRED).isPresent(); } + @Override + public String getProjectsPermissionsProvisioningTaskName() { + return GITLAB_PROJECT_PERMISSIONS_PROVISIONING; + } + static List definitions() { return Arrays.asList( PropertyDefinition.builder(GITLAB_AUTH_ENABLED) diff --git a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java index 2c21df6171a..aea7215f05f 100644 --- a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java +++ b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GitLabSettingsTest.java @@ -36,6 +36,7 @@ import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_SECRET; import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_SYNC_USER_GROUPS; import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_URL; import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_USER_CONSENT_FOR_PERMISSION_PROVISIONING_REQUIRED; +import static org.sonar.db.ce.CeTaskTypes.GITLAB_PROJECT_PERMISSIONS_PROVISIONING; public class GitLabSettingsTest { @@ -134,6 +135,11 @@ public class GitLabSettingsTest { assertThat(config.isUserConsentRequiredAfterUpgrade()).isTrue(); } + @Test + public void getProjectsPermissionsProvisioningTaskName_returnsCorrectTaskName() { + assertThat(config.getProjectsPermissionsProvisioningTaskName()).isEqualTo(GITLAB_PROJECT_PERMISSIONS_PROVISIONING); + } + private void enableGitlabAuthentication() { settings.setProperty(GITLAB_AUTH_ENABLED, true); settings.setProperty(GITLAB_AUTH_APPLICATION_ID, "on"); -- 2.39.5