Skip to content

Commit

Permalink
core: align config_path type annotation (#166)
Browse files Browse the repository at this point in the history
* core: align config_path type annotation
the oras-py CI setup uses basic auth for auth tests

Signed-off-by: tarilabs <[email protected]>
  • Loading branch information
tarilabs authored Oct 21, 2024
1 parent 6df6127 commit ff9c2e2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions oras/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions oras/tests/test_oras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion oras/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
NAME = "oras"
Expand Down

0 comments on commit ff9c2e2

Please sign in to comment.