Authenticate using codeartifact token via environment variable#19
Authenticate using codeartifact token via environment variable#19nicholsn wants to merge 4 commits intojmkeyes:mainfrom
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.
This block could be moved to the top of the get_password method and shortcut most of the logic.
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.
The CODEARTIFACT_AUTH_TOKEN environment variable could be moved into a constant.
There was a problem hiding this comment.
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.