From 3d0457ebe0e95560de1c5803281ddf13f6dfe25e Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 30 Sep 2018 23:33:27 +0000 Subject: [PATCH] Encode injected file data in containers module We encode file content before sending it via HTTP. In before, we encode injected file content in CLI shell module so the file is encoded only when users are using CLI commands. This commit moves encoding down to containers module so that it will be available for non-CLI users as well. Change-Id: I9638ee363ae85c36e421dc997fe2dcad5d4d71cc --- zunclient/common/utils.py | 2 +- zunclient/v1/containers.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/zunclient/common/utils.py b/zunclient/common/utils.py index 55590ee3..c8a75084 100644 --- a/zunclient/common/utils.py +++ b/zunclient/common/utils.py @@ -248,7 +248,7 @@ def parse_mounts(mounts): # TODO(hongbin): handle the case that 'source' is a directory filename = mount_info.pop('source') with open(filename, 'rb') as file: - mount_info['source'] = encode_file_data(file.read()) + mount_info['source'] = file.read() parsed_mounts.append(mount_info) return parsed_mounts diff --git a/zunclient/v1/containers.py b/zunclient/v1/containers.py index a187d1dd..438e9f6d 100644 --- a/zunclient/v1/containers.py +++ b/zunclient/v1/containers.py @@ -96,6 +96,7 @@ class ContainerManager(base.Manager): def create(self, **kwargs): self._process_command(kwargs) + self._process_mounts(kwargs) new = {} for (key, value) in kwargs.items(): @@ -113,6 +114,13 @@ class ContainerManager(base.Manager): if command: kwargs['command'] = utils.parse_command(command) + def _process_mounts(self, kwargs): + mounts = kwargs.get('mounts', None) + if mounts: + for mount in mounts: + if mount['type'] == 'bind': + mount['source'] = utils.encode_file_data(mount['source']) + def delete(self, id, **kwargs): return self._delete(self._path(id), qparams=kwargs) @@ -170,6 +178,7 @@ class ContainerManager(base.Manager): def run(self, **kwargs): self._process_command(kwargs) + self._process_mounts(kwargs) if not set(kwargs).issubset(CREATION_ATTRIBUTES): raise exceptions.InvalidAttribute(