-
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
Changes from all commits
3fa149d
2679ff8
e0e89f4
2089de9
4cf74df
27a1000
cbab8a5
8f59ff1
939f723
642c7bc
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 |
---|---|---|
|
@@ -144,7 +144,7 @@ def login( | |
password_stdin: bool = False, | ||
tls_verify: bool = True, | ||
hostname: Optional[str] = None, | ||
config_path: Optional[List[str]] = None, | ||
config_path: Optional[str] = None, | ||
) -> dict: | ||
""" | ||
Login to a registry. | ||
|
@@ -161,8 +161,8 @@ def login( | |
:type tls_verify: bool | ||
:param hostname: the hostname to login to | ||
:type hostname: str | ||
: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 | ||
Comment on lines
-164
to
+165
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. align pydoc to above comment. |
||
""" | ||
# Read password from stdin | ||
if password_stdin: | ||
|
@@ -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=[config_path] if config_path else None | ||
) | ||
|
||
# Prepare a new manifest | ||
manifest = oras.oci.NewManifest() | ||
|
@@ -867,7 +869,9 @@ def pull( | |
:type target: str | ||
""" | ||
container = self.get_container(target) | ||
self.auth.load_configs(container, configs=config_path) | ||
self.auth.load_configs( | ||
container, configs=[config_path] if config_path else None | ||
) | ||
manifest = self.get_manifest(container, allowed_media_type) | ||
outdir = outdir or oras.utils.get_tmpdir() | ||
overwrite = overwrite | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,3 +190,40 @@ def test_directory_push_pull_selfsigned_auth( | |
assert str(tmp_path) in files[0] | ||
assert os.path.exists(files[0]) | ||
assert "artifact.txt" in os.listdir(files[0]) | ||
|
||
|
||
@pytest.mark.with_auth(True) | ||
def test_custom_docker_config_path(tmp_path, registry, credentials, target_dir): | ||
Comment on lines
+195
to
+196
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. this provides a test case |
||
""" | ||
Custom docker config_path for login, push, pull | ||
""" | ||
my_dockercfg_path = tmp_path / "myconfig.json" | ||
client = oras.client.OrasClient( | ||
hostname=registry, tls_verify=False, auth_backend="basic" | ||
) | ||
res = client.login( | ||
hostname=registry, | ||
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 commentThe 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. |
||
) | ||
assert res["Status"] == "Login Succeeded" | ||
|
||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. so we use the custom docker config_path during push, |
||
) | ||
assert res.status_code == 201 | ||
|
||
files = client.pull( | ||
target=target_dir, outdir=tmp_path, config_path=my_dockercfg_path | ||
) | ||
Comment on lines
+220
to
+222
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. ... and pull. |
||
assert len(files) == 1 | ||
assert os.path.basename(files[0]) == "upload_data" | ||
assert str(tmp_path) in files[0] | ||
assert os.path.exists(files[0]) | ||
assert "artifact.txt" in os.listdir(files[0]) | ||
|
||
client.logout(registry) |
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
inlogin()
is used to write the credentials to that config_path, after successful loginoras-py/oras/provider.py
Lines 196 to 205 in 6df6127
so I intend this is a "custom file" I want to use,
hence not an optional list,
but an optional str to keep consistency.