Skip to content

Commit 3e8359c

Browse files
authored
refactor(cli): aws-auth uses modern messaging infrastructure everywhere (#292)
Updates `aws-auth` module to use modern messaging infrastructure. ## Testing - Existing unit and integration tests are passing - Successfully run the auth test suite, with the exception of `tests/test-non-commercial-region.sh` which was skipped. - Manually confirmed that the `AccountAccessKeyCache` is still written - Manually executed common CLI operations and I did not spot any additional output (as expected) --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent d3f6c3c commit 3e8359c

34 files changed

+419
-228
lines changed

packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/messages.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export const IO = {
4545
description: 'Default trace messages emitted from the Toolkit',
4646
}),
4747

48+
// warnings & errors
49+
CDK_TOOLKIT_W0100: make.warn({
50+
code: 'CDK_TOOLKIT_W0100',
51+
description: 'Credential plugin warnings',
52+
}),
53+
4854
// 1: Synth (1xxx)
4955
CDK_TOOLKIT_I1000: make.info<Duration>({
5056
code: 'CDK_TOOLKIT_I1000',
@@ -268,7 +274,6 @@ export const IO = {
268274
description: 'Hotswap disclosure message',
269275
}),
270276

271-
// errors
272277
CDK_TOOLKIT_E5001: make.error({
273278
code: 'CDK_TOOLKIT_E5001',
274279
description: 'No stacks found',
@@ -482,9 +487,17 @@ export const IO = {
482487
}),
483488

484489
// SDK codes
485-
CDK_SDK_I0000: make.trace({
490+
DEFAULT_SDK_TRACE: make.trace({
486491
code: 'CDK_SDK_I0000',
487-
description: 'An SDK message.',
492+
description: 'An SDK trace message.',
493+
}),
494+
DEFAULT_SDK_DEBUG: make.debug({
495+
code: 'CDK_SDK_I0000',
496+
description: 'An SDK debug message.',
497+
}),
498+
DEFAULT_SDK_WARN: make.warn({
499+
code: 'CDK_SDK_W0000',
500+
description: 'An SDK warning message.',
488501
}),
489502
CDK_SDK_I0100: make.trace<SdkTrace>({
490503
code: 'CDK_SDK_I0100',

packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/testing/test-io-host.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { RequireApproval } from '../../../require-approval';
22
import type { IIoHost } from '../../io-host';
33
import type { IoMessage, IoMessageLevel, IoRequest } from '../../io-message';
4+
import type { IoHelper } from '../io-helper';
5+
import { asIoHelper } from '../io-helper';
46
import { isMessageRelevantForLevel } from '../level-priority';
57

68
/**
@@ -26,6 +28,10 @@ export class TestIoHost implements IIoHost {
2628
this.requestSpy = jest.fn();
2729
}
2830

31+
public asHelper(action = 'synth'): IoHelper {
32+
return asIoHelper(this, action as any);
33+
}
34+
2935
public async notify(msg: IoMessage<unknown>): Promise<void> {
3036
if (isMessageRelevantForLevel(msg, this.level)) {
3137
this.notifySpy(msg);

packages/@aws-cdk/toolkit-lib/docs/message-registry.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ group: Documents
1111
| `CDK_TOOLKIT_W0000` | Default warning messages emitted from the Toolkit | `warn` | n/a |
1212
| `CDK_TOOLKIT_E0000` | Default error messages emitted from the Toolkit | `error` | n/a |
1313
| `CDK_TOOLKIT_I0000` | Default trace messages emitted from the Toolkit | `trace` | n/a |
14+
| `CDK_TOOLKIT_W0100` | Credential plugin warnings | `warn` | n/a |
1415
| `CDK_TOOLKIT_I1000` | Provides synthesis times. | `info` | {@link Duration} |
1516
| `CDK_TOOLKIT_I1001` | Cloud Assembly synthesis is starting | `trace` | {@link StackSelectionDetails} |
1617
| `CDK_TOOLKIT_I1901` | Provides stack data | `result` | {@link StackAndAssemblyData} |
@@ -95,5 +96,7 @@ group: Documents
9596
| `CDK_ASSEMBLY_I9999` | Annotations emitted by the cloud assembly | `info` | [cxapi.SynthesisMessage](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_cx-api.SynthesisMessage.html) |
9697
| `CDK_ASSEMBLY_W9999` | Warnings emitted by the cloud assembly | `warn` | [cxapi.SynthesisMessage](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_cx-api.SynthesisMessage.html) |
9798
| `CDK_ASSEMBLY_E9999` | Errors emitted by the cloud assembly | `error` | [cxapi.SynthesisMessage](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_cx-api.SynthesisMessage.html) |
98-
| `CDK_SDK_I0000` | An SDK message. | `trace` | n/a |
99+
| `CDK_SDK_I0000` | An SDK trace message. | `trace` | n/a |
100+
| `CDK_SDK_I0000` | An SDK debug message. | `debug` | n/a |
101+
| `CDK_SDK_W0000` | An SDK warning message. | `warn` | n/a |
99102
| `CDK_SDK_I0100` | An SDK trace. SDK traces are emitted as traces to the IoHost, but contain the original SDK logging level. | `trace` | {@link SdkTrace} |

packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,11 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
128128
private async sdkProvider(action: ToolkitAction): Promise<SdkProvider> {
129129
// @todo this needs to be different instance per action
130130
if (!this._sdkProvider) {
131+
const ioHelper = asIoHelper(this.ioHost, action);
131132
this._sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({
132133
...this.props.sdkConfig,
133-
logger: asSdkLogger(asIoHelper(this.ioHost, action)),
134+
ioHelper,
135+
logger: asSdkLogger(ioHelper),
134136
});
135137
}
136138

packages/aws-cdk/lib/api/aws-auth/account-cache.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as path from 'path';
22
import * as fs from 'fs-extra';
33
import type { Account } from './sdk-provider';
4-
import { debug } from '../../logging';
54
import { cdkCacheDir } from '../../util';
65

76
/**
@@ -16,13 +15,24 @@ export class AccountAccessKeyCache {
1615
*/
1716
public static readonly MAX_ENTRIES = 1000;
1817

18+
/**
19+
* The default path used for the accounts access key cache
20+
*/
21+
public static get DEFAULT_PATH(): string {
22+
// needs to be a getter because cdkCacheDir can be set via env variable and might change
23+
return path.join(cdkCacheDir(), 'accounts_partitions.json');
24+
}
25+
1926
private readonly cacheFile: string;
2027

28+
private readonly debug: (msg: string) => Promise<void>;
29+
2130
/**
2231
* @param filePath Path to the cache file
2332
*/
24-
constructor(filePath?: string) {
25-
this.cacheFile = filePath || path.join(cdkCacheDir(), 'accounts_partitions.json');
33+
constructor(filePath: string = AccountAccessKeyCache.DEFAULT_PATH, debugFn: (msg: string) => Promise<void>) {
34+
this.cacheFile = filePath;
35+
this.debug = debugFn;
2636
}
2737

2838
/**
@@ -40,7 +50,7 @@ export class AccountAccessKeyCache {
4050
// try to get account ID based on this access key ID from disk.
4151
const cached = await this.get(accessKeyId);
4252
if (cached) {
43-
debug(`Retrieved account ID ${cached.accountId} from disk cache`);
53+
await this.debug(`Retrieved account ID ${cached.accountId} from disk cache`);
4454
return cached;
4555
}
4656

0 commit comments

Comments
 (0)