-
Notifications
You must be signed in to change notification settings - Fork 34
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: align config_path type annotation #166
core: align config_path type annotation #166
Conversation
Signed-off-by: tarilabs <matteo.mortari@gmail.com>
the oras-py CI setup uses basic auth for auth tests Signed-off-by: tarilabs <matteo.mortari@gmail.com>
This reverts commit 2679ff8. Signed-off-by: tarilabs <matteo.mortari@gmail.com>
This reverts commit 2089de9. Signed-off-by: tarilabs <matteo.mortari@gmail.com>
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 is my proposal minimizing changes.
My understanding is that config_path on provider.py methods is intended to specify a custom docker config_path where to write the credentials to on successful login, and to lookup the credentials from on push/pull.
On separate note, my understanding is that also utils.py load_configs is an utility function to load auths from multiple places, ie the default homedir docker config and a custom list of supplied paths.
config_path: Optional[List[str]] = None, | ||
config_path: Optional[str] = None, |
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.
the config_path
in login()
is used to write the credentials to that config_path, after successful login
Lines 196 to 205 in 6df6127
dockercfg_path=config_path, | |
) | |
# Fallback to manual login | |
except Exception: | |
return login.DockerClient().login( | |
username=username, # type: ignore | |
password=password, # type: ignore | |
registry=hostname, # type: ignore | |
dockercfg_path=config_path, |
so I intend this is a "custom file" I want to use,
hence not an optional list,
but an optional str to keep consistency.
:param config_path: list of config paths to add | ||
:type config_path: list | ||
:param config_path: custom config path to add credentials to | ||
:type config_path: str |
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.
align pydoc to above comment.
oras/provider.py
Outdated
self.auth.load_configs(container, configs=config_path) | ||
self.auth.load_configs( | ||
container, configs=None if config_path is None else [config_path] | ||
) |
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 makes an internal call to
Line 86 in 6df6127
def load_configs(self, container: container_type, configs: Optional[list] = None): |
in turn,
Line 14 in 6df6127
def load_configs(configs: Optional[List[str]] = None): |
that has capabilities to load credentials from multiple files.
So, if the user has specified its own custom docker config_path, we pass it, otherwise None.
oras/provider.py
Outdated
self.auth.load_configs(container, configs=config_path) | ||
self.auth.load_configs( | ||
container, configs=None if config_path is None else [config_path] | ||
) |
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.
analogous as above comment, for pull
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.
Ditto here to simplify the statement.
@pytest.mark.with_auth(True) | ||
def test_custom_docker_config_path(tmp_path, registry, credentials, target_dir): |
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 provides a test case
tls_verify=False, | ||
username=credentials.user, | ||
password=credentials.password, | ||
config_path=my_dockercfg_path, # <-- for login |
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.
see first comment; here we specify a custom docker config_path where the credentials are written to on successful login.
# Test push/pull with custom docker config_path | ||
upload_dir = os.path.join(here, "upload_data") | ||
res = client.push( | ||
files=[upload_dir], target=target_dir, config_path=my_dockercfg_path |
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.
so we use the custom docker config_path during push,
files = client.pull( | ||
target=target_dir, outdir=tmp_path, config_path=my_dockercfg_path | ||
) |
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.
... and pull.
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.
I like this design better @tarilabs ! I forget why we originally did a list - I do remember there was a reason and even at the time I thought it would be more likely to have just one config. Just a few tweaks to the statement I pointed out and this should be good.
oras/provider.py
Outdated
@@ -729,7 +729,9 @@ def push( | |||
""" | |||
container = self.get_container(target) | |||
files = files or [] | |||
self.auth.load_configs(container, configs=config_path) | |||
self.auth.load_configs( | |||
container, configs=None if config_path is None else [config_path] |
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.
You could probably do [config_path] if config_path else None
oras/provider.py
Outdated
self.auth.load_configs(container, configs=config_path) | ||
self.auth.load_configs( | ||
container, configs=None if config_path is None else [config_path] | ||
) |
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.
Ditto here to simplify the statement.
Signed-off-by: tarilabs <matteo.mortari@gmail.com> Co-authored-by: vsoch <vsoch@users.noreply.github.com>
Make sense, I wanted to highlight the "most likely case" (ie no custom config_path) but I agree is much more readable this way; thanks for the review! |
Signed-off-by: tarilabs <matteo.mortari@gmail.com>
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.
Looks great, thanks @tarilabs !
thanks @vsoch ! 🚀 |
ref #164 (comment)
will add explanation on this proposal after raising the PR