summaryrefslogtreecommitdiff
path: root/docker/credentials
diff options
context:
space:
mode:
Diffstat (limited to 'docker/credentials')
-rw-r--r--docker/credentials/store.py31
-rw-r--r--docker/credentials/utils.py28
2 files changed, 9 insertions, 50 deletions
diff --git a/docker/credentials/store.py b/docker/credentials/store.py
index 0017888..297f468 100644
--- a/docker/credentials/store.py
+++ b/docker/credentials/store.py
@@ -1,23 +1,21 @@
import errno
import json
+import shutil
import subprocess
-import six
-
from . import constants
from . import errors
from .utils import create_environment_dict
-from .utils import find_executable
-class Store(object):
+class Store:
def __init__(self, program, environment=None):
""" Create a store object that acts as an interface to
perform the basic operations for storing, retrieving
and erasing credentials using `program`.
"""
self.program = constants.PROGRAM_PREFIX + program
- self.exe = find_executable(self.program)
+ self.exe = shutil.which(self.program)
self.environment = environment
if self.exe is None:
raise errors.InitializationError(
@@ -30,7 +28,7 @@ class Store(object):
""" Retrieve credentials for `server`. If no credentials are found,
a `StoreError` will be raised.
"""
- if not isinstance(server, six.binary_type):
+ if not isinstance(server, bytes):
server = server.encode('utf-8')
data = self._execute('get', server)
result = json.loads(data.decode('utf-8'))
@@ -41,7 +39,7 @@ class Store(object):
# raise CredentialsNotFound
if result['Username'] == '' and result['Secret'] == '':
raise errors.CredentialsNotFound(
- 'No matching credentials in {}'.format(self.program)
+ f'No matching credentials in {self.program}'
)
return result
@@ -61,7 +59,7 @@ class Store(object):
""" Erase credentials for `server`. Raises a `StoreError` if an error
occurs.
"""
- if not isinstance(server, six.binary_type):
+ if not isinstance(server, bytes):
server = server.encode('utf-8')
self._execute('erase', server)
@@ -75,20 +73,9 @@ class Store(object):
output = None
env = create_environment_dict(self.environment)
try:
- if six.PY3:
- output = subprocess.check_output(
- [self.exe, subcmd], input=data_input, env=env,
- )
- else:
- process = subprocess.Popen(
- [self.exe, subcmd], stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, env=env,
- )
- output, _ = process.communicate(data_input)
- if process.returncode != 0:
- raise subprocess.CalledProcessError(
- returncode=process.returncode, cmd='', output=output
- )
+ output = subprocess.check_output(
+ [self.exe, subcmd], input=data_input, env=env,
+ )
except subprocess.CalledProcessError as e:
raise errors.process_store_error(e, self.program)
except OSError as e:
diff --git a/docker/credentials/utils.py b/docker/credentials/utils.py
index 3f720ef..5c83d05 100644
--- a/docker/credentials/utils.py
+++ b/docker/credentials/utils.py
@@ -1,32 +1,4 @@
-import distutils.spawn
import os
-import sys
-
-
-def find_executable(executable, path=None):
- """
- As distutils.spawn.find_executable, but on Windows, look up
- every extension declared in PATHEXT instead of just `.exe`
- """
- if sys.platform != 'win32':
- return distutils.spawn.find_executable(executable, path)
-
- if path is None:
- path = os.environ['PATH']
-
- paths = path.split(os.pathsep)
- extensions = os.environ.get('PATHEXT', '.exe').split(os.pathsep)
- base, ext = os.path.splitext(executable)
-
- if not os.path.isfile(executable):
- for p in paths:
- for ext in extensions:
- f = os.path.join(p, base + ext)
- if os.path.isfile(f):
- return f
- return None
- else:
- return executable
def create_environment_dict(overrides):