-
Notifications
You must be signed in to change notification settings - Fork 39
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
core: add missing prefix property to auth backend #165
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, prefix="https", **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. step 2. unless otherwise specified, this function |
||
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 = prefix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. step 3. this maintains code-style for |
||
return backend |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ class AuthBackend: | |
|
||
def __init__(self, *args, **kwargs): | ||
self._auths: dict = {} | ||
self.prefix: str = "https" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. step 4. the base |
||
|
||
def get_auth_header(self): | ||
raise NotImplementedError | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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, self.prefix) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. step 1. the prefix of provider is set a few lines above: Line 69 in 36ef98a
and is "pass forward" as suggested to the call of |
||||
|
||||
def __repr__(self) -> str: | ||||
return str(self) | ||||
|
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.
@tarilabs this won't always be https - specifically in testing. I think we'd want to inherit this from the parent that created it, and use the same convention there with insecure as a boolean to determine the prefix (and not hard code http or https). Let me know your thoughts.
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 line is specifically about the default isn't it,
and is mainly never used because here:
https://github.com/oras-project/oras-py/pull/165/files#diff-ccb407ceff93417721d33c41bf1975c04c98454fd2a36518a7b8572808db03a4R81
is set explicitly.
am I missing something? 🤔
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.
Yes I think you want to set it based on the insecure parameter:
Which is in the init of the provider.
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.
mmm, I've actually mimic-ed on existing code and did that in line 23 of this file.
making the line you quote:
https://github.com/oras-project/oras-py/pull/165/files#diff-fcbd6629a667f0deb29e01bccd3fa21f8790961f48092d8cee24ad00986706a9R22
another (unused) default.
I'm happy to refactor this code differently if that helps, I was just trying to go with the existing "code convention"? :)