Skip to content

Commit df2e7e0

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 df2e7e0

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

podman/client.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,32 @@ def __init__(self, **kwargs) -> None:
5959
"""
6060
super().__init__()
6161
config = PodmanConfig()
62-
6362
api_kwargs = kwargs.copy()
6463

64+
# Case 1: Use named connection from kwargs if specified
6565
if "connection" in api_kwargs:
66+
logger.debug("Using kwargs")
6667
connection = config.services[api_kwargs.get("connection")]
6768
api_kwargs["base_url"] = connection.url.geturl()
68-
69+
logger.debug("Connection URL: %s", api_kwargs["base_url"])
6970
# Override configured identity, if provided in arguments
7071
api_kwargs["identity"] = kwargs.get("identity", str(connection.identity))
71-
elif "base_url" not in api_kwargs:
72+
73+
# Case 2: No kwargs provided - try to load from system configuration
74+
elif not api_kwargs and "Connection" in config.attrs:
75+
logger.debug("Using System Configuration")
76+
default_connection_name = config.attrs["Connection"]["Default"]
77+
connection = config.attrs["Connection"]["Connections"][default_connection_name]
78+
api_kwargs["base_url"] = connection["URI"]
79+
api_kwargs["identity"] = connection["Identity"]
80+
logger.debug("Connection URL: %s", api_kwargs["base_url"])
81+
82+
# Case 3: Fallback - if no base_url is specified, use default socket path
83+
if "base_url" not in api_kwargs:
7284
path = str(Path(get_runtime_dir()) / "podman" / "podman.sock")
7385
api_kwargs["base_url"] = "http+unix://" + path
86+
logger.debug("Using Default Socket Path: %s", api_kwargs["base_url"])
87+
7488
self.api = APIClient(**api_kwargs)
7589

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

0 commit comments

Comments
 (0)