Skip to content

Commit f8f753e

Browse files
committed
Correctly load configuration when instantiating new client without kwargs
The init function of PodmanClient was never loading the system configuration when no kwargs were specified. This change makes it so that we load the core data (base_url and identity) from the config file. Signed-off-by: Anish Asthana <[email protected]>
1 parent e46c204 commit f8f753e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

podman/client.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,21 @@ def __init__(self, **kwargs) -> None:
6262

6363
api_kwargs = kwargs.copy()
6464

65-
if "connection" in api_kwargs:
66-
connection = config.services[api_kwargs.get("connection")]
67-
api_kwargs["base_url"] = connection.url.geturl()
68-
69-
# Override configured identity, if provided in arguments
70-
api_kwargs["identity"] = kwargs.get("identity", str(connection.identity))
71-
elif "base_url" not in api_kwargs:
72-
path = str(Path(get_runtime_dir()) / "podman" / "podman.sock")
73-
api_kwargs["base_url"] = "http+unix://" + path
65+
if not api_kwargs:
66+
if "Connection" in config.attrs:
67+
default_connection_name = config.attrs["Connection"]["Default"]
68+
connection = config.attrs["Connection"]["Connections"][default_connection_name]
69+
api_kwargs["base_url"] = connection["URI"]
70+
api_kwargs["identity"] = connection["Identity"]
71+
else:
72+
if "connection" in api_kwargs:
73+
connection = config.services[api_kwargs.get("connection")]
74+
api_kwargs["base_url"] = connection.url.geturl()
75+
# Override configured identity, if provided in arguments
76+
api_kwargs["identity"] = kwargs.get("identity", str(connection.identity))
77+
elif "base_url" not in api_kwargs:
78+
path = str(Path(get_runtime_dir()) / "podman" / "podman.sock")
79+
api_kwargs["base_url"] = "http+unix://" + path
7480
self.api = APIClient(**api_kwargs)
7581

7682
def __enter__(self) -> "PodmanClient":

0 commit comments

Comments
 (0)