]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17195 Use "externalIdentityProvider" in users array in telemetry
authorJacek <jacek.poreda@sonarsource.com>
Tue, 27 Sep 2022 12:40:19 +0000 (14:40 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 28 Sep 2022 20:04:08 +0000 (20:04 +0000)
- drop "externalAuthProviders" field

server/sonar-db-dao/src/main/java/org/sonar/db/user/UserTelemetryDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml
server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java
server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java
server/sonar-server-common/src/test/java/org/sonar/server/telemetry/TelemetryDataJsonWriterTest.java
server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java

index 0c0a0c35539e9d90a76a44bfb9106600e5d905b6..cbee0dc4f6088a6ef16a9821da782189e32ca35b 100644 (file)
@@ -23,12 +23,13 @@ import javax.annotation.Nullable;
 
 public class UserTelemetryDto {
 
-  private String uuid;
+  private String uuid = null;
   private boolean active = true;
+  private String externalIdentityProvider = null;
   @Nullable
-  private Long lastConnectionDate;
+  private Long lastConnectionDate = null;
   @Nullable
-  private Long lastSonarlintConnectionDate;
+  private Long lastSonarlintConnectionDate = null;
 
   public String getUuid() {
     return uuid;
@@ -48,6 +49,15 @@ public class UserTelemetryDto {
     return this;
   }
 
+  public String getExternalIdentityProvider() {
+    return externalIdentityProvider;
+  }
+
+  public UserTelemetryDto setExternalIdentityProvider(String externalIdentityProvider) {
+    this.externalIdentityProvider = externalIdentityProvider;
+    return this;
+  }
+
   @Nullable
   public Long getLastConnectionDate() {
     return lastConnectionDate;
index 7265b8dde2e391ebf66f818fe8350fdf8c094095..abab22c87573746edaaa433d8da2a099c05aa8d4 100644 (file)
         SELECT
             u.uuid as uuid,
             u.active as "active",
+            u.external_identity_provider as "externalIdentityProvider",
             u.last_connection_date as "lastConnectionDate",
             u.last_sonarlint_connection as "lastSonarlintConnectionDate"
         FROM users u
index 1f4cd508c6dfdf52b5e1a98e69bcb3451445bb7b..09b2c1ee5a1f98d4d907aca1d9c224d375b1175a 100644 (file)
@@ -36,7 +36,6 @@ public class TelemetryData {
   private final String version;
   private final Map<String, String> plugins;
   private final Database database;
-  private final List<String> externalAuthenticationProviders;
   private final EditionProvider.Edition edition;
   private final String licenseType;
   private final Long installationDate;
@@ -62,7 +61,6 @@ public class TelemetryData {
     hasUnanalyzedC = builder.hasUnanalyzedC;
     hasUnanalyzedCpp = builder.hasUnanalyzedCpp;
     customSecurityConfigs = builder.customSecurityConfigs == null ? emptyList() : builder.customSecurityConfigs;
-    externalAuthenticationProviders = builder.externalAuthenticationProviders;
     users = builder.users;
     projects = builder.projects;
     projectStatistics = builder.projectStatistics;
@@ -116,10 +114,6 @@ public class TelemetryData {
     return customSecurityConfigs;
   }
 
-  public List<String> getExternalAuthenticationProviders() {
-    return externalAuthenticationProviders;
-  }
-
   public List<UserTelemetryDto> getUserTelemetries() {
     return users;
   }
@@ -149,7 +143,6 @@ public class TelemetryData {
     private Boolean hasUnanalyzedC;
     private Boolean hasUnanalyzedCpp;
     private List<String> customSecurityConfigs;
-    private List<String> externalAuthenticationProviders;
     private List<UserTelemetryDto> users;
     private List<Project> projects;
     private List<ProjectStatistics> projectStatistics;
@@ -158,11 +151,6 @@ public class TelemetryData {
       // enforce static factory method
     }
 
-    Builder setExternalAuthenticationProviders(List<String> providers) {
-      this.externalAuthenticationProviders = providers;
-      return this;
-    }
-
     Builder setServerId(String serverId) {
       this.serverId = serverId;
       return this;
@@ -238,7 +226,6 @@ public class TelemetryData {
       requireNonNull(version);
       requireNonNull(plugins);
       requireNonNull(database);
-      requireNonNull(externalAuthenticationProviders);
 
       return new TelemetryData(this);
     }
index 3bd3dda66e446b81db12d36f2802c43ebc3792ae..c6ab6177ff83301231ec421db17d07c2b60735d4 100644 (file)
@@ -64,11 +64,6 @@ public class TelemetryDataJsonWriter {
     statistics.hasUnanalyzedC().ifPresent(hasUnanalyzedC -> json.prop("hasUnanalyzedC", hasUnanalyzedC));
     statistics.hasUnanalyzedCpp().ifPresent(hasUnanalyzedCpp -> json.prop("hasUnanalyzedCpp", hasUnanalyzedCpp));
 
-    json.name("externalAuthProviders");
-    json.beginArray();
-    statistics.getExternalAuthenticationProviders().forEach(json::value);
-    json.endArray();
-
     if (statistics.getInstallationDate() != null) {
       json.prop("installationDate", toUtc(statistics.getInstallationDate()));
     }
@@ -92,6 +87,7 @@ public class TelemetryDataJsonWriter {
         json.beginObject();
         json.prop("userUuid", DigestUtils.sha3_224Hex(user.getUuid()));
         json.prop("status", user.isActive() ? "active" : "inactive");
+        json.prop("identityProvider", user.getExternalIdentityProvider());
 
         if (user.getLastConnectionDate() != null) {
           json.prop("lastActivity", toUtc(user.getLastConnectionDate()));
index 8782cd1863b6fab062621d7e527e81b93ad80052..4d6d482f62d646e9d3027a750f59d900ea0c6815 100644 (file)
@@ -40,7 +40,6 @@ import org.sonar.core.platform.EditionProvider;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.user.UserTelemetryDto;
 
-import static java.util.Arrays.asList;
 import static java.util.stream.Collectors.joining;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -53,7 +52,6 @@ public class TelemetryDataJsonWriterTest {
     .setServerId("foo")
     .setVersion("bar")
     .setPlugins(Collections.emptyMap())
-    .setExternalAuthenticationProviders(asList("github", "gitlab"))
     .setDatabase(new TelemetryData.Database("H2", "11"));
 
   private final Random random = new Random();
@@ -81,15 +79,6 @@ public class TelemetryDataJsonWriterTest {
     assertThat(json).doesNotContain("edition");
   }
 
-  @Test
-  public void write_external_auth_providers() {
-    TelemetryData data = SOME_TELEMETRY_DATA.build();
-
-    String json = writeTelemetryData(data);
-
-    assertJson(json).isSimilarTo("{ \"externalAuthProviders\": [ \"github\", \"gitlab\" ] }");
-  }
-
   @Test
   @UseDataProvider("allEditions")
   public void writes_edition_if_non_null(EditionProvider.Edition edition) {
@@ -281,18 +270,21 @@ public class TelemetryDataJsonWriterTest {
       "    {" +
       "      \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-0") + "\"," +
       "      \"lastActivity\":\"1970-01-01T00:00:00+0000\"," +
+      "      \"identityProvider\":\"gitlab\"," +
       "      \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," +
       "      \"status\":\"active\"" +
       "    }," +
       "    {" +
       "      \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-1") + "\"," +
       "      \"lastActivity\":\"1970-01-01T00:00:00+0000\"," +
+      "      \"identityProvider\":\"gitlab\"," +
       "      \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," +
       "      \"status\":\"inactive\"" +
       "    }," +
       "    {" +
       "      \"userUuid\":\"" + DigestUtils.sha3_224Hex("uuid-2") + "\"," +
       "      \"lastActivity\":\"1970-01-01T00:00:00+0000\"," +
+      "      \"identityProvider\":\"gitlab\"," +
       "      \"lastSonarlintActivity\":\"1970-01-01T00:00:00+0000\"," +
       "      \"status\":\"active\"" +
       "    }" +
@@ -372,7 +364,9 @@ public class TelemetryDataJsonWriterTest {
 
   @NotNull
   private static List<UserTelemetryDto> getUsers() {
-    return IntStream.range(0, 3).mapToObj(i -> new UserTelemetryDto().setUuid("uuid-" + i).setActive(i % 2 == 0).setLastConnectionDate(1L).setLastSonarlintConnectionDate(2L))
+    return IntStream.range(0, 3)
+      .mapToObj(
+        i -> new UserTelemetryDto().setUuid("uuid-" + i).setActive(i % 2 == 0).setLastConnectionDate(1L).setLastSonarlintConnectionDate(2L).setExternalIdentityProvider("gitlab"))
       .collect(Collectors.toList());
   }
 
index 8a91caa450572ec444d38a60e681c93e20034592..4c6436847520796addbec37242d259d904ff5049 100644 (file)
@@ -121,8 +121,6 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
           data.setHasUnanalyzedCpp(numberOfUnanalyzedCppMeasures > 0);
         });
 
-      data.setExternalAuthenticationProviders(dbClient.userDao().selectExternalIdentityProviders(dbSession));
-
       Map<String, String> scmByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDSCM);
       Map<String, String> ciByProject = getAnalysisPropertyByProject(dbSession, SONAR_ANALYSIS_DETECTEDCI);
       Map<String, ProjectAlmKeyAndProject> almAndUrlByProject = getAlmAndUrlByProject(dbSession);
index bed2ed3e7a056494a5135714af1b277fb062a789..ba4186af014fdc8b010616eea6daa0c941eac9bd 100644 (file)
@@ -34,7 +34,6 @@ import org.sonar.server.property.MapInternalProperties;
 import org.sonar.server.util.GlobalLockManager;
 import org.sonar.server.util.GlobalLockManagerImpl;
 
-import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
@@ -64,8 +63,6 @@ public class TelemetryDaemonTest {
     .setServerId("foo")
     .setVersion("bar")
     .setPlugins(Collections.emptyMap())
-    .setExternalAuthenticationProviders(singletonList("github"))
-    .setExternalAuthenticationProviders(Collections.emptyList())
     .setDatabase(new TelemetryData.Database("H2", "11"))
     .build();
 
index b4fa868a8dfbefbb35d15fedec96379e8a38df1d..1ef601422d5e547f3b60fb0820354df42bb09857 100644 (file)
@@ -154,7 +154,6 @@ public class TelemetryDataLoaderImplTest {
     assertThat(data.getPlugins()).containsOnly(
       entry("java", "4.12.0.11033"), entry("scmgit", "1.2"), entry("other", "undefined"));
     assertThat(data.isInDocker()).isFalse();
-    assertThat(data.getExternalAuthenticationProviders()).containsExactlyInAnyOrder("provider0", "provider1", "provider2");
 
     assertThat(data.getUserTelemetries())
       .extracting(UserTelemetryDto::getUuid, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate, UserTelemetryDto::isActive)