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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
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.

) -> 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
Comment on lines -164 to +165
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.

"""
# 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):
Comment on lines +195 to +196
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

"""
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
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.

)
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
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,

)
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
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.

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 = "vsoch@users.noreply.github.com"
NAME = "oras"
Expand Down
Loading