Skip to content

Commit

Permalink
Add support for forcing AR auth for a repo. (#45)
Browse files Browse the repository at this point in the history
* add support for forcing AR auth for a repo if "ar_auth=1" is set in the repo config

* fix issue where fallback keyword isnt supported, like in CentOS 9 DNF

* Change repository config option to "artifact_registry_oauth" to be more explicit to any sysadmins
  • Loading branch information
rafibarash authored Oct 17, 2024
1 parent 054eaa7 commit 8b720fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dnf/artifact-registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ def __init__(self, base, cli):
def config(self):
""" Setup http headers to repos with baseurl option containing pkg.dev. """
for repo in self.base.repos.iter_enabled():
# Check if the 'artifact_registry_oauth' option is set in the repository's config.
if repo.cfg.has_option(repo.id, 'artifact_registry_oauth') and repo.cfg.getboolean(repo.id, 'artifact_registry_oauth'):
self._add_headers(repo)
break # Don't add more than one Authorization header.
# We don't have baseurl option so skip it earlier.
if not hasattr(repo, 'baseurl'):
continue
# Check if any repo urls are for Artifact Registry.
for baseurl in repo.baseurl:
# We stop checking if an error has been flagged.
if baseurl.startswith('https://') and '-yum.pkg.dev/' in baseurl and not self.error:
Expand Down
5 changes: 5 additions & 0 deletions yum/artifact-registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def prereposetup_hook(conduit):
if not token:
return
for repo in conduit.getRepos().listEnabled():
# Check if the 'artifact_registry_oauth' option is set in the repository's config.
if repo.cfg.has_option(repo.id, 'artifact_registry_oauth') and repo.cfg.getboolean(repo.id, 'artifact_registry_oauth'):
_add_headers(token, repo)
break # Stop looking at URLs
# Check if any repo urls are for Artifact Registry.
for url in repo.urls:
if 'pkg.dev' in url and url.startswith('https://'):
_add_headers(token, repo)
Expand Down

0 comments on commit 8b720fa

Please sign in to comment.