Skip to content

Commit

Permalink
Add missing parameters for login method
Browse files Browse the repository at this point in the history
- Handle the URL scheme based on TLS
- Since the 'auth' argument is not well documented in the podman
  swagger it will follow the same here until the swagger is better
  documented

Signed-off-by: Milan Balazs <[email protected]>
  • Loading branch information
milanbalazs authored and inknos committed Sep 25, 2024
1 parent 1767eea commit 46d321f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 5 additions & 2 deletions podman/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def post(
Keyword Args:
compatible: Will override the default path prefix with compatible prefix
verify: Whether to verify TLS certificates.
Raises:
APIError: when service returns an error
Expand Down Expand Up @@ -400,6 +401,7 @@ def _request(
Keyword Args:
compatible: Will override the default path prefix with compatible prefix
verify: Whether to verify TLS certificates.
Raises:
APIError: when service returns an error
Expand All @@ -415,10 +417,10 @@ def _request(

path = path.lstrip("/") # leading / makes urljoin crazy...

# TODO should we have an option for HTTPS support?
scheme = "https" if kwargs.get("verify", None) else "http"
# Build URL for operation from base_url
uri = urllib.parse.ParseResult(
"http",
scheme,
self.base_url.netloc,
urllib.parse.urljoin(path_prefix, path),
self.base_url.params,
Expand All @@ -435,6 +437,7 @@ def _request(
data=data,
headers=(headers or {}),
stream=stream,
verify=kwargs.get("verify", None),
**timeout_kw,
)
)
Expand Down
19 changes: 16 additions & 3 deletions podman/domain/system.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""SystemManager to provide system level information from Podman service."""

import logging
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, Union

from podman.api.client import APIClient
from podman import api
Expand Down Expand Up @@ -42,8 +42,12 @@ def login( # pylint: disable=too-many-arguments,too-many-positional-arguments,u
password: Optional[str] = None,
email: Optional[str] = None,
registry: Optional[str] = None,
reauth: Optional[bool] = False, # pylint: disable=unused-argument
dockercfg_path: Optional[str] = None, # pylint: disable=unused-argument
reauth: Optional[bool] = False,
dockercfg_path: Optional[str] = None,
auth: Optional[str] = None,
identitytoken: Optional[str] = None,
registrytoken: Optional[str] = None,
tls_verify: Optional[Union[bool, str]] = None,
) -> Dict[str, Any]:
"""Log into Podman service.
Expand All @@ -55,20 +59,29 @@ def login( # pylint: disable=too-many-arguments,too-many-positional-arguments,u
reauth: Ignored: If True, refresh existing authentication. Default: False
dockercfg_path: Ignored: Path to custom configuration file.
https://quay.io/v2
auth: TODO: Add description based on the source code of Podman.
identitytoken: IdentityToken is used to authenticate the user and
get an access token for the registry.
registrytoken: RegistryToken is a bearer token to be sent to a registry
tls_verify: Whether to verify TLS certificates.
"""

payload = {
"username": username,
"password": password,
"email": email,
"serveraddress": registry,
"auth": auth,
"identitytoken": identitytoken,
"registrytoken": registrytoken,
}
payload = api.prepare_body(payload)
response = self.client.post(
path="/auth",
headers={"Content-type": "application/json"},
data=payload,
compatible=True,
verify=tls_verify, # Pass tls_verify to the client
)
response.raise_for_status()
return response.json()
Expand Down

0 comments on commit 46d321f

Please sign in to comment.