Skip to content

Commit da8458c

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 da8458c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

podman/client.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,20 @@ 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 and "Connection" in config.attrs:
66+
default_connection_name = config.attrs["Connection"]["Default"]
67+
connection = config.attrs["Connection"]["Connections"][default_connection_name]
68+
api_kwargs["base_url"] = connection["URI"]
69+
api_kwargs["identity"] = connection["Identity"]
70+
else:
71+
if "connection" in api_kwargs:
72+
connection = config.services[api_kwargs.get("connection")]
73+
api_kwargs["base_url"] = connection.url.geturl()
74+
# Override configured identity, if provided in arguments
75+
api_kwargs["identity"] = kwargs.get("identity", str(connection.identity))
76+
elif "base_url" not in api_kwargs:
77+
path = str(Path(get_runtime_dir()) / "podman" / "podman.sock")
78+
api_kwargs["base_url"] = "http+unix://" + path
7479
self.api = APIClient(**api_kwargs)
7580

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

0 commit comments

Comments
 (0)