2018-08-27 21:05:53 +00:00
|
|
|
import base64
|
|
|
|
import os
|
|
|
|
|
2018-05-23 20:57:26 +00:00
|
|
|
from config_app.config_util.config.fileprovider import FileConfigProvider
|
|
|
|
from config_app.config_util.config.testprovider import TestConfigProvider
|
2018-06-28 17:45:26 +00:00
|
|
|
from config_app.config_util.config.TransientDirectoryProvider import TransientDirectoryProvider
|
2018-08-27 21:05:53 +00:00
|
|
|
from util.config.validator import EXTRA_CA_DIRECTORY, EXTRA_CA_DIRECTORY_PREFIX
|
2018-05-21 21:02:38 +00:00
|
|
|
|
|
|
|
|
2018-06-08 19:33:54 +00:00
|
|
|
def get_config_provider(config_volume, yaml_filename, py_filename, testing=False):
|
2018-08-15 19:32:24 +00:00
|
|
|
""" Loads and returns the config provider for the current environment. """
|
2018-06-18 20:01:30 +00:00
|
|
|
|
2018-08-15 19:32:24 +00:00
|
|
|
if testing:
|
|
|
|
return TestConfigProvider()
|
2018-05-21 21:02:38 +00:00
|
|
|
|
2018-08-15 19:32:24 +00:00
|
|
|
return TransientDirectoryProvider(config_volume, yaml_filename, py_filename)
|
2018-08-27 21:05:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_config_as_kube_secret(config_path):
|
|
|
|
data = {}
|
|
|
|
|
|
|
|
# Kubernetes secrets don't have sub-directories, so for the extra_ca_certs dir
|
|
|
|
# we have to put the extra certs in with a prefix, and then one of our init scripts
|
|
|
|
# (02_get_kube_certs.sh) will expand the prefixed certs into the equivalent directory
|
|
|
|
# so that they'll be installed correctly on startup by the certs_install script
|
|
|
|
certs_dir = os.path.join(config_path, EXTRA_CA_DIRECTORY)
|
|
|
|
if os.path.exists(certs_dir):
|
|
|
|
for extra_cert in os.listdir(certs_dir):
|
|
|
|
with open(os.path.join(certs_dir, extra_cert)) as f:
|
|
|
|
data[EXTRA_CA_DIRECTORY_PREFIX + extra_cert] = base64.b64encode(f.read())
|
|
|
|
|
|
|
|
|
|
|
|
for name in os.listdir(config_path):
|
|
|
|
file_path = os.path.join(config_path, name)
|
|
|
|
if not os.path.isdir(file_path):
|
|
|
|
with open(file_path) as f:
|
|
|
|
data[name] = base64.b64encode(f.read())
|
|
|
|
|
|
|
|
return data
|