Read tarball into in-memory config provider
This commit is contained in:
parent
8aa18a29a8
commit
bb2b28cd11
5 changed files with 83 additions and 9 deletions
|
@ -1,9 +1,13 @@
|
|||
from config_app.config_util.config.fileprovider import FileConfigProvider
|
||||
from config_app.config_util.config.testprovider import TestConfigProvider
|
||||
from config_app.config_util.config.inmemoryprovider import InMemoryProvider
|
||||
|
||||
|
||||
def get_config_provider(config_volume, yaml_filename, py_filename, testing=False):
|
||||
""" Loads and returns the config provider for the current environment. """
|
||||
if True:
|
||||
return InMemoryProvider()
|
||||
|
||||
if testing:
|
||||
return TestConfigProvider()
|
||||
|
||||
|
|
66
config_app/config_util/config/inmemoryprovider.py
Normal file
66
config_app/config_util/config/inmemoryprovider.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
import logging
|
||||
import yaml
|
||||
|
||||
from config_app.config_util.config.baseprovider import BaseProvider
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_FILENAME = 'config.yaml'
|
||||
|
||||
class InMemoryProvider(BaseProvider):
|
||||
def __init__(self):
|
||||
self.files = {}
|
||||
self.config = {}
|
||||
|
||||
@property
|
||||
def provider_id(self):
|
||||
return 'memory'
|
||||
|
||||
def update_app_config(self, app_config):
|
||||
self.config = app_config
|
||||
|
||||
def get_config(self):
|
||||
return self.config
|
||||
|
||||
def save_config(self, config_object):
|
||||
raise Exception('Not implemented yet')
|
||||
|
||||
def config_exists(self):
|
||||
raise Exception('Not implemented yet')
|
||||
|
||||
def volume_exists(self):
|
||||
raise Exception('Not implemented yet')
|
||||
|
||||
def volume_file_exists(self, filename):
|
||||
return filename in self.files
|
||||
|
||||
def get_volume_file(self, filename, mode='r'):
|
||||
return self.files[filename]
|
||||
|
||||
def write_volume_file(self, filename, contents):
|
||||
raise Exception('Not implemented yet')
|
||||
|
||||
def remove_volume_file(self, filename):
|
||||
raise Exception('Not implemented yet')
|
||||
|
||||
def list_volume_directory(self, path):
|
||||
return [ name for name in self.files ]
|
||||
|
||||
def save_volume_file(self, filename, flask_file):
|
||||
raise Exception('Not implemented yet')
|
||||
|
||||
def requires_restart(self, app_config):
|
||||
raise Exception('Not implemented yet')
|
||||
|
||||
def get_volume_path(self, directory, filename):
|
||||
raise Exception('Not implemented yet')
|
||||
|
||||
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()
|
||||
|
Reference in a new issue