diff --git a/infrastructures/infrastructure-factory/src/main/java/org/eclipse/che/api/factory/server/scm/kubernetes/KubernetesPersonalAccessTokenManager.java b/infrastructures/infrastructure-factory/src/main/java/org/eclipse/che/api/factory/server/scm/kubernetes/KubernetesPersonalAccessTokenManager.java index 869808717a..47cceea106 100644 --- a/infrastructures/infrastructure-factory/src/main/java/org/eclipse/che/api/factory/server/scm/kubernetes/KubernetesPersonalAccessTokenManager.java +++ b/infrastructures/infrastructure-factory/src/main/java/org/eclipse/che/api/factory/server/scm/kubernetes/KubernetesPersonalAccessTokenManager.java @@ -212,7 +212,7 @@ private Optional doGetPersonalAccessToken( PersonalAccessToken personalAccessToken = new PersonalAccessToken( personalAccessTokenParams.getScmProviderUrl(), - getScmProviderName(personalAccessTokenParams), + personalAccessTokenParams.getScmProviderName(), secretAnnotations.get(ANNOTATION_CHE_USERID), personalAccessTokenParams.getOrganization(), scmUsername.get(), @@ -242,20 +242,6 @@ private Optional doGetPersonalAccessToken( return Optional.empty(); } - /** - * Returns the name of the SCM provider. If the name is not set, the name of the token is used. - * This is used to support back compatibility with the old token secrets, which do not have the - * 'che.eclipse.org/scm-provider-name' annotation. - * - * @param params the parameters of the personal access token - * @return the name of the SCM provider - */ - private String getScmProviderName(PersonalAccessTokenParams params) { - return isNullOrEmpty(params.getScmProviderName()) - ? params.getScmTokenName() - : params.getScmProviderName(); - } - private boolean deleteSecretIfMisconfigured(Secret secret) throws InfrastructureException { Map secretAnnotations = secret.getMetadata().getAnnotations(); LOG.debug("Secret annotations: {}", secretAnnotations); @@ -263,8 +249,7 @@ private boolean deleteSecretIfMisconfigured(Secret secret) throws Infrastructure LOG.debug("SCM server URL: {}", configuredScmServerUrl); String configuredCheUserId = secretAnnotations.get(ANNOTATION_CHE_USERID); LOG.debug("Che user ID: {}", configuredCheUserId); - String configuredOAuthProviderName = - secretAnnotations.get(ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME); + String configuredOAuthProviderName = secretAnnotations.get(ANNOTATION_SCM_PROVIDER_NAME); LOG.debug("OAuth provider name: {}", configuredOAuthProviderName); // if any of the required annotations is missing, the secret is not valid diff --git a/infrastructures/infrastructure-factory/src/test/java/org/eclipse/che/api/factory/server/scm/kubernetes/KubernetesPersonalAccessTokenManagerTest.java b/infrastructures/infrastructure-factory/src/test/java/org/eclipse/che/api/factory/server/scm/kubernetes/KubernetesPersonalAccessTokenManagerTest.java index 7556e46569..6b770178d1 100644 --- a/infrastructures/infrastructure-factory/src/test/java/org/eclipse/che/api/factory/server/scm/kubernetes/KubernetesPersonalAccessTokenManagerTest.java +++ b/infrastructures/infrastructure-factory/src/test/java/org/eclipse/che/api/factory/server/scm/kubernetes/KubernetesPersonalAccessTokenManagerTest.java @@ -104,7 +104,7 @@ public void shouldTrimBlankCharsInToken() throws Exception { new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user", @@ -187,7 +187,7 @@ public void testGetTokenFromNamespace() throws Exception { new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1", @@ -198,7 +198,7 @@ public void testGetTokenFromNamespace() throws Exception { new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1", @@ -209,7 +209,7 @@ public void testGetTokenFromNamespace() throws Exception { new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user2", @@ -255,7 +255,7 @@ public void shouldGetTokenFromASecretWithSCMUsername() throws Exception { new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1", @@ -300,7 +300,7 @@ public void shouldGetTokenFromASecretWithoutSCMUsername() throws Exception { new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1", @@ -345,7 +345,7 @@ public void testGetTokenFromNamespaceWithTrailingSlashMismatch() throws Exceptio new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1", @@ -356,7 +356,7 @@ public void testGetTokenFromNamespaceWithTrailingSlashMismatch() throws Exceptio new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1", @@ -402,11 +402,7 @@ public void shouldDeleteMisconfiguredTokensOnGet() throws Exception { new ObjectMetaBuilder() .withNamespace("test") .withAnnotations( - Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, - "github", - ANNOTATION_CHE_USERID, - "user1")) + Map.of(ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1")) .build(); Secret secret1 = new SecretBuilder().withMetadata(meta1).withData(data1).build(); when(secrets.get(any(LabelSelector.class))).thenReturn(Arrays.asList(secret1)); @@ -439,7 +435,7 @@ public void shouldDeleteInvalidTokensOnGet() throws Exception { new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1", @@ -486,7 +482,7 @@ public void shouldReturnFirstValidToken() throws Exception { new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1", @@ -499,7 +495,7 @@ public void shouldReturnFirstValidToken() throws Exception { new ObjectMetaBuilder() .withAnnotations( Map.of( - ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME, + ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1",