Skip to content

Commit

Permalink
silence warning messages when calling is__Published
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizencc committed May 19, 2023
1 parent 48270f4 commit 93dad51
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion packages/aws-cdk/lib/api/aws-auth/sdk-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class SdkProvider {
environment: cxapi.Environment,
mode: Mode,
options?: CredentialsOptions,
quiet = false,
): Promise<SdkForEnvironment> {
const env = await this.resolveEnvironment(environment);

Expand Down Expand Up @@ -213,7 +214,8 @@ export class SdkProvider {
// but if we can't then let's just try with available credentials anyway.
if (baseCreds.source === 'correctDefault' || baseCreds.source === 'plugin') {
debug(e.message);
warning(`${fmtObtainedCredentials(baseCreds)} could not be used to assume '${options.assumeRoleArn}', but are for the right account. Proceeding anyway.`);
const logger = quiet ? debug : warning;
logger(`${fmtObtainedCredentials(baseCreds)} could not be used to assume '${options.assumeRoleArn}', but are for the right account. Proceeding anyway.`);
return { sdk: new SDK(baseCreds.credentials, env.region, this.sdkOptions), didAssumeRole: false };
}

Expand Down
3 changes: 2 additions & 1 deletion packages/aws-cdk/lib/util/asset-publishing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export class PublishingAws implements cdk_assets.IAws {
env, // region, name, account
assumeRuleArn: options.assumeRoleArn,
assumeRoleExternalId: options.assumeRoleExternalId,
quiet: options.quiet,
});

const maybeSdk = this.sdkCache.get(cacheKey);
Expand All @@ -179,7 +180,7 @@ export class PublishingAws implements cdk_assets.IAws {
const sdk = (await this.aws.forEnvironment(env, Mode.ForWriting, {
assumeRoleArn: options.assumeRoleArn,
assumeRoleExternalId: options.assumeRoleExternalId,
})).sdk;
}, options.quiet)).sdk;
this.sdkCache.set(cacheKey, sdk);

return sdk;
Expand Down
1 change: 1 addition & 0 deletions packages/cdk-assets/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ClientOptions {
region?: string;
assumeRoleArn?: string;
assumeRoleExternalId?: string;
quiet?: boolean;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions packages/cdk-assets/lib/private/handlers/container-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ContainerImageAssetHandler implements IAssetHandler {

public async isPublished(): Promise<boolean> {
try {
const initOnce = await this.initOnce();
const initOnce = await this.initOnce({ quiet: true });
return initOnce.destinationAlreadyExists;
} catch (e: any) {
this.host.emitMessage(EventType.DEBUG, `${e.message}`);
Expand All @@ -73,13 +73,16 @@ export class ContainerImageAssetHandler implements IAssetHandler {
await dockerForPushing.push(initOnce.imageUri);
}

private async initOnce(): Promise<ContainerImageAssetHandlerInit> {
private async initOnce(options: { quiet?: boolean } = {}): Promise<ContainerImageAssetHandlerInit> {
if (this.init) {
return this.init;
}

const destination = await replaceAwsPlaceholders(this.asset.destination, this.host.aws);
const ecr = await this.host.aws.ecrClient(destination);
const ecr = await this.host.aws.ecrClient({
...destination,
quiet: options.quiet,
});
const account = async () => (await this.host.aws.discoverCurrentAccount())?.accountId;

const repoUri = await repositoryUri(ecr, destination.repositoryName);
Expand Down
5 changes: 4 additions & 1 deletion packages/cdk-assets/lib/private/handlers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export class FileAssetHandler implements IAssetHandler {
const destination = await replaceAwsPlaceholders(this.asset.destination, this.host.aws);
const s3Url = `s3://${destination.bucketName}/${destination.objectKey}`;
try {
const s3 = await this.host.aws.s3Client(destination);
const s3 = await this.host.aws.s3Client({
...destination,
quiet: true,
});
this.host.emitMessage(EventType.CHECK, `Check ${s3Url}`);

if (await objectExists(s3, destination.bucketName, destination.objectKey)) {
Expand Down

0 comments on commit 93dad51

Please sign in to comment.