Skip to content

Commit

Permalink
from_env: Use default base_url if no environment is given
Browse files Browse the repository at this point in the history
The PodmanClient class has its own mechanism to detect the default
value for base_url if no specific value is provided. However this
mechanism can't be used when creating an instance by from_env, because
from_env requires (DOCKER|CONTAINER)_HOST environment.

This drops the validation from from_env, so that users can use from_env
without explicitly setting the HOST environment.

Signed-off-by: Takashi Kajinami <[email protected]>
  • Loading branch information
kajinamit committed Feb 12, 2024
1 parent ce63c3d commit 7cee340
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions podman/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,19 @@ def from_env(
if version == "auto":
version = None

kwargs = {
'version': version,
'timeout': timeout,
'tls': False,
'credstore_env': credstore_env,
'max_pool_size': max_pool_size,
}

host = environment.get("CONTAINER_HOST") or environment.get("DOCKER_HOST") or None
if host is None:
raise ValueError("CONTAINER_HOST or DOCKER_HOST must be set to URL of podman service.")

return PodmanClient(
base_url=host,
version=version,
timeout=timeout,
tls=False,
credstore_env=credstore_env,
max_pool_size=max_pool_size,
)
if host is not None:
kwargs['base_url'] = host

return PodmanClient(**kwargs)

@cached_property
def containers(self) -> ContainersManager:
Expand Down

0 comments on commit 7cee340

Please sign in to comment.