Merge pull request #5097 from backjo/feat/improveAwsCredLoading

improve credential loading for AWS IAM translator
This commit is contained in:
Ben Lambert
2021-03-29 09:44:46 +02:00
committed by GitHub
3 changed files with 18 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-kubernetes-backend': patch
---
Load credentials properly for AWS Kubernetes Auth Translator
@@ -46,6 +46,8 @@ describe('AwsIamKubernetesAuthTranslator tests', () => {
url: '',
authProvider: 'aws',
});
await expect(promise).rejects.toThrow('no AWS credentials found.');
await expect(promise).rejects.toThrow(
'Could not load credentials from any providers',
);
});
});
@@ -32,7 +32,16 @@ const makeUrlSafe = pipe([replace('+', '-'), replace('/', '_')]);
export class AwsIamKubernetesAuthTranslator
implements KubernetesAuthTranslator {
async getBearerToken(clusterName: string): Promise<string> {
const credentials = AWS.config.credentials;
const credentials = await new Promise((resolve, reject) => {
AWS.config.getCredentials(err => {
if (err) {
reject(err);
} else {
resolve(AWS.config.credentials);
}
});
});
if (!(credentials instanceof Credentials)) {
throw new Error('no AWS credentials found.');
}