Skip to content
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

Support for multiple CodeArtifact repositories? #2

Closed
jfly opened this issue Jun 4, 2024 · 3 comments
Closed

Support for multiple CodeArtifact repositories? #2

jfly opened this issue Jun 4, 2024 · 3 comments
Assignees

Comments

@jfly
Copy link

jfly commented Jun 4, 2024

The current configuration options don't seem to be nuanced enough to support multiple CodeArtifact repositories at once.

It looks like this would be a straightforward change (at the time we load the config, we already know the url of the repository we're dealing with).

Would you be open to adding more granularly scoped configuration options? I'm not terribly familiar with ini files, but one way of doing this would be with more sections:

$ cat keyringrc.cfg
[codeartifact]
# 30 minutes
token_duration = 1800
profile_name = global-profile

[codeartifact.domain1-dev]
url = "https://domain1-999999999999.d.codeartifact.us-west-2.amazonaws.com/pypi/domain1-dev/simple/"
profile_name = domain1-dev

[codeartifact.domain1-prod]
url = "https://domain1-999999999999.d.codeartifact.us-west-2.amazonaws.com/pypi/domain1-prod/simple/"
profile_name = domain1-prod

In the above example, the names of the sections don't really matter, they just need to be unique. An alternative would be to jam these urls into the section names (for example [codeartifact.https://domain1-999999999999.d.codeartifact.us-west-2.amazonaws.com/pypi/domain1-prod/simple/]), but that feels a little ugly/unwieldy IMO.

This would be backwards compatible with the existing options, but would take precedence if the url matches one of these subsections.

If you're open to this, I'd be happy to send in a PR implementing it.

(tangentially related: jaraco/keyring#682)

@jmkeyes
Copy link
Owner

jmkeyes commented Jun 16, 2024

Hey @jfly, thanks for submitting this issue!

I've pushed up an implementation of this to the multiple-config-sections branch. Here's a sample from the README:

# These are the defaults for other sections.
[codeartifact]
token_duration = 1800

# Use for any repositories in account 000000000000.
[codeartifact account="000000000000"]
profile_name = special_profile

# Use for account 999999999999 with a repository named "staging".
[codeartifact account="999999999999" name="staging"]
profile_name = staging_profile

Or using your sample configuration with some tweaks:

[codeartifact]
# 30 minutes
token_duration = 1800
profile_name = global-profile

[codeartifact domain="domain1" account="999999999999" region="us-west-2" name="domain1-dev"]
profile_name = domain1-dev

[codeartifact domain="domain1" account="999999999999" region="us-west-2" name="domain1-prod"]
profile_name = domain1-prod

If you'd like to give it a try yourself, you can install it with this pip command:

# Or add the following URL to your `requirements.txt`. 
python -m pip install git+https://github.com/jmkeyes/keyrings.codeartifact.git@multiple-config-sections

@jmkeyes jmkeyes self-assigned this Jun 16, 2024
@jmkeyes
Copy link
Owner

jmkeyes commented Jun 17, 2024

I've added some unit testing around this functionality and released it as 1.3.0 in 46e83fe.

Let me know if it works for you!

@jfly
Copy link
Author

jfly commented Jul 30, 2024

Thanks, @jmkeyes!

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

No branches or pull requests

2 participants