mirror of https://github.com/docker/docker-py.git
Add support for user on exec_create.
This commit is contained in:
parent
d300f5f323
commit
6a5a256509
|
@ -521,19 +521,26 @@ class Client(requests.Session):
|
|||
return self.exec_start(create_res, detach, tty, stream)
|
||||
|
||||
def exec_create(self, container, cmd, stdout=True, stderr=True, tty=False,
|
||||
privileged=False):
|
||||
user=None, privileged=False):
|
||||
if utils.compare_version('1.15', self._version) < 0:
|
||||
raise errors.InvalidVersion('Exec is not supported in API < 1.15')
|
||||
if privileged and utils.compare_version('1.19', self._version) < 0:
|
||||
raise errors.InvalidVersion(
|
||||
'Privileged exec is not supported in API < 1.19'
|
||||
)
|
||||
if user and utils.compare_version('1.19', self._version) < 0:
|
||||
raise errors.InvalidVersion(
|
||||
'User-specific exec is not supported in API < 1.19'
|
||||
)
|
||||
if isinstance(cmd, six.string_types):
|
||||
cmd = shlex.split(str(cmd))
|
||||
|
||||
if user is None:
|
||||
user = ''
|
||||
|
||||
data = {
|
||||
'Container': container,
|
||||
'User': '',
|
||||
'User': user,
|
||||
'Privileged': privileged,
|
||||
'Tty': tty,
|
||||
'AttachStdin': False,
|
||||
|
|
|
@ -829,6 +829,23 @@ class TestExecuteCommandString(BaseTestCase):
|
|||
self.assertEqual(exec_log, expected)
|
||||
|
||||
|
||||
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
|
||||
class TestExecuteCommandStringAsUser(BaseTestCase):
|
||||
def runTest(self):
|
||||
container = self.client.create_container('busybox', 'cat',
|
||||
detach=True, stdin_open=True)
|
||||
id = container['Id']
|
||||
self.client.start(id)
|
||||
self.tmp_containers.append(id)
|
||||
|
||||
res = self.client.exec_create(id, 'whoami', user='default')
|
||||
self.assertIn('Id', res)
|
||||
|
||||
exec_log = self.client.exec_start(res)
|
||||
expected = b'default' if six.PY3 else 'default\n'
|
||||
self.assertEqual(exec_log, expected)
|
||||
|
||||
|
||||
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
|
||||
class TestExecuteCommandStreaming(BaseTestCase):
|
||||
def runTest(self):
|
||||
|
|
Loading…
Reference in New Issue