Address comments on pr for k8s oidc authProvider

Signed-off-by: Daniel Bravo <dbravo@vmware.com>
This commit is contained in:
Daniel Bravo
2022-05-06 15:34:33 -05:00
parent 447e060872
commit cdf3ca2b84
8 changed files with 33 additions and 25 deletions
+6 -1
View File
@@ -52,7 +52,12 @@ export interface Config {
/** @visibility secret */
serviceAccountToken?: string;
/** @visibility frontend */
authProvider: 'aws' | 'google' | 'serviceAccount' | 'azure' | 'oidc';
authProvider:
| 'aws'
| 'google'
| 'serviceAccount'
| 'azure'
| 'oidc';
/** @visibility frontend */
oidcTokenProvider?: string;
/** @visibility frontend */
@@ -38,7 +38,9 @@ describe('OidcKubernetesAuthTranslator tests', () => {
...baseClusterDetails,
},
{
oidc: { okta: 'fakeToken' },
auth: {
oidc: { okta: 'fakeToken' },
},
entity,
},
);
@@ -36,7 +36,8 @@ export class OidcKubernetesAuthTranslator implements KubernetesAuthTranslator {
);
}
const authToken: string | undefined = requestBody.oidc?.[oidcTokenProvider];
const authToken: string | undefined =
requestBody.auth?.oidc?.[oidcTokenProvider];
if (authToken) {
clusterDetailsWithAuthToken.serviceAccountToken = authToken;
+4 -5
View File
@@ -194,14 +194,13 @@ export interface KubernetesFetchError {
export interface KubernetesRequestBody {
// (undocumented)
auth?: {
google: string;
google?: string;
oidc?: {
[key: string]: string;
};
};
// (undocumented)
entity: Entity;
// (undocumented)
oidc?: {
[key: string]: string;
};
}
// Warning: (ae-missing-release-tag) "ObjectsByEntityResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
+4 -4
View File
@@ -30,10 +30,10 @@ import { Entity } from '@backstage/catalog-model';
export interface KubernetesRequestBody {
auth?: {
google: string;
};
oidc?: {
[key: string]: string;
google?: string;
oidc?: {
[key: string]: string;
};
};
entity: Entity;
}
@@ -58,7 +58,7 @@ describe('KubernetesAuthProviders tests', () => {
requestBody,
);
expect(details.oidc?.okta).toBe('oktaToken');
expect(details.auth?.oidc?.okta).toBe('oktaToken');
});
it('returns error for unknown authProvider', async () => {
@@ -31,11 +31,13 @@ export class OidcKubernetesAuthProvider implements KubernetesAuthProvider {
requestBody: KubernetesRequestBody,
): Promise<KubernetesRequestBody> {
const authToken: string = await this.authProvider.getIdToken();
if ('oidc' in requestBody) {
requestBody.oidc![this.providerName] = authToken;
const auth = { ...requestBody.auth };
if (auth.oidc) {
auth.oidc[this.providerName] = authToken;
} else {
requestBody.oidc = { [this.providerName]: authToken };
auth.oidc = { [this.providerName]: authToken };
}
requestBody.auth = auth;
return requestBody;
}
}