Skip to content

Commit d04f825

Browse files
authored
Merge pull request #196 from cdoern/login
podman-py login support
2 parents 56750f8 + 911f69e commit d04f825

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

podman/domain/system.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, Dict, Optional
44

55
from podman.api.client import APIClient
6+
from podman import api
67

78
logger = logging.getLogger("podman.system")
89

@@ -40,8 +41,8 @@ def login(
4041
password: Optional[str] = None,
4142
email: Optional[str] = None,
4243
registry: Optional[str] = None,
43-
reauth: bool = False,
44-
dockercfg_path: Optional[str] = None,
44+
reauth: Optional[bool] = False, # pylint: disable=unused-argument
45+
dockercfg_path: Optional[str] = None, # pylint: disable=unused-argument
4546
) -> Dict[str, Any]:
4647
"""Log into Podman service.
4748
@@ -50,12 +51,27 @@ def login(
5051
password: Registry plaintext password
5152
email: Registry account email address
5253
registry: URL for registry access. For example,
54+
reauth: Ignored: If True, refresh existing authentication. Default: False
55+
dockercfg_path: Ignored: Path to custom configuration file.
5356
https://quay.io/v2
54-
reauth: If True, refresh existing authentication. Default: False
55-
dockercfg_path: Path to custom configuration file.
56-
Default: $HOME/.config/containers/config.json
5757
"""
5858

59+
payload = {
60+
"username": username,
61+
"password": password,
62+
"email": email,
63+
"serveraddress": registry,
64+
}
65+
payload = api.prepare_body(payload)
66+
response = self.client.post(
67+
path="/auth",
68+
headers={"Content-type": "application/json"},
69+
data=payload,
70+
compatible=True,
71+
)
72+
response.raise_for_status()
73+
return response.json()
74+
5975
def ping(self) -> bool:
6076
"""Returns True if service responded with OK."""
6177
response = self.client.head("/_ping")

podman/tests/integration/test_system.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import podman.tests.integration.base as base
1818
from podman import PodmanClient
19+
from podman.errors import APIError
1920

2021

2122
class SystemIntegrationTest(base.IntegrationTest):
@@ -44,3 +45,15 @@ def test_show_disk_usage(self):
4445
self.assertTrue('Images' in output)
4546
self.assertTrue('Containers' in output)
4647
self.assertTrue('Volumes' in output)
48+
49+
def test_login(self):
50+
"""integration: system login call"""
51+
# here, we just test the sanity of the endpoint
52+
# confirming that we get through to podman, and get tcp rejected.
53+
with self.assertRaises(APIError) as e:
54+
next(
55+
self.client.login(
56+
"fake_user", "fake_password", "fake_email@fake_domain.test", "fake_registry"
57+
)
58+
)
59+
self.assertIn("lookup fake_registry: no such host", e.exception.explanation)

0 commit comments

Comments
 (0)