def load_configs(configuration_files): v.automatic_env() v.set_env_key_replacer(".", "_") v.set_config_type("yaml") v.add_config_path("./resources/configurations") for configuration_file in configuration_files: v.set_config_name(configuration_file) v.merge_in_config()
def setup_vyper(parser): env_name = os.getenv("APP_ENV_NAME", "LOCAL").lower() config_name = "config.{}".format(env_name) v.bind_args(parser) v.set_env_prefix(v.get("environment_variables_prefix")) v.set_env_key_replacer("-", "_") v.automatic_env() v.add_config_path("config") v.set_config_type("toml") v.set_config_name(config_name) v.read_in_config()
def setup_vyper(parser, overrides): defaults = _get_default_args(parser) actual_overrides = \ {k: val for k, val in overrides.items() if defaults[k] != val} env_name = os.getenv("APP_ENV_NAME", "LOCAL").lower() config_name = "config.{}".format(env_name) _setup_args(parser) _setup_overrides(actual_overrides) v.set_env_prefix(v.get("env_vars_prefix")) v.automatic_env() v.add_config_path("config") v.set_config_type("toml") v.set_config_name(config_name) v.read_in_config()
def pytest_configure(config): """ Performs loading of json-formatted config and extracts vyper object to pytest context variable 'config' The config can be loaded from consul server if consul-url, consul-token, consul-path provided, seeks for config at {consul-url/consul-path/env} If consul-url is not specified, reads config files stored at {test-rootdir/config/env.json} """ config_type = 'json' env = config.option.env v.set_config_type(config_type) is_remote = bool(config.option.consul_url) if is_remote: c = urlparse(config.option.consul_url) token = config.option.consul_token client = consul.Consul(host=c.hostname, port=c.port, scheme=c.scheme, token=token) path = f'{config.option.consul_path}/{env}' provider = 'consul' v.add_remote_provider(provider, client, path) v.read_remote_config() else: path = f'{config.rootdir.strpath}/config' v.set_config_name(config.option.env) v.add_config_path(path) try: v.read_in_config() except FileNotFoundError: raise FileNotFoundError( f'File not found: {path}/{env}.{config_type}') config.v = v
def setup_vyper(parser: argparse.ArgumentParser, overrides: Dict[str, Any] = None): env_name = os.getenv("APP_ENV_NAME", "LOCAL").lower() config_name = "config.{}".format(env_name) v.bind_args(parser) if overrides: for k, val in overrides.items(): v.set(k, val) v.set_env_prefix(v.get("environment_variables_prefix")) v.set_env_key_replacer("-", "_") v.automatic_env() v.add_config_path("config") v.set_config_type("toml") v.set_config_name(config_name) v.read_in_config()
import etcd from flask import Flask from vyper import v app = Flask(__name__) client = etcd.Client(port=2379) def update_config(): """Updates Flask's config.""" return app.config.update(v.all_settings(uppercase_keys=True)) v.set_config_type("json") v.add_remote_provider("etcd", client, "/config.json") v.read_remote_config() update_config() v.watch_remote_config() v.on_remote_config_change(update_config) @app.route("/") def hello(): return "Hello " + app.config["HELLO"] if __name__ == "__main__": app.run(use_reloader=False)
def pytest_configure(config): env = config.getoption('--env') configuration.set_config_name(env) configuration.set_config_type('yaml') configuration.add_config_path('./config') configuration.read_in_config()
from kazoo import client from vyper import v client = client.KazooClient() client.start() v.set_config_type('json') v.add_remote_provider('zookeeper', client, '/config.json') v.read_remote_config() print('Hello ' + v.get('hello'))
import consul from vyper import v client = consul.Consul() v.set_config_type("yaml") v.add_remote_provider("consul", client, "config.yaml") v.read_remote_config() print("Hello " + v.get("hello"))
import consul from vyper import v import vyper client = consul.Consul() v.set_config_type('yaml') v.add_remote_provider('consul', client, 'config.yaml') v.read_remote_config() print('Hello ' + v.get('hello'))
import etcd from vyper import v client = etcd.Client() v.set_config_type('toml') v.add_remote_provider('etcd', client, '/config.toml') v.read_remote_config() print('Hello ' + v.get('hello'))
def set_config_file_extensions(): for ext in default.SUPPORTED_CONFIG_EXTENSIONS: v.set_config_type(ext)
import etcd from vyper import v client = etcd.Client(port=2379) v.set_config_type("toml") v.add_remote_provider("etcd", client, "/config.toml") v.read_remote_config() print("Hello " + v.get("hello"))