Merge 6a67b3f666 into aa213c3003
commit
b36e0f3f43
|
|
@ -7,7 +7,8 @@ metadata:
|
|||
app.kubernetes.io/part-of: che.eclipse.org
|
||||
annotations:
|
||||
che.eclipse.org/che-userid: che-user-id
|
||||
che.eclipse.org/scm-personal-access-token-name: git-provider-name
|
||||
che.eclipse.org/scm-personal-access-token-name: token-name
|
||||
che.eclipse.org/scm-provider-name: git-provider-name
|
||||
che.eclipse.org/scm-url: git-provider-url
|
||||
che.eclipse.org/scm-organization: ''
|
||||
data:
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ public class KubernetesPersonalAccessTokenManager implements PersonalAccessToken
|
|||
PersonalAccessToken personalAccessToken =
|
||||
new PersonalAccessToken(
|
||||
personalAccessTokenParams.getScmProviderUrl(),
|
||||
getScmProviderName(personalAccessTokenParams),
|
||||
personalAccessTokenParams.getScmProviderName(),
|
||||
secretAnnotations.get(ANNOTATION_CHE_USERID),
|
||||
personalAccessTokenParams.getOrganization(),
|
||||
scmUsername.get(),
|
||||
|
|
@ -242,20 +242,6 @@ public class KubernetesPersonalAccessTokenManager implements PersonalAccessToken
|
|||
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<String, String> secretAnnotations = secret.getMetadata().getAnnotations();
|
||||
LOG.debug("Secret annotations: {}", secretAnnotations);
|
||||
|
|
@ -263,8 +249,7 @@ public class KubernetesPersonalAccessTokenManager implements PersonalAccessToken
|
|||
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
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
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 class KubernetesPersonalAccessTokenManagerTest {
|
|||
new ObjectMetaBuilder()
|
||||
.withAnnotations(
|
||||
Map.of(
|
||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
||||
ANNOTATION_SCM_PROVIDER_NAME,
|
||||
"github",
|
||||
ANNOTATION_CHE_USERID,
|
||||
"user1",
|
||||
|
|
|
|||
Loading…
Reference in New Issue