From 3fa149d6aa9544e3f692c65b372d88cb3eced900 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Sun, 20 Oct 2024 10:47:19 +0200 Subject: [PATCH 01/10] core: align config_path type annotation Signed-off-by: tarilabs --- oras/provider.py | 10 +++++----- oras/tests/test_oras.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/oras/provider.py b/oras/provider.py index e1d04c1..a2e0b64 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,7 @@ 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]) # Prepare a new manifest manifest = oras.oci.NewManifest() @@ -867,7 +867,7 @@ def pull( :type target: str """ container = self.get_container(target) - self.auth.load_configs(container, configs=config_path) + self.auth.load_configs(container, configs=None if config_path is None else [config_path]) 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..6209419 100644 --- a/oras/tests/test_oras.py +++ b/oras/tests/test_oras.py @@ -190,3 +190,33 @@ 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(False) +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) + 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) From 2679ff88094414d3feb931fdb0351a7e0fd0d185 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Sun, 20 Oct 2024 10:48:35 +0200 Subject: [PATCH 02/10] tmp Signed-off-by: tarilabs --- .github/workflows/auth-tests.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auth-tests.yaml b/.github/workflows/auth-tests.yaml index ff67209..d540b8c 100644 --- a/.github/workflows/auth-tests.yaml +++ b/.github/workflows/auth-tests.yaml @@ -1,6 +1,6 @@ name: Oras Auth Tests -on: - pull_request: [] + +on: [push, pull_request] jobs: test-auth: From e0e89f4799877542a0a0bd7a06aef4d88b45ea79 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Sun, 20 Oct 2024 10:52:55 +0200 Subject: [PATCH 03/10] keep Signed-off-by: tarilabs --- oras/tests/test_oras.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/oras/tests/test_oras.py b/oras/tests/test_oras.py index 6209419..1d9cb05 100644 --- a/oras/tests/test_oras.py +++ b/oras/tests/test_oras.py @@ -192,7 +192,7 @@ def test_directory_push_pull_selfsigned_auth( assert "artifact.txt" in os.listdir(files[0]) -@pytest.mark.with_auth(False) +@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 @@ -208,6 +208,9 @@ def test_custom_docker_config_path(tmp_path, registry, credentials, target_dir): ) assert res["Status"] == "Login Succeeded" + with open(my_dockercfg_path, "r") as f: + print(f.read()) + # 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) From 2089de91813237bcad050cfbfc6bec85761b06f4 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Sun, 20 Oct 2024 10:55:09 +0200 Subject: [PATCH 04/10] tmp Signed-off-by: tarilabs --- scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index 8a5e9e8..03b814e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -20,4 +20,4 @@ printf "ORAS_REGISTRY: ${ORAS_REGISTRY}\n" printf "ORAS_AUTH: ${ORAS_AUTH}\n" # Client (command line) tests -pytest -xs oras/ +pytest -xs oras/ -vv From 4cf74df4a8b1113035c3ef673d47013ec9280f53 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Sun, 20 Oct 2024 11:01:54 +0200 Subject: [PATCH 05/10] keep: test use basic the oras-py CI setup uses basic auth for auth tests Signed-off-by: tarilabs --- oras/tests/test_oras.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/oras/tests/test_oras.py b/oras/tests/test_oras.py index 1d9cb05..d8b7de0 100644 --- a/oras/tests/test_oras.py +++ b/oras/tests/test_oras.py @@ -198,7 +198,9 @@ 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) + client = oras.client.OrasClient( + hostname=registry, tls_verify=False, auth_backend="basic" + ) res = client.login( hostname=registry, tls_verify=False, From 27a10008d919e3dad6aee8006eeb3ee716ac5989 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Sun, 20 Oct 2024 11:07:07 +0200 Subject: [PATCH 06/10] Revert "tmp" This reverts commit 2679ff88094414d3feb931fdb0351a7e0fd0d185. Signed-off-by: tarilabs --- .github/workflows/auth-tests.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auth-tests.yaml b/.github/workflows/auth-tests.yaml index d540b8c..ff67209 100644 --- a/.github/workflows/auth-tests.yaml +++ b/.github/workflows/auth-tests.yaml @@ -1,6 +1,6 @@ name: Oras Auth Tests - -on: [push, pull_request] +on: + pull_request: [] jobs: test-auth: From cbab8a5595e247adade5b1f8168fca8c3b15fcd0 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Sun, 20 Oct 2024 11:07:26 +0200 Subject: [PATCH 07/10] Revert "tmp" This reverts commit 2089de91813237bcad050cfbfc6bec85761b06f4. Signed-off-by: tarilabs --- scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index 03b814e..8a5e9e8 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -20,4 +20,4 @@ printf "ORAS_REGISTRY: ${ORAS_REGISTRY}\n" printf "ORAS_AUTH: ${ORAS_AUTH}\n" # Client (command line) tests -pytest -xs oras/ -vv +pytest -xs oras/ From 8f59ff1c30ca1363ded5bc87a8aff495cd3d97c9 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Sun, 20 Oct 2024 11:08:17 +0200 Subject: [PATCH 08/10] cleanups Signed-off-by: tarilabs --- oras/provider.py | 8 ++++++-- oras/tests/test_oras.py | 14 ++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/oras/provider.py b/oras/provider.py index a2e0b64..1c57bd1 100644 --- a/oras/provider.py +++ b/oras/provider.py @@ -729,7 +729,9 @@ def push( """ container = self.get_container(target) files = files or [] - self.auth.load_configs(container, configs=None if config_path is None else [config_path]) + self.auth.load_configs( + container, configs=None if config_path is None else [config_path] + ) # 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=None if config_path is None else [config_path]) + self.auth.load_configs( + container, configs=None if config_path is None else [config_path] + ) 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 d8b7de0..7ebff96 100644 --- a/oras/tests/test_oras.py +++ b/oras/tests/test_oras.py @@ -206,18 +206,20 @@ def test_custom_docker_config_path(tmp_path, registry, credentials, target_dir): tls_verify=False, username=credentials.user, password=credentials.password, - config_path=my_dockercfg_path, # <-- for login + config_path=my_dockercfg_path, # <-- for login ) assert res["Status"] == "Login Succeeded" - with open(my_dockercfg_path, "r") as f: - print(f.read()) - # 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) + 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) + + 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] From 939f72318b5b9871ecf4a08c931decd1497f80c7 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Mon, 21 Oct 2024 09:25:02 +0200 Subject: [PATCH 09/10] implement review feedback Signed-off-by: tarilabs Co-authored-by: vsoch --- oras/provider.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oras/provider.py b/oras/provider.py index 1c57bd1..809ee12 100644 --- a/oras/provider.py +++ b/oras/provider.py @@ -730,7 +730,7 @@ def push( container = self.get_container(target) files = files or [] self.auth.load_configs( - container, configs=None if config_path is None else [config_path] + container, configs=[config_path] if config_path else None ) # Prepare a new manifest @@ -870,7 +870,7 @@ def pull( """ container = self.get_container(target) self.auth.load_configs( - container, configs=None if config_path is None else [config_path] + container, configs=[config_path] if config_path else None ) manifest = self.get_manifest(container, allowed_media_type) outdir = outdir or oras.utils.get_tmpdir() From 642c7bc1dc3f6698dfe5825a0015818a46e12e2a Mon Sep 17 00:00:00 2001 From: tarilabs Date: Mon, 21 Oct 2024 09:30:38 +0200 Subject: [PATCH 10/10] bump version and maintain changelog entry Signed-off-by: tarilabs --- CHANGELOG.md | 1 + oras/version.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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/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"