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

core: align config_path type annotation #166

Merged

Conversation

tarilabs
Copy link
Contributor

ref #164 (comment)

will add explanation on this proposal after raising the PR

Signed-off-by: tarilabs <matteo.mortari@gmail.com>
Signed-off-by: tarilabs <matteo.mortari@gmail.com>
Signed-off-by: tarilabs <matteo.mortari@gmail.com>
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>
Signed-off-by: tarilabs <matteo.mortari@gmail.com>
Copy link
Contributor Author

@tarilabs tarilabs left a 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,
Copy link
Contributor Author

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

oras-py/oras/provider.py

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.

Comment on lines -164 to +165
: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
Copy link
Contributor Author

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
Comment on lines 732 to 734
self.auth.load_configs(container, configs=config_path)
self.auth.load_configs(
container, configs=None if config_path is None else [config_path]
)
Copy link
Contributor Author

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

def load_configs(self, container: container_type, configs: Optional[list] = None):

in turn,

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
Comment on lines 870 to 874
self.auth.load_configs(container, configs=config_path)
self.auth.load_configs(
container, configs=None if config_path is None else [config_path]
)
Copy link
Contributor Author

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

Copy link
Contributor

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.

Comment on lines +195 to +196
@pytest.mark.with_auth(True)
def test_custom_docker_config_path(tmp_path, registry, credentials, target_dir):
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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,

Comment on lines +220 to +222
files = client.pull(
target=target_dir, outdir=tmp_path, config_path=my_dockercfg_path
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and pull.

Copy link
Contributor

@vsoch vsoch left a 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]
Copy link
Contributor

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
Comment on lines 870 to 874
self.auth.load_configs(container, configs=config_path)
self.auth.load_configs(
container, configs=None if config_path is None else [config_path]
)
Copy link
Contributor

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>
@tarilabs
Copy link
Contributor Author

Just a few tweaks to the statement I pointed out and this should be good.

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!

@tarilabs tarilabs requested a review from vsoch October 21, 2024 07:28
Signed-off-by: tarilabs <matteo.mortari@gmail.com>
Copy link
Contributor

@vsoch vsoch left a 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 !

@vsoch vsoch merged commit ff9c2e2 into oras-project:main Oct 21, 2024
5 checks passed
@tarilabs
Copy link
Contributor Author

thanks @vsoch ! 🚀

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

Successfully merging this pull request may close these issues.

2 participants