diff --git a/CHANGELOG.md b/CHANGELOG.md index adcc11d..f35ed91 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) + - align provider config_path type annotations (0.2.24) - add missing prefix property to auth backend (0.2.23) - allow for filepaths to include `:` (0.2.22) - release request (0.2.21) diff --git a/oras/provider.py b/oras/provider.py index e1d04c1..809ee12 100644 --- a/oras/provider.py +++ b/oras/provider.py @@ -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 """ # 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 diff --git a/oras/tests/test_oras.py b/oras/tests/test_oras.py index 0f16f71..7ebff96 100644 --- a/oras/tests/test_oras.py +++ b/oras/tests/test_oras.py @@ -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): + """ + 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 + ) + 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 + ) + assert res.status_code == 201 + + files = client.pull( + target=target_dir, outdir=tmp_path, config_path=my_dockercfg_path + ) + 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) diff --git a/oras/version.py b/oras/version.py index 7e49a30..2501083 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.23" +__version__ = "0.2.24" AUTHOR = "Vanessa Sochat" EMAIL = "vsoch@users.noreply.github.com" NAME = "oras"