Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): credential plugin exceptions stop the entire CLI #26244

Merged
merged 6 commits into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions packages/aws-cdk/lib/api/aws-auth/credential-plugins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { debug } from './_env';
import { Mode } from './credentials';
import { warning } from '../../logging';
import { CredentialProviderSource, PluginHost } from '../plugin';

/**
Expand Down Expand Up @@ -33,12 +34,29 @@ export class CredentialPlugins {
const triedSources: CredentialProviderSource[] = [];
// Otherwise, inspect the various credential sources we have
for (const source of PluginHost.instance.credentialProviderSources) {
if (!(await source.isAvailable())) {
let available: boolean;
try {
available = await source.isAvailable();
} catch (e: any) {
// This shouldn't happen, but let's guard against it anyway
warning(`Uncaught exception in ${source.name}: ${e.message}`);
available = false;
}

if (!available) {
debug('Credentials source %s is not available, ignoring it.', source.name);
continue;
}
triedSources.push(source);
if (!(await source.canProvideCredentials(awsAccountId))) { continue; }
let canProvide: boolean;
try {
canProvide = await source.canProvideCredentials(awsAccountId);
} catch (e: any) {
// This shouldn't happen, but let's guard against it anyway
warning(`Uncaught exception in ${source.name}: ${e.message}`);
canProvide = false;
}
if (!canProvide) { continue; }
debug(`Using ${source.name} credentials for account ${awsAccountId}`);
const providerOrCreds = await source.getProvider(awsAccountId, mode);

Expand All @@ -55,4 +73,4 @@ export class CredentialPlugins {
export interface PluginCredentials {
readonly credentials: AWS.Credentials;
readonly pluginName: string;
}
}