Merge 6a67b3f666 into aa213c3003
commit
b36e0f3f43
|
|
@ -7,7 +7,8 @@ metadata:
|
||||||
app.kubernetes.io/part-of: che.eclipse.org
|
app.kubernetes.io/part-of: che.eclipse.org
|
||||||
annotations:
|
annotations:
|
||||||
che.eclipse.org/che-userid: che-user-id
|
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-url: git-provider-url
|
||||||
che.eclipse.org/scm-organization: ''
|
che.eclipse.org/scm-organization: ''
|
||||||
data:
|
data:
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ public class KubernetesPersonalAccessTokenManager implements PersonalAccessToken
|
||||||
PersonalAccessToken personalAccessToken =
|
PersonalAccessToken personalAccessToken =
|
||||||
new PersonalAccessToken(
|
new PersonalAccessToken(
|
||||||
personalAccessTokenParams.getScmProviderUrl(),
|
personalAccessTokenParams.getScmProviderUrl(),
|
||||||
getScmProviderName(personalAccessTokenParams),
|
personalAccessTokenParams.getScmProviderName(),
|
||||||
secretAnnotations.get(ANNOTATION_CHE_USERID),
|
secretAnnotations.get(ANNOTATION_CHE_USERID),
|
||||||
personalAccessTokenParams.getOrganization(),
|
personalAccessTokenParams.getOrganization(),
|
||||||
scmUsername.get(),
|
scmUsername.get(),
|
||||||
|
|
@ -242,20 +242,6 @@ public class KubernetesPersonalAccessTokenManager implements PersonalAccessToken
|
||||||
return Optional.empty();
|
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 {
|
private boolean deleteSecretIfMisconfigured(Secret secret) throws InfrastructureException {
|
||||||
Map<String, String> secretAnnotations = secret.getMetadata().getAnnotations();
|
Map<String, String> secretAnnotations = secret.getMetadata().getAnnotations();
|
||||||
LOG.debug("Secret annotations: {}", secretAnnotations);
|
LOG.debug("Secret annotations: {}", secretAnnotations);
|
||||||
|
|
@ -263,8 +249,7 @@ public class KubernetesPersonalAccessTokenManager implements PersonalAccessToken
|
||||||
LOG.debug("SCM server URL: {}", configuredScmServerUrl);
|
LOG.debug("SCM server URL: {}", configuredScmServerUrl);
|
||||||
String configuredCheUserId = secretAnnotations.get(ANNOTATION_CHE_USERID);
|
String configuredCheUserId = secretAnnotations.get(ANNOTATION_CHE_USERID);
|
||||||
LOG.debug("Che user ID: {}", configuredCheUserId);
|
LOG.debug("Che user ID: {}", configuredCheUserId);
|
||||||
String configuredOAuthProviderName =
|
String configuredOAuthProviderName = secretAnnotations.get(ANNOTATION_SCM_PROVIDER_NAME);
|
||||||
secretAnnotations.get(ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME);
|
|
||||||
LOG.debug("OAuth provider name: {}", configuredOAuthProviderName);
|
LOG.debug("OAuth provider name: {}", configuredOAuthProviderName);
|
||||||
|
|
||||||
// if any of the required annotations is missing, the secret is not valid
|
// if any of the required annotations is missing, the secret is not valid
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user",
|
"user",
|
||||||
|
|
@ -187,7 +187,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user1",
|
"user1",
|
||||||
|
|
@ -198,7 +198,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user1",
|
"user1",
|
||||||
|
|
@ -209,7 +209,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user2",
|
"user2",
|
||||||
|
|
@ -255,7 +255,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user1",
|
"user1",
|
||||||
|
|
@ -300,7 +300,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user1",
|
"user1",
|
||||||
|
|
@ -345,7 +345,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user1",
|
"user1",
|
||||||
|
|
@ -356,7 +356,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user1",
|
"user1",
|
||||||
|
|
@ -402,11 +402,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withNamespace("test")
|
.withNamespace("test")
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(ANNOTATION_SCM_PROVIDER_NAME, "github", ANNOTATION_CHE_USERID, "user1"))
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
|
||||||
"github",
|
|
||||||
ANNOTATION_CHE_USERID,
|
|
||||||
"user1"))
|
|
||||||
.build();
|
.build();
|
||||||
Secret secret1 = new SecretBuilder().withMetadata(meta1).withData(data1).build();
|
Secret secret1 = new SecretBuilder().withMetadata(meta1).withData(data1).build();
|
||||||
when(secrets.get(any(LabelSelector.class))).thenReturn(Arrays.asList(secret1));
|
when(secrets.get(any(LabelSelector.class))).thenReturn(Arrays.asList(secret1));
|
||||||
|
|
@ -439,7 +435,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user1",
|
"user1",
|
||||||
|
|
@ -486,7 +482,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user1",
|
"user1",
|
||||||
|
|
@ -499,7 +495,7 @@ public class KubernetesPersonalAccessTokenManagerTest {
|
||||||
new ObjectMetaBuilder()
|
new ObjectMetaBuilder()
|
||||||
.withAnnotations(
|
.withAnnotations(
|
||||||
Map.of(
|
Map.of(
|
||||||
ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_NAME,
|
ANNOTATION_SCM_PROVIDER_NAME,
|
||||||
"github",
|
"github",
|
||||||
ANNOTATION_CHE_USERID,
|
ANNOTATION_CHE_USERID,
|
||||||
"user1",
|
"user1",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue