Modify config field to use base api endpoint

allow streaming from gzipped tarball config
This commit is contained in:
Sam Chow 2018-06-21 15:55:17 -04:00
parent aff1a08a83
commit d6d0bb640a
7 changed files with 40 additions and 33 deletions

View file

@ -39,7 +39,7 @@ class InMemoryProvider(BaseProvider):
return any([ name.startswith(filename) for name in self.files ])
def get_volume_file(self, filename, mode='r'):
return self.files[filename]
return io.BytesIO(self.files[filename])
def write_volume_file(self, filename, contents):
raise Exception('Not implemented yet')
@ -48,7 +48,12 @@ class InMemoryProvider(BaseProvider):
raise Exception('Not implemented yet')
def list_volume_directory(self, path):
return [ name for name in self.files if name.startswith(path) ]
def strip_directory(string):
if '/' in string:
return string[string.rfind('/') + 1:]
return string
return [ strip_directory(name) for name in self.files if name.startswith(path) ]
def save_volume_file(self, filename, flask_file):
self.files[filename] = flask_file.read()
@ -66,9 +71,17 @@ class InMemoryProvider(BaseProvider):
def load_from_tarball(self, tarfile):
for tarinfo in tarfile.getmembers():
if tarinfo.isfile():
if tarinfo.name == CONFIG_FILENAME:
self.config = yaml.load(tarfile.extractfile(tarinfo.name).read())
else:
self.files[tarinfo.name] = tarfile.extractfile(tarinfo.name).read()
self.was_loaded = True
self.files[tarinfo.name] = tarfile.extractfile(tarinfo.name).read()
if self.files.has_key(CONFIG_FILENAME):
self.config = yaml.load(self.files.get(CONFIG_FILENAME))
self.was_loaded = True
def load_from_tar_stream(self, tarfile):
for tarinfo in tarfile:
if tarinfo.isfile():
self.files[tarinfo.name] = tarfile.extractfile(tarinfo).read()
if self.files.has_key(CONFIG_FILENAME):
self.config = yaml.load(self.files.get(CONFIG_FILENAME))
self.was_loaded = True