Skip to content

Conversation

@kevluu-aws
Copy link
Contributor

Problem

Policy Checks currently only uses the default profile within the credentials file for the CLI tool and SDK calls made to A2.

Solution

Pass on the profile name from the current profile setup in AWS Toolkits to the CLI tool and SDK.


License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kevluu-aws kevluu-aws requested a review from a team as a code owner November 21, 2024 00:40
@github-actions
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.
  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

Copy link
Contributor

@jpinkney-aws jpinkney-aws left a comment

Choose a reason for hiding this comment

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

When someone from your team approves I'll merge it

if (isJsonPolicyLanguage(document)) {
telemetry.accessanalyzer_iamPolicyChecksValidatePolicy.run((span) => {
span.record({
documentType,
Copy link

Choose a reason for hiding this comment

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

Firstly, thank you @kevluu-aws for fixing it! 🙌


export function getProfileName(): string | undefined {
// We neeed to split the name on 'profile:' to extract the correct profile name
return globals.awsContext.getCredentialProfileName()?.split('profile:')[1]
Copy link

Choose a reason for hiding this comment

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

Is this a constant format? I am trying to understand who enforces this format?

Copy link

Choose a reason for hiding this comment

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

Also, can we add an error message on the backend to determine any incorrect format here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Toolkits uses the format in displaying the profile name to users after authenticating through the extension. It's stored with profile: prepended in the Credentials object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed we should probably refactor the profile name in to a data object instead. It doesnt need to be done in this PR.

Also, can we add an error message on the backend to determine any incorrect format here?

There shouldn't be a need to determine incorrect formats as the format of this data should have been validated here and then right after we create the name with this format.

'--template-path',
IamPolicyChecksWebview.editedDocumentFileName,
'--region',
'us-east-1',
Copy link

Choose a reason for hiding this comment

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

Can we add a test that will help us determine if there is any change to the expected format in the getProfileName() function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CLI tool tests check for a profile to be passed as undefined. This will check if the 'profile:' part gets changed

Copy link

Choose a reason for hiding this comment

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

Had a chat with Kevin offline regarding if there is a way for us to catch the change in the format of the profile name, and he confirmed that it should be caught in the unit tests.

@justinmk3
Copy link
Contributor

Does this fix a user-facing symptom? If so, please add a changelog as described in #6074 (comment)

@kevluu-aws
Copy link
Contributor Author

Added changelog describing the fix

@justinmk3
Copy link
Contributor

Please try doing a squash-merge locally (git merge --squash, or whatever tool you prefer). That will fix the commit history here.

If this still adds 1700 lines of code then next question is why :)

@kevluu-aws kevluu-aws force-pushed the master branch 2 times, most recently from 48370e4 to 8e02176 Compare January 24, 2025 00:27
@kevluu-aws
Copy link
Contributor Author

Please try doing a squash-merge locally (git merge --squash, or whatever tool you prefer). That will fix the commit history here.

If this still adds 1700 lines of code then next question is why :)

Accidental rebasing caused it, just fixed it and rebased with updated changelog

@justinmk3
Copy link
Contributor

The jscpd ci check (for redundant code) is failing, and its logs point to code that could easily be deduplicated with minimal effort.

'--region',
'us-east-1',
'--profile',
'undefined',
Copy link
Contributor

@justinmk3 justinmk3 Jan 28, 2025

Choose a reason for hiding this comment

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

All of the tests assert "undefined". If this PR is intended to support the non-undefined case, at least one test should assert that case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These test cases do not actually ever use this argument, as we stub the actual execution of our CLI tool here. It simply looks at the global globals.awsContext.getCredentialProfileName(), which is undefined in the test execution context.

Is there a way to change the current profile in the test execution context? If we are able to, we can assert it is propagated properly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to change the current profile in the test execution context?

Look at existing code.

@kevluu-aws kevluu-aws requested a review from justinmk3 January 28, 2025 22:04
@justinmk3
Copy link
Contributor

Merging to unblock. Please followup on the above comments.

@justinmk3 justinmk3 merged commit 3f16d7d into aws:master Jan 28, 2025
25 of 26 checks passed
s7ab059789 pushed a commit to s7ab059789/aws-toolkit-vscode that referenced this pull request Feb 19, 2025
## Problem
Policy Checks currently only uses the default profile within the
credentials file for the CLI tool and SDK calls made to A2.

## Solution
Pass on the profile name from the current profile setup in AWS Toolkits
to the CLI tool and SDK.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants