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
This commit is contained in:
@@ -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
|
||||
|
@@ -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(
|
||||
|
Reference in New Issue
Block a user