diff options
author | Yanlong Wang <yanlong.wang@naiver.org> | 2023-01-11 06:45:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-10 17:45:25 -0500 |
commit | 22718ba59a193263bed8c52cc1abd5ee52358440 (patch) | |
tree | c3a3aa61fb62b5d07daf0c50d47cc3ac354f54ca | |
parent | d38b41a13c05530eca34691ffd4c70236f8f0d5c (diff) | |
download | docker-py-22718ba59a193263bed8c52cc1abd5ee52358440.tar.gz |
fix(store): warn on init instead of throw (#3080)
Signed-off-by: yanlong.wang <yanlong.wang@naiver.org>
-rw-r--r-- | docker/credentials/store.py | 9 | ||||
-rw-r--r-- | tests/integration/credentials/store_test.py | 7 |
2 files changed, 15 insertions, 1 deletions
diff --git a/docker/credentials/store.py b/docker/credentials/store.py index 297f468..b7ab53f 100644 --- a/docker/credentials/store.py +++ b/docker/credentials/store.py @@ -2,6 +2,7 @@ import errno import json import shutil import subprocess +import warnings from . import constants from . import errors @@ -18,7 +19,7 @@ class Store: self.exe = shutil.which(self.program) self.environment = environment if self.exe is None: - raise errors.InitializationError( + warnings.warn( '{} not installed or not available in PATH'.format( self.program ) @@ -70,6 +71,12 @@ class Store: return json.loads(data.decode('utf-8')) def _execute(self, subcmd, data_input): + if self.exe is None: + raise errors.StoreError( + '{} not installed or not available in PATH'.format( + self.program + ) + ) output = None env = create_environment_dict(self.environment) try: diff --git a/tests/integration/credentials/store_test.py b/tests/integration/credentials/store_test.py index 213cf30..16f4d60 100644 --- a/tests/integration/credentials/store_test.py +++ b/tests/integration/credentials/store_test.py @@ -84,3 +84,10 @@ class TestStore: data = self.store._execute('--null', '') assert b'\0FOO=bar\0' in data assert 'FOO' not in os.environ + + def test_unavailable_store(self): + some_unavailable_store = None + with pytest.warns(UserWarning): + some_unavailable_store = Store('that-does-not-exist') + with pytest.raises(StoreError): + some_unavailable_store.get('anything-this-does-not-matter') |