From 6df61271f68ee9c066f9a78d59ab3bb68f8fe960 Mon Sep 17 00:00:00 2001 From: Matteo Mortari Date: Sun, 20 Oct 2024 00:28:45 +0200 Subject: [PATCH] core: add missing prefix property to auth backend (#165) * core: add missing prefix property to auth backend ref https://github.com/oras-project/oras-py/issues/164#issuecomment-2419535612 Signed-off-by: tarilabs --- CHANGELOG.md | 1 + oras/auth/__init__.py | 3 ++- oras/auth/base.py | 1 + oras/provider.py | 2 +- oras/version.py | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee1d657a..adcc11d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are: The versions coincide with releases on pip. Only major versions will be released as tags on Github. ## [0.0.x](https://github.com/oras-project/oras-py/tree/main) (0.0.x) + - add missing prefix property to auth backend (0.2.23) - allow for filepaths to include `:` (0.2.22) - release request (0.2.21) - add missing basic auth data for request token function in token auth backend (0.2.2) diff --git a/oras/auth/__init__.py b/oras/auth/__init__.py index ff6b65fd..6ea5900d 100644 --- a/oras/auth/__init__.py +++ b/oras/auth/__init__.py @@ -14,10 +14,11 @@ class AuthenticationException(Exception): pass -def get_auth_backend(name="token", session=None, **kwargs): +def get_auth_backend(name="token", session=None, insecure=False, **kwargs): backend = auth_backends.get(name) if not backend: raise ValueError(f"Authentication backend {backend} is not known.") backend = backend(**kwargs) backend.session = session or requests.Session() + backend.prefix = "http" if insecure else "https" return backend diff --git a/oras/auth/base.py b/oras/auth/base.py index 37098e50..8dd7ad88 100644 --- a/oras/auth/base.py +++ b/oras/auth/base.py @@ -19,6 +19,7 @@ class AuthBackend: def __init__(self, *args, **kwargs): self._auths: dict = {} + self.prefix: str = "https" def get_auth_header(self): raise NotImplementedError diff --git a/oras/provider.py b/oras/provider.py index ff2e950e..e1d04c11 100644 --- a/oras/provider.py +++ b/oras/provider.py @@ -78,7 +78,7 @@ def __init__( self.session.cookies.set_policy(DefaultCookiePolicy(allowed_domains=[])) # Get custom backend, pass on session to share - self.auth = oras.auth.get_auth_backend(auth_backend, self.session) + self.auth = oras.auth.get_auth_backend(auth_backend, self.session, insecure) def __repr__(self) -> str: return str(self) diff --git a/oras/version.py b/oras/version.py index b2787066..7e49a300 100644 --- a/oras/version.py +++ b/oras/version.py @@ -2,7 +2,7 @@ __copyright__ = "Copyright The ORAS Authors." __license__ = "Apache-2.0" -__version__ = "0.2.22" +__version__ = "0.2.23" AUTHOR = "Vanessa Sochat" EMAIL = "vsoch@users.noreply.github.com" NAME = "oras"