From: Aurelien Poscia Date: Mon, 4 Dec 2023 13:49:57 +0000 (+0100) Subject: SONAR-21119 Add GitLabManagedInstanceService, reuse logic from GitHub X-Git-Tag: 10.4.0.87286~269 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fb90e3a6491a517d7cb41bece875635f835f4845;p=sonarqube.git SONAR-21119 Add GitLabManagedInstanceService, reuse logic from GitHub --- 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 new file mode 100644 index 00000000000..3f9bf239ee6 --- /dev/null +++ b/server/sonar-auth-common/src/main/java/org/sonar/auth/DevOpsPlatformSettings.java @@ -0,0 +1,30 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.auth; + +public interface DevOpsPlatformSettings { + + String getDevOpsPlatform(); + + boolean isProvisioningEnabled(); + + boolean isProjectVisibilitySynchronizationActivated(); + +} 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 23651360fb2..cd7790371f6 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 @@ -30,8 +30,10 @@ import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.config.Configuration; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.server.ServerSide; +import org.sonar.auth.DevOpsPlatformSettings; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.db.alm.setting.ALM; import org.sonar.server.property.InternalProperties; import static java.lang.String.format; @@ -44,7 +46,7 @@ import static org.sonar.api.utils.Preconditions.checkState; @ServerSide @ComputeEngineSide -public class GitHubSettings { +public class GitHubSettings implements DevOpsPlatformSettings { public static final String CLIENT_ID = "sonar.auth.github.clientId.secured"; public static final String CLIENT_SECRET = "sonar.auth.github.clientSecret.secured"; @@ -159,6 +161,12 @@ public class GitHubSettings { return format("%s to enable GitHub provisioning.", prefix); } + @Override + public String getDevOpsPlatform() { + return ALM.GITHUB.getId(); + } + + @Override public boolean isProvisioningEnabled() { return isEnabled() && internalProperties.read(PROVISIONING).map(Boolean::parseBoolean).orElse(false); } @@ -167,6 +175,7 @@ public class GitHubSettings { return configuration.get(USER_CONSENT_FOR_PERMISSIONS_REQUIRED_AFTER_UPGRADE).isPresent(); } + @Override public boolean isProjectVisibilitySynchronizationActivated() { return configuration.getBoolean(PROVISION_VISIBILITY).orElse(true); } diff --git a/server/sonar-auth-gitlab/build.gradle b/server/sonar-auth-gitlab/build.gradle index f1ece299f90..26b522bafa8 100644 --- a/server/sonar-auth-gitlab/build.gradle +++ b/server/sonar-auth-gitlab/build.gradle @@ -11,6 +11,7 @@ dependencies { api 'com.github.scribejava:scribejava-core' api 'com.google.code.gson:gson' api project(':server:sonar-auth-common') + api project(':server:sonar-server-common') compileOnlyApi 'com.google.code.findbugs:jsr305' compileOnlyApi 'com.squareup.okhttp3:okhttp' 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 4f1058a5a5a..bf5810fe516 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 @@ -26,13 +26,15 @@ import org.sonar.api.PropertyType; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.config.Configuration; import org.sonar.api.config.PropertyDefinition; +import org.sonar.auth.DevOpsPlatformSettings; +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; @ComputeEngineSide -public class GitLabSettings { +public class GitLabSettings implements DevOpsPlatformSettings { public static final String GITLAB_AUTH_ENABLED = "sonar.auth.gitlab.enabled"; public static final String GITLAB_AUTH_URL = "sonar.auth.gitlab.url"; @@ -89,10 +91,21 @@ public class GitLabSettings { return Set.of(configuration.getStringArray(GITLAB_AUTH_PROVISIONING_GROUPS)); } + @Override + public String getDevOpsPlatform() { + return ALM.GITLAB.getId(); + } + + @Override public boolean isProvisioningEnabled() { return isEnabled() && configuration.getBoolean(GITLAB_AUTH_PROVISIONING_ENABLED).orElse(false); } + @Override + public boolean isProjectVisibilitySynchronizationActivated() { + return false; + } + static List definitions() { return Arrays.asList( PropertyDefinition.builder(GITLAB_AUTH_ENABLED)