-
Notifications
You must be signed in to change notification settings - Fork 10
Authenticate using codeartifact token via environment variable #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@jmkeyes snagging this from alxbrd@6f50c45 |
|
Note that I'm using this in a GHA CI/CD pipeline where I'm installing dependencies from codeartifact in a docker container that is being pushed to ECR in a different account. This is somewhat similar use case as #6 where I assume a role to get the token outside of docker and then pass it in as an env var to install the package. |
|
@jmkeyes any thoughts on this? |
|
Hey @nicholsn! Thanks for the contribution! I think this is a great idea: being able to short circuit the keyring backend lookup process and pass through the token with an environment variable is a great idea. I do have some outstanding questions:
I'll submit my review of the code itself shortly. |
keyrings/codeartifact.py
Outdated
| ) | ||
|
|
||
| # Check for token in environment variable | ||
| token_from_env = os.getenv("CODEARTIFACT_AUTH_TOKEN") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block could be moved to the top of the get_password method and shortcut most of the logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, moved it up!
keyrings/codeartifact.py
Outdated
| ) | ||
|
|
||
| # Check for token in environment variable | ||
| token_from_env = os.getenv("CODEARTIFACT_AUTH_TOKEN") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CODEARTIFACT_AUTH_TOKEN environment variable could be moved into a constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and brought in pulling the name of the environment variable to use from the config
@jmkeyes Please find my answers to the questions you raised:
|
That works for me!
I was referring to your commit 6f50c45 that @nicholsn referenced above which uses
Ok, perfect! |
|
@jmkeyes lmk if you want to see any additional changes before merging |
This pull request introduces support for using an environment variable (
CODEARTIFACT_AUTH_TOKEN) to bypass AWS API calls when interacting with CodeArtifact, enhancing usability in CI/CD environments and simplifying token management. The changes include updates to documentation, backend logic, and test cases.Documentation Updates:
README.md: Added instructions for setting theCODEARTIFACT_AUTH_TOKENenvironment variable to bypass AWS API calls, with examples for usage in CI/CD environments.Backend Logic Enhancements:
keyrings/codeartifact.py: Updated theget_passwordmethod to check for theCODEARTIFACT_AUTH_TOKENenvironment variable and use it if available, logging the usage for transparency.keyrings/codeartifact.py: Imported theosmodule to support environment variable retrieval.Testing Improvements:
tests/test_backend.py: Added a new test case (test_get_credential_from_env) to verify that the backend can retrieve credentials from theCODEARTIFACT_AUTH_TOKENenvironment variable and bypass client creation when the variable is set.