Repository navigation
Honour CONTAINER_CONNECTION in PodmanClient.from_env() - #682
Merged
Merged
Conversation
from_env() read CONTAINER_HOST/DOCKER_HOST but ignored CONTAINER_CONNECTION, which the podman CLI honours. The failure was silent: it connected to the local socket and returned plausible data from the wrong machine. Now from_env() resolves CONTAINER_CONNECTION through PodmanConfig.services (the same path as PodmanClient(connection=...)), raises a clear ValueError for unknown connection names instead of silently using the wrong host, and CONTAINER_CONNECTION takes precedence over CONTAINER_HOST, matching the CLI. Four regression tests cover the named-connection, precedence, unknown-name, and no-env cases. Fixes containers#654 Signed-off-by: Ryan McGee <[email protected]>
Member
|
Depends on: #656 |
Member
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #673 — this is the same change, squashed into a single commit with a proper sign-off, per @Honny1's review on #673. The two commits there were authored under one identity and signed off under another, so the DCO check failed; this branch has one commit, signed off by its author. Closing #673 in favor of this PR.
Honour CONTAINER_CONNECTION in PodmanClient.from_env()
Fixes #654
Problem
from_env()readCONTAINER_HOST/DOCKER_HOSTbut ignoredCONTAINER_CONNECTION, which thepodmanCLI honours. The failure was silent: withCONTAINER_CONNECTIONpointing at a remote host,from_env()connected to the local socket and returned entirely plausible data from the wrong machine.Fix
When no explicit
CONTAINER_HOST/DOCKER_HOSTURL is set,from_env()now resolvesCONTAINER_CONNECTIONthroughPodmanConfig.services— the same path asPodmanClient(connection=...)— so the named connection's URL (and identity) is applied. When both are set,CONTAINER_CONNECTIONtakes precedence, matching thepodmanCLI (setupRemoteConnectionchecksCONTAINER_CONNECTIONbeforeCONTAINER_HOST). An unknown connection name raises a clearValueErrorinstead of silently falling back to the local socket. The docstring now documentsCONTAINER_CONNECTION.Tests
Added 4 regression tests in
podman/tests/unit/test_podmanclient.py:test_from_env_container_connection: named connection resolves to its URL and identitytest_from_env_container_connection_takes_precedence: named connection wins over an explicit URLtest_from_env_unknown_connection: unknown name raisesValueErrortest_from_env_no_connection_env: no env vars keeps the local-socket fallback unchangedResults:
python3 -m unittest podman.tests.unit.test_podmanclient: 11/11 passtest_utilsimport error (it shells out to apodmanbinary that isn't installed here; fails identically without this change)ruff check+ruff format --check: cleanmypy podman/client.py: cleanpylint: 10.00/10podman/client.py: 98% (merge bar is 85%)Notes
PodmanClient(connection=...)path, so it picks that fix up automatically.CONTAINER_CONNECTIONvalue without an identity raisesTypeErrorfromServiceConnection.identity; merged together with fix: make service connection identity optional #656 it resolves to the right socket.