Skip to content

Conversation

@mrgrain
Copy link
Contributor

@mrgrain mrgrain commented Mar 28, 2025

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

@mrgrain mrgrain temporarily deployed to integ-approval March 28, 2025 20:03 — with GitHub Actions Inactive
@github-actions github-actions bot added the p2 label Mar 28, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team March 28, 2025 20:05
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a weird change, but i think the abstraction was kind of wrong already.

Copy link
Contributor

Choose a reason for hiding this comment

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

It wasn't an abstraction, it was a set of factory functions grouped in a namespace 😆

};
}

public static proxyAgent(options: SdkHttpOptions) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pulled out into a separate class. this had otherwise nothing to do with this file

@codecov-commenter
Copy link

codecov-commenter commented Mar 28, 2025

Codecov Report

Attention: Patch coverage is 83.67347% with 40 lines in your changes missing coverage. Please review.

Project coverage is 85.62%. Comparing base (445fd71) to head (14f03f3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/aws-cdk/lib/api/aws-auth/proxy-agent.ts 65.45% 19 Missing ⚠️
packages/aws-cdk/lib/api/aws-auth/sdk-provider.ts 77.41% 7 Missing ⚠️
...ages/aws-cdk/lib/api/aws-auth/awscli-compatible.ts 93.02% 6 Missing ⚠️
...helpers/src/api/io/private/testing/test-io-host.ts 33.33% 4 Missing ⚠️
...ges/aws-cdk/lib/api/aws-auth/credential-plugins.ts 70.00% 3 Missing ⚠️
packages/aws-cdk/lib/notices.ts 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #292      +/-   ##
==========================================
+ Coverage   85.54%   85.62%   +0.07%     
==========================================
  Files         222      223       +1     
  Lines       36926    37003      +77     
  Branches     4458     4491      +33     
==========================================
+ Hits        31588    31682      +94     
+ Misses       5248     5222      -26     
- Partials       90       99       +9     
Flag Coverage Δ
suite.unit 85.62% <83.67%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

}
return fs.readFileSync(filename, { encoding: 'utf-8' });
} catch (e: any) {
debug(e);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm removing this debug. This only happens of the file exists but cannot be read, which seems super unliekly. The helper is called from only two places. If someone feels strongly about it, I can implement this in the call-sites.

Copy link
Contributor

Choose a reason for hiding this comment

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

Given this is used in our proxy support, I feel we need any bit of information while debugging strange behavior there. I don't mind dropping it from the user agent construction.

Comment on lines +497 to +502

const options: RequestOptions = {
agent: await new ProxyAgentProvider(this.ioHelper).create(this.options),
};

const notices = await new Promise<Notice[]>((resolve, reject) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bit of a rejig here to allow sending a message after the promise resolved

Copy link
Contributor

Choose a reason for hiding this comment

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

Could just have done a .then() at the end 🤣

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to change it, I don't mind either way. I've received feedback in the past that mixing promise styles is confusing.

): Promise<SuccessfulDeployStackResult | undefined> {
let hotswapProps = hotswapPropertyOverrides || new HotswapPropertyOverrides();
return deployments.tryHotswapDeployment(this, asIoHelper(ioHost, 'deploy'), assetParams, currentCfnStack, stackArtifact, hotswapMode, hotswapProps);
return deployments.tryHotswapDeployment(this, asIoHelper(ioHost, 'deploy'), assetParams, currentCfnStack, stackArtifact, hotswapMode as any, hotswapProps);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a type error before. tryHotswapDeployment only takes two of the 3 enum values and in the CLI code this is enforced. Tests also don't call the method with the third value.

*/
@traceMemberMethods
export class SDK {
private static readonly accountCache = new AccountAccessKeyCache();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this doesn't need to be a singleton. The class is always reading/writing from a file anywhere and does not cache values. If we ever wanted to, we can make the cache a singleton but keep the class as an instance per SDK.

Copy link
Contributor

Choose a reason for hiding this comment

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

It could also be made a constructor argument. Same point as for the proxy agent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could also be made a constructor argument. Same point as for the proxy agent.

True. There is opportunity for refactoring. Right now I want to keep the changes to the minimum to get this in.

@mrgrain mrgrain changed the title refactor(cli): aws-use uses modern messaging infrastructure everywhere refactor(cli): aws-auth uses modern messaging infrastructure everywhere Mar 28, 2025
@mrgrain mrgrain marked this pull request as ready for review April 1, 2025 17:59
@mrgrain mrgrain disabled auto-merge April 2, 2025 11:55
public static requestHandlerBuilder(options: SdkHttpOptions = {}): NodeHttpHandlerOptions {
const agent = this.proxyAgent(options);
public async requestHandlerBuilder(options: SdkHttpOptions = {}): Promise<NodeHttpHandlerOptions> {
const agent = await new ProxyAgentProvider(this.ioHelper).create(options);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are changing these things, it would be better to pass then agent as a constructor argument. Let the SDK Provider, which is the factory class, to also instantiate this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried, but it has a bunch of knock-on effects that I don't want to deal with right now.

*/
@traceMemberMethods
export class SDK {
private static readonly accountCache = new AccountAccessKeyCache();
Copy link
Contributor

Choose a reason for hiding this comment

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

It could also be made a constructor argument. Same point as for the proxy agent.

}
return fs.readFileSync(filename, { encoding: 'utf-8' });
} catch (e: any) {
debug(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Given this is used in our proxy support, I feel we need any bit of information while debugging strange behavior there. I don't mind dropping it from the user agent construction.

* 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.

@mrgrain mrgrain temporarily deployed to integ-approval April 2, 2025 16:42 — with GitHub Actions Inactive
@kaizencc kaizencc added this pull request to the merge queue Apr 2, 2025
Merged via the queue into main with commit 3e8359c Apr 2, 2025
20 checks passed
@kaizencc kaizencc deleted the mrgrain/refactor/messaging-aws-auth branch April 2, 2025 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants