Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export const IO = {
description: 'Default trace messages emitted from the Toolkit',
}),

// warnings & errors
CDK_TOOLKIT_W0100: make.warn({
code: 'CDK_TOOLKIT_W0100',
description: 'Credential plugin warnings',
}),

// 1: Synth (1xxx)
CDK_TOOLKIT_I1000: make.info<Duration>({
code: 'CDK_TOOLKIT_I1000',
Expand Down Expand Up @@ -268,7 +274,6 @@ export const IO = {
description: 'Hotswap disclosure message',
}),

// errors
CDK_TOOLKIT_E5001: make.error({
code: 'CDK_TOOLKIT_E5001',
description: 'No stacks found',
Expand Down Expand Up @@ -482,9 +487,17 @@ export const IO = {
}),

// SDK codes
CDK_SDK_I0000: make.trace({
DEFAULT_SDK_TRACE: make.trace({
code: 'CDK_SDK_I0000',
description: 'An SDK message.',
description: 'An SDK trace message.',
}),
DEFAULT_SDK_DEBUG: make.debug({
code: 'CDK_SDK_I0000',
description: 'An SDK debug message.',
}),
DEFAULT_SDK_WARN: make.warn({
code: 'CDK_SDK_W0000',
description: 'An SDK warning message.',
}),
CDK_SDK_I0100: make.trace<SdkTrace>({
code: 'CDK_SDK_I0100',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { RequireApproval } from '../../../require-approval';
import type { IIoHost } from '../../io-host';
import type { IoMessage, IoMessageLevel, IoRequest } from '../../io-message';
import type { IoHelper } from '../io-helper';
import { asIoHelper } from '../io-helper';
import { isMessageRelevantForLevel } from '../level-priority';

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

public asHelper(action = 'synth'): IoHelper {
return asIoHelper(this, action as any);
}

public async notify(msg: IoMessage<unknown>): Promise<void> {
if (isMessageRelevantForLevel(msg, this.level)) {
this.notifySpy(msg);
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/toolkit-lib/docs/message-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ group: Documents
| `CDK_TOOLKIT_W0000` | Default warning messages emitted from the Toolkit | `warn` | n/a |
| `CDK_TOOLKIT_E0000` | Default error messages emitted from the Toolkit | `error` | n/a |
| `CDK_TOOLKIT_I0000` | Default trace messages emitted from the Toolkit | `trace` | n/a |
| `CDK_TOOLKIT_W0100` | Credential plugin warnings | `warn` | n/a |
| `CDK_TOOLKIT_I1000` | Provides synthesis times. | `info` | {@link Duration} |
| `CDK_TOOLKIT_I1001` | Cloud Assembly synthesis is starting | `trace` | {@link StackSelectionDetails} |
| `CDK_TOOLKIT_I1901` | Provides stack data | `result` | {@link StackAndAssemblyData} |
Expand Down Expand Up @@ -95,5 +96,7 @@ group: Documents
| `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) |
| `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) |
| `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) |
| `CDK_SDK_I0000` | An SDK message. | `trace` | n/a |
| `CDK_SDK_I0000` | An SDK trace message. | `trace` | n/a |
| `CDK_SDK_I0000` | An SDK debug message. | `debug` | n/a |
| `CDK_SDK_W0000` | An SDK warning message. | `warn` | n/a |
| `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} |
4 changes: 3 additions & 1 deletion packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
private async sdkProvider(action: ToolkitAction): Promise<SdkProvider> {
// @todo this needs to be different instance per action
if (!this._sdkProvider) {
const ioHelper = asIoHelper(this.ioHost, action);
this._sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({
...this.props.sdkConfig,
logger: asSdkLogger(asIoHelper(this.ioHost, action)),
ioHelper,
logger: asSdkLogger(ioHelper),
});
}

Expand Down
18 changes: 14 additions & 4 deletions packages/aws-cdk/lib/api/aws-auth/account-cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import type { Account } from './sdk-provider';
import { debug } from '../../logging';
import { cdkCacheDir } from '../../util';

/**
Expand All @@ -16,13 +15,24 @@ export class AccountAccessKeyCache {
*/
public static readonly MAX_ENTRIES = 1000;

/**
* The default path used for the accounts access key cache
*/
public static get DEFAULT_PATH(): string {
// needs to be a getter because cdkCacheDir can be set via env variable and might change
Copy link
Contributor

@rix0rrr rix0rrr Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...during tests?

(Trying to wrap my head around how an env var might change across the execution)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

during tests, but in toolkit-lib it could be at any point of the code execution.

return path.join(cdkCacheDir(), 'accounts_partitions.json');
}

private readonly cacheFile: string;

private readonly debug: (msg: string) => Promise<void>;

/**
* @param filePath Path to the cache file
*/
constructor(filePath?: string) {
this.cacheFile = filePath || path.join(cdkCacheDir(), 'accounts_partitions.json');
constructor(filePath: string = AccountAccessKeyCache.DEFAULT_PATH, debugFn: (msg: string) => Promise<void>) {
this.cacheFile = filePath;
this.debug = debugFn;
}

/**
Expand All @@ -40,7 +50,7 @@ export class AccountAccessKeyCache {
// try to get account ID based on this access key ID from disk.
const cached = await this.get(accessKeyId);
if (cached) {
debug(`Retrieved account ID ${cached.accountId} from disk cache`);
await this.debug(`Retrieved account ID ${cached.accountId} from disk cache`);
return cached;
}

Expand Down
Loading