def test_ConfigIniEnv(datadir): ini_filename = os.path.join(datadir, 'config_test.ini') cie = ConfigIniEnv([ini_filename]) assert cie.get('foo') == 'bar' assert cie.get('foo', namespace=['namespacebaz']) == 'bat' # FIXME: Add multi-tier namespace cie = ConfigIniEnv(['/a/b/c/bogus/filename']) assert cie.get('foo') == NO_VALUE
def test_ConfigIniEnv(datadir): ini_filename = os.path.join(datadir, 'config_test.ini') cie = ConfigIniEnv([ini_filename]) assert cie.get('foo') == 'bar' assert cie.get('FOO') == 'bar' assert cie.get('foo', namespace='nsbaz') == 'bat' assert cie.get('foo', namespace=['nsbaz']) == 'bat' assert cie.get('foo', namespace=['nsbaz', 'nsbaz2']) == 'bat2' cie = ConfigIniEnv(['/a/b/c/bogus/filename']) assert cie.get('foo') == NO_VALUE
def get_config(): return ConfigManager([ ConfigIniEnv([ os.environ.get('THREATRESPONSE_INI'), '~/.threatresponse.ini', '/etc/threatresponse.ini' ]), ConfigOSEnv() ])
def get_config(): return ConfigManager([ ConfigIniEnv([ os.environ.get("DASHBOARD_CONFIG_INI"), "~/.sso-dashboard.ini", "/etc/sso-dashboard.ini", ]), CredstashEnv(), ])
def __init__(self, profile=None, rv_home=None, config_overrides=None, tmp_dir=None, verbosity=Verbosity.NORMAL): self.verbosity = verbosity # Set logging level root_log = logging.getLogger('rastervision') if self.verbosity >= Verbosity.VERBOSE: root_log.setLevel(logging.DEBUG) elif self.verbosity >= Verbosity.NORMAL: root_log.setLevel(logging.INFO) else: root_log.setLevel(logging.WARN) if tmp_dir is not None: self.set_tmp_dir(tmp_dir) if profile is None: if os.environ.get('RV_PROFILE'): profile = os.environ.get('RV_PROFILE') else: profile = RVConfig.DEFAULT_PROFILE if config_overrides is None: config_overrides = {} if rv_home is None: home = os.path.expanduser('~') rv_home = os.path.join(home, '.rastervision') self.rv_home = rv_home config_file_locations = self._discover_config_file_locations(profile) help_doc = ('Check https://docs.rastervision.io/ for docs.') self.config = ConfigManager( # Specify one or more configuration environments in # the order they should be checked [ # Allow overrides ConfigDictEnv(config_overrides), # Looks in OS environment first ConfigOSEnv(), # Look for an .env file ConfigEnvFileEnv('.env'), # Looks in INI files in order specified ConfigIniEnv(config_file_locations), ], # Make it easy for users to find your configuration docs doc=help_doc)
def getEverettManager(configfile): return ConfigManager( # Specify one or more configuration environments in # the order they should be checked [ # Looks in OS environment first ConfigOSEnv(), # Looks in INI files in order specified ConfigIniEnv([ configfile, ]), ], )
def reset(self, profile=None, rv_home=None, config_overrides=None, tmp_dir=None, verbosity=Verbosity.NORMAL): self.verbosity = verbosity root_log = logging.getLogger('rastervision2') if self.verbosity >= Verbosity.VERBOSE: root_log.setLevel(logging.DEBUG) elif self.verbosity >= Verbosity.NORMAL: root_log.setLevel(logging.INFO) else: root_log.setLevel(logging.WARN) if tmp_dir is not None: self.set_tmp_dir(tmp_dir) if profile is None: if os.environ.get('RV_PROFILE'): profile = os.environ.get('RV_PROFILE') else: profile = RVConfig.DEFAULT_PROFILE if config_overrides is None: config_overrides = {} if rv_home is None: home = os.path.expanduser('~') rv_home = os.path.join(home, '.rastervision') self.rv_home = rv_home config_file_locations = self._discover_config_file_locations(profile) self.config = ConfigManager( [ ConfigDictEnv(config_overrides), ConfigOSEnv(), ConfigIniEnv(config_file_locations), ], doc='Check https://docs.rastervision.io/ for docs.')
def set_everett_config(self, profile: str = None, rv_home: str = None, config_overrides: Dict[str, str] = None): """Set Everett config. This sets up any other configuration using the Everett library. See https://everett.readthedocs.io/ It roughly mimics the behavior of how the AWS CLI is configured, if that is a helpful analogy. Configuration can be specified through configuration files, environment variables, and the config_overrides argument in increasing order of precedence. Configuration files are in the following format: ``` [namespace_1] key_11=val_11 ... key_1n=val_1n ... [namespace_m] key_m1=val_m1 ... key_mn=val_mn ``` Each namespace can be used for the configuration of a different plugin. Each configuration file is a "profile" with the name of the file being the name of the profile. This supports switching between different configuration sets. The corresponding environment variable setting for namespace_i and key_ij is `namespace_i_key_ij=val_ij`. Args: profile: name of the RV configuration profile to use. If not set, defaults to value of RV_PROFILE env var, or DEFAULT_PROFILE. rv_home: a local dir with RV configuration files. If not set, attempts to use ~/.rastervision. config_overrides: any configuration to override. Each key is of form namespace_i_key_ij with corresponding value val_ij. """ if profile is None: if os.environ.get('RV_PROFILE'): profile = os.environ.get('RV_PROFILE') else: profile = RVConfig.DEFAULT_PROFILE self.profile = profile if config_overrides is None: config_overrides = {} if rv_home is None: home = os.path.expanduser('~') rv_home = os.path.join(home, '.rastervision') self.rv_home = rv_home if self.profile == 'local': config_ini_env = LocalEnv() else: config_file_locations = self._discover_config_file_locations( self.profile) config_ini_env = ConfigIniEnv(config_file_locations) self.config = ConfigManager( [ ConfigDictEnv(config_overrides), ConfigOSEnv(), config_ini_env, ], doc=( 'Check https://docs.rastervision.io/ for docs. ' 'Switch to the version being run and search for Raster Vision ' 'Configuration.'))
import os from everett.manager import (ConfigDictEnv, ConfigIniEnv, ConfigManager, ConfigOSEnv) config = ConfigManager([ # Pull from the OS environment first ConfigOSEnv(), # Fall back to the file specified by the FOO_INI OS environment # variable if such file exists ConfigIniEnv(os.environ.get('FOO_INI')), # Fall back to this dict of defaults ConfigDictEnv({'FOO_VAR': 'bar'}) ]) assert config('foo_var') == 'bar'
""" import os import raven from everett.manager import ( ConfigDictEnv, ConfigEnvFileEnv, ConfigIniEnv, ConfigManager, ConfigOSEnv, ListOf, ) config = ConfigManager([ ConfigOSEnv(), ConfigIniEnv(['config.ini', '/etc/signoxe/server.ini']), ConfigDictEnv({ 'SECRET_KEY': 'vo7v#s9o7$t%x=fpbt7j5#%=-bl^y6e4&n2hpklg&rzx%z2mp$', 'DEBUG': 'false', }) ]) # Core config BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ADMINS = (('Kshitij Sobti', '*****@*****.**'), ) DEBUG = config('DEBUG', parser=bool) SECRET_KEY = config('SECRET_KEY')