Skip to content

Commit

Permalink
fixup! Omit scm-username annotation from the PAT secret
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Jul 20, 2023
1 parent 6a1daa4 commit ea736d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private Optional<PersonalAccessToken> doGetPersonalAccessToken(
String tokenId = annotations.get(ANNOTATION_SCM_PERSONAL_ACCESS_TOKEN_ID);
String organization = annotations.get(ANNOTATION_SCM_ORGANIZATION);
String scmUsername =
scmPersonalAccessTokenFetcher.isValid(
scmPersonalAccessTokenFetcher.getScmUsername(
new PersonalAccessTokenParams(
trimmedUrl, providerName, tokenId, token, organization));
if (!isNullOrEmpty(scmUsername)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void shouldTrimBlankCharsInToken() throws Exception {
KubernetesSecrets secrets = Mockito.mock(KubernetesSecrets.class);
when(namespaceFactory.access(eq(null), eq(meta.getName()))).thenReturn(kubernetesnamespace);
when(kubernetesnamespace.secrets()).thenReturn(secrets);
when(scmPersonalAccessTokenFetcher.isValid(any(PersonalAccessTokenParams.class)))
when(scmPersonalAccessTokenFetcher.getScmUsername(any(PersonalAccessTokenParams.class)))
.thenReturn("user");

Map<String, String> data =
Expand Down Expand Up @@ -163,7 +163,7 @@ public void testGetTokenFromNamespace() throws Exception {
KubernetesSecrets secrets = Mockito.mock(KubernetesSecrets.class);
when(namespaceFactory.access(eq(null), eq(meta.getName()))).thenReturn(kubernetesnamespace);
when(kubernetesnamespace.secrets()).thenReturn(secrets);
when(scmPersonalAccessTokenFetcher.isValid(any(PersonalAccessTokenParams.class)))
when(scmPersonalAccessTokenFetcher.getScmUsername(any(PersonalAccessTokenParams.class)))
.thenReturn("user");

Map<String, String> data1 =
Expand Down Expand Up @@ -217,7 +217,7 @@ public void shouldGetTokenFromASecretWithSCMUsername() throws Exception {
KubernetesSecrets secrets = Mockito.mock(KubernetesSecrets.class);
when(namespaceFactory.access(eq(null), eq(meta.getName()))).thenReturn(kubernetesnamespace);
when(kubernetesnamespace.secrets()).thenReturn(secrets);
when(scmPersonalAccessTokenFetcher.isValid(any(PersonalAccessTokenParams.class)))
when(scmPersonalAccessTokenFetcher.getScmUsername(any(PersonalAccessTokenParams.class)))
.thenReturn("user");

Map<String, String> data =
Expand Down Expand Up @@ -260,7 +260,7 @@ public void shouldGetTokenFromASecretWithoutSCMUsername() throws Exception {
KubernetesSecrets secrets = Mockito.mock(KubernetesSecrets.class);
when(namespaceFactory.access(eq(null), eq(meta.getName()))).thenReturn(kubernetesnamespace);
when(kubernetesnamespace.secrets()).thenReturn(secrets);
when(scmPersonalAccessTokenFetcher.isValid(any(PersonalAccessTokenParams.class)))
when(scmPersonalAccessTokenFetcher.getScmUsername(any(PersonalAccessTokenParams.class)))
.thenReturn("user");

Map<String, String> data =
Expand Down Expand Up @@ -297,7 +297,7 @@ public void testGetTokenFromNamespaceWithTrailingSlashMismatch() throws Exceptio
KubernetesSecrets secrets = Mockito.mock(KubernetesSecrets.class);
when(namespaceFactory.access(eq(null), eq(meta.getName()))).thenReturn(kubernetesnamespace);
when(kubernetesnamespace.secrets()).thenReturn(secrets);
when(scmPersonalAccessTokenFetcher.isValid(any(PersonalAccessTokenParams.class)))
when(scmPersonalAccessTokenFetcher.getScmUsername(any(PersonalAccessTokenParams.class)))
.thenReturn("user");

Map<String, String> data1 =
Expand Down Expand Up @@ -345,7 +345,7 @@ public void shouldDeleteInvalidTokensOnGet() throws Exception {
KubernetesSecrets secrets = Mockito.mock(KubernetesSecrets.class);
when(namespaceFactory.access(eq(null), eq(meta.getName()))).thenReturn(kubernetesnamespace);
when(kubernetesnamespace.secrets()).thenReturn(secrets);
when(scmPersonalAccessTokenFetcher.isValid(any(PersonalAccessTokenParams.class)))
when(scmPersonalAccessTokenFetcher.getScmUsername(any(PersonalAccessTokenParams.class)))
.thenReturn(null);
when(cheServerKubernetesClientFactory.create()).thenReturn(kubeClient);
when(kubeClient.secrets()).thenReturn(secretsMixedOperation);
Expand Down Expand Up @@ -377,7 +377,7 @@ public void shouldReturnFirstValidToken() throws Exception {
KubernetesSecrets secrets = Mockito.mock(KubernetesSecrets.class);
when(namespaceFactory.access(eq(null), eq(meta.getName()))).thenReturn(kubernetesnamespace);
when(kubernetesnamespace.secrets()).thenReturn(secrets);
when(scmPersonalAccessTokenFetcher.isValid(any(PersonalAccessTokenParams.class)))
when(scmPersonalAccessTokenFetcher.getScmUsername(any(PersonalAccessTokenParams.class)))
.thenAnswer(
(Answer<String>)
invocation -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public PersonalAccessToken fetchPersonalAccessToken(Subject cheUser, String scmS
* Iterate over the Set<PersonalAccessTokenFetcher> declared in container and sequentially invoke
* {@link PersonalAccessTokenFetcher#isValid(PersonalAccessToken)} method.
*
* @deprecated use {@link #isValid(PersonalAccessTokenParams)} instead.
* @deprecated use {@link #getScmUsername(PersonalAccessTokenParams)} instead.
* @throws UnknownScmProviderException - if none of PersonalAccessTokenFetchers return a
* meaningful result.
*/
Expand All @@ -82,7 +82,7 @@ public boolean isValid(PersonalAccessToken personalAccessToken)
* fetchers return an scm username, return it. Otherwise, return null.
*/
@Nullable
public String isValid(PersonalAccessTokenParams params)
public String getScmUsername(PersonalAccessTokenParams params)
throws UnknownScmProviderException, ScmUnauthorizedException, ScmCommunicationException {
for (PersonalAccessTokenFetcher fetcher : personalAccessTokenFetchers) {
Optional<Pair<Boolean, String>> isValid = fetcher.isValid(params);
Expand Down

0 comments on commit ea736d1

Please sign in to comment.