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
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)
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'))
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 etcd from flask import Flask from vyper import v app = Flask(__name__) client = etcd.Client() 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)
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'))
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"))