]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21119 Add GitLabManagedInstanceService, reuse logic from GitHub
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Mon, 4 Dec 2023 13:49:57 +0000 (14:49 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 22 Dec 2023 20:03:02 +0000 (20:03 +0000)
server/sonar-auth-common/src/main/java/org/sonar/auth/DevOpsPlatformSettings.java [new file with mode: 0644]
server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java
server/sonar-auth-gitlab/build.gradle
server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java

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 (file)
index 0000000..3f9bf23
--- /dev/null
@@ -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();
+
+}
index 23651360fb24b6981ef865ff87cd4b597a0de12e..cd7790371f6bb2e23af66149e4e8ae54afd64936 100644 (file)
@@ -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);
   }
index f1ece299f9061d0df7d96c41fde666cfd1e6e679..26b522bafa89589eeb61792b75383c9376e7037f 100644 (file)
@@ -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'
index 4f1058a5a5ac2220892a0ae62a190e72d01d3897..bf5810fe516fecd204dd1d551b9cd459cef27e9e 100644 (file)
@@ -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<PropertyDefinition> definitions() {
     return Arrays.asList(
       PropertyDefinition.builder(GITLAB_AUTH_ENABLED)