def Config(envvar_silent=True) -> FlaskConfig: global _Config_instance if _Config_instance is None: _Config_instance = FlaskConfig('.') _Config_instance.from_object('ledslie.defaults') _Config_instance.from_envvar('LEDSLIE_CONFIG', silent=envvar_silent) return _Config_instance
def main(): config = Config(__name__) config.from_envvar('COMPOWSR_SETTINGS', silent=True) # get the praw stuff reddit = praw.Reddit(config['PRAW_SITE_NAME'], user_agent='flair_updater by /u/Witchtower') subreddit = reddit.subreddit(config['PRAW_SUBREDDIT_NAME']) # get reddit users with rank flair set print "getting all users with rank-flair from reddit" to_update = [(user['user'].name, user['flair_css_class']) for user in subreddit.flair() if user['flair_css_class'] in config['OW_RANKS'].keys()] print "got %i users with a rank flair" % len(to_update) # check who really needs to be updated db = connect_db(config) to_update_usernames = [i[0] for i in to_update] statement = "SELECT * FROM acc_links " #\ #% ','.join(['?']*len(to_update_usernames)) # AND last_update > datetime('now', '+14 days')" \ print statement print to_update_usernames cursor = db.execute(statement) #, to_update_usernames) to_update2 = cursor.fetchall() print "%i users haven't been updated in the last 14 days" % len(to_update2) for row in to_update2: # pull sr and update in db new_rank = playoverwatch.CareerProfile('eu', row['bnet_name']).rank db.execute( "UPDATE acc_links SET \ last_rank = ?, \ last_update = datetime('now') \ WHERE bnet_name = ?", [new_rank, row['bnet_name']]) subreddit.flair.set(row['reddit_name'], css_class=new_rank) print "flair '%s' set for '%s'" % (new_rank, row['reddit_name']) print "all done"
def main(expected): config = Config(here) config.from_object('ooi_status.default_settings') if 'OOISTATUS_SETTINGS' in os.environ: config.from_envvar('OOISTATUS_SETTINGS') for key in config: log.info('OOI_STATUS CONFIG: %r: %r', key, config[key]) monitor = StatusMonitor(config) if expected: monitor.read_expected_csv(expected) else: scheduler = BlockingScheduler() log.info('adding jobs') # notify on change every minute scheduler.add_job(monitor.check_all, 'cron', second=0) scheduler.add_job(monitor.notify_all, 'cron', second=10) log.info('starting jobs') scheduler.start()
class Configurator(object): """ Object that takes care of loading the different configurations from the different sources. There are 3 types of settings: * Project: The basic set of settings needed by the system. These are shipped with Shiva. * Local: Specific to each instance, useful for overwriting system settings. Some of them must be defined before running Shiva, like the DB URI. * Debug: This setting will only be loaded if ``DEBUG`` is set to True in the local settings. There are also 3 different places where Shiva looks for this config files: * A ``local.py`` file inside the ``config/`` directory, relative to Shiva. * The ``$SHIVA_CONFIG`` environment variable. It's assumed to be pointing to a file (not a dir) if exists. * The ``$XDG_CONFIG_HOME/shiva/config.py`` file. If ``$XDG_CONFIG_HOME`` is not set, defaults to ``$HOME/.config``, as defined by the `XDG Base Directory Specification <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest\ .html>`_. """ def __init__(self): self._config = FlaskConfig('') # project _project = self.load_project() # local _xdg_config = self.from_xdg_config() _env = self.from_env() _local = self.from_local() # debug _debug = self.load_debug() self.extract_conf(self._config) if not (_xdg_config or _env or _local): raise NoConfigFoundError def load_project(self): return self._config.from_object(project) def get_xdg_path(self): default_config_home = os.path.join(os.getenv('HOME'), '.config') return os.getenv('XDG_CONFIG_HOME') or default_config_home def from_xdg_config(self): local_py = os.path.join(self.get_xdg_path(), 'shiva/config.py') if not os.path.exists(local_py): return False return self._config.from_pyfile(local_py) def from_env(self): if not os.getenv('SHIVA_CONFIG'): return False return self._config.from_envvar('SHIVA_CONFIG') def from_local(self): with ignored(ImportError): self._config.from_object('shiva.config.local') return True return False def load_debug(self): if not self._config.get('DEBUG'): return False loaded = False with ignored(ImportError): from shiva.config import debug loaded = self._config.from_object(debug) debug_py = os.path.join(self.get_xdg_path(), 'shiva/debug.py') if not os.path.exists(debug_py): return False return self._config.from_pyfile(debug_py) or loaded def extract_conf(self, *args): """ Receives one or more objects, iterates over their elements, extracts all the uppercase properties and injects them into the Configurator object. """ for obj in args: for key in dir(obj): if key.isupper(): setattr(self, key, getattr(obj, key)) if hasattr(obj, 'iterkeys') and callable(getattr(obj, 'iterkeys')): for key in obj.iterkeys(): if key.isupper(): setattr(self, key, obj[key])
def get_user_config(): from flask import Config config = Config('/') config.from_object('alerta.settings') config.from_pyfile('/etc/alertad.conf', silent=True) config.from_envvar('ALERTA_SVR_CONF_FILE', silent=True) if 'DEBUG' in os.environ: config['DEBUG'] = True if 'BASE_URL' in os.environ: config['BASE_URL'] = os.environ['BASE_URL'] if 'SECRET_KEY' in os.environ: config['SECRET_KEY'] = os.environ['SECRET_KEY'] database_url = ( os.environ.get('DATABASE_URL', None) or # The following database settings are deprecated. os.environ.get('MONGO_URI', None) or os.environ.get('MONGODB_URI', None) or os.environ.get('MONGOHQ_URL', None) or os.environ.get('MONGOLAB_URI', None) ) # Use app config for DATABASE_URL if no env var from above override it config['DATABASE_URL'] = database_url or config['DATABASE_URL'] if 'DATABASE_NAME' in os.environ: config['DATABASE_NAME'] = os.environ['DATABASE_NAME'] if 'AUTH_REQUIRED' in os.environ: config['AUTH_REQUIRED'] = True if os.environ['AUTH_REQUIRED'] == 'True' else False if 'ADMIN_USERS' in os.environ: config['ADMIN_USERS'] = os.environ['ADMIN_USERS'].split(',') if 'CUSTOMER_VIEWS' in os.environ: config['CUSTOMER_VIEWS'] = True if os.environ['CUSTOMER_VIEWS'] == 'True' else False if 'OAUTH2_CLIENT_ID' in os.environ: config['OAUTH2_CLIENT_ID'] = os.environ['OAUTH2_CLIENT_ID'] if 'OAUTH2_CLIENT_SECRET' in os.environ: config['OAUTH2_CLIENT_SECRET'] = os.environ['OAUTH2_CLIENT_SECRET'] if 'ALLOWED_EMAIL_DOMAINS' in os.environ: config['ALLOWED_EMAIL_DOMAINS'] = os.environ['ALLOWED_EMAIL_DOMAINS'].split(',') if 'GITHUB_URL' in os.environ: config['GITHUB_URL'] = os.environ['GITHUB_URL'] if 'ALLOWED_GITHUB_ORGS' in os.environ: config['ALLOWED_GITHUB_ORGS'] = os.environ['ALLOWED_GITHUB_ORGS'].split(',') if 'GITLAB_URL' in os.environ: config['GITLAB_URL'] = os.environ['GITLAB_URL'] if 'ALLOWED_GITLAB_GROUPS' in os.environ: config['ALLOWED_GITLAB_GROUPS'] = os.environ['ALLOWED_GITLAB_GROUPS'].split(',') if 'KEYCLOAK_URL' in os.environ: config['KEYCLOAK_URL'] = os.environ['KEYCLOAK_URL'] if 'KEYCLOAK_REALM' in os.environ: config['KEYCLOAK_REALM'] = os.environ['KEYCLOAK_REALM'] if 'ALLOWED_KEYCLOAK_ROLES' in os.environ: config['ALLOWED_KEYCLOAK_ROLES'] = os.environ['ALLOWED_KEYCLOAK_ROLES'].split(',') if 'PINGFEDERATE_OPENID_ACCESS_TOKEN_URL' in os.environ: config['PINGFEDERATE_OPENID_ACCESS_TOKEN_URL'] = os.environ['PINGFEDERATE_OPENID_ACCESS_TOKEN_URL'].split(',') if 'PINGFEDERATE_OPENID_PAYLOAD_USERNAME' in os.environ: config['PINGFEDERATE_OPENID_PAYLOAD_USERNAME'] = os.environ['PINGFEDERATE_OPENID_PAYLOAD_USERNAME'].split(',') if 'PINGFEDERATE_OPENID_PAYLOAD_EMAIL' in os.environ: config['PINGFEDERATE_OPENID_PAYLOAD_EMAIL'] = os.environ['PINGFEDERATE_OPENID_PAYLOAD_EMAIL'].split(',') if 'PINGFEDERATE_OPENID_PAYLOAD_GROUP' in os.environ: config['PINGFEDERATE_OPENID_PAYLOAD_GROUP'] = os.environ['PINGFEDERATE_OPENID_PAYLOAD_GROUP'].split(',') if 'PINGFEDERATE_PUBKEY_LOCATION' in os.environ: config['PINGFEDERATE_PUBKEY_LOCATION'] = os.environ['PINGFEDERATE_PUBKEY_LOCATION'].split(',') if 'PINGFEDERATE_TOKEN_ALGORITHM' in os.environ: config['PINGFEDERATE_TOKEN_ALGORITHM'] = os.environ['PINGFEDERATE_TOKEN_ALGORITHM'].split(',') if 'CORS_ORIGINS' in os.environ: config['CORS_ORIGINS'] = os.environ['CORS_ORIGINS'].split(',') if 'MAIL_FROM' in os.environ: config['MAIL_FROM'] = os.environ['MAIL_FROM'] if 'SMTP_PASSWORD' in os.environ: config['SMTP_PASSWORD'] = os.environ['SMTP_PASSWORD'] if 'PLUGINS' in os.environ: config['PLUGINS'] = os.environ['PLUGINS'].split(',') # Runtime config check if config['CUSTOMER_VIEWS'] and not config['AUTH_REQUIRED']: raise RuntimeError('Must enable authentication to use customer views') if config['CUSTOMER_VIEWS'] and not config['ADMIN_USERS']: raise RuntimeError('Customer views is enabled but there are no admin users') return config
#!/usr/bin/env python3 import bcrypt from flask import Config from getpass import getpass import os.path as op import psycopg2 as dbc from sys import exit cfg = Config(op.dirname(__file__)) cfg.from_envvar('CONFIG') def connect_db(): """Connects to the database""" return dbc.connect(dbname=cfg['DBNAME'], user=cfg['USER'], password=cfg['PASSWORD'], host=cfg['HOST']) if __name__ == '__main__': name = input("""Enter admin's nickname: """) passwd = getpass(prompt='Enter password: '******'Repeat password: '******'t match.""") exit() passwd_hash = bcrypt.hashpw(passwd.encode(), bcrypt.gensalt()).decode() e_mail = input('Enter email: ') dbc = connect_db() cur = dbc.cursor() cur.execute(
import os import logging from flask import Config logger = logging.getLogger(__name__) configs = Config(os.path.dirname(__file__)) configs.from_object('config.default') try: configs.from_envvar('CONFIG_FILE') except RuntimeError as ex: logger.warning("Failed to load config from envar")
""" We will use flask Config class as configuration """ import os from flask import ( Config, ) ENV_VAR_NAME = "QUAKESTATS_SETTINGS" cnf = Config(os.path.dirname(__file__)) cnf.from_envvar(variable_name=ENV_VAR_NAME) def get_conf_val(key: str): return cnf[key]
engine = None sessionmaker = sa.orm.sessionmaker() session = sa.orm.scoped_session(sessionmaker) def configure_engine(url): global sessionmaker, engine, session engine = sa.create_engine(url) session.remove() sessionmaker.configure(bind=engine) _config = Config('') _config.from_object('config') _config.from_envvar('MULCHN_CONFIG', silent=True) configure_engine(_config.get('DATABASE_URL')) class _Base(object): @declared_attr def __tablename__(cls): """ Convert CamelCase class name to underscores_between_words table name. """ name = cls.__name__ return ( name[0].lower() + re.sub(r'([A-Z])', lambda m:"_" + m.group(0).lower(), name[1:]) )
from flask import Config cfg = Config('.') cfg.from_envvar('TIGERGRADER_SETTINGS')
class Configurator(object): """ Object that takes care of loading the different configurations from the different sources. There are 3 types of settings: * Project: The basic set of settings needed by the system. These are shipped with Shiva. * Local: Specific to each instance, useful for overwriting system settings. Some of them must be defined before running Shiva, like the DB URI. * Debug: This setting will only be loaded if ``DEBUG`` is set to True in the local settings. There are also 3 different places where Shiva looks for this config files: * A ``local.py`` file inside the ``config/`` directory, relative to Shiva. * The ``$SHIVA_CONFIG`` environment variable. It's assumed to be pointing to a file (not a dir) if exists. * The ``$XDG_CONFIG_HOME/shiva/config.py`` file. If ``$XDG_CONFIG_HOME`` is not set, defaults to ``$HOME/.config``, as defined by the `XDG Base Directory Specification <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest\ .html>`_. """ def __init__(self): self._config = FlaskConfig("") # project _project = self.load_project() # local _xdg_config = self.from_xdg_config() _env = self.from_env() _local = self.from_local() # debug _debug = self.load_debug() self.extract_conf(self._config) if not (_xdg_config or _env or _local): raise NoConfigFoundError def load_project(self): return self._config.from_object(project) def get_xdg_path(self): path_home = os.getenv("HOME") if not path_home: return None default_config_home = os.path.join(path_home, ".config") return os.getenv("XDG_CONFIG_HOME") or default_config_home def from_xdg_config(self): xdg_path = self.get_xdg_path() if not xdg_path: return False local_py = os.path.join(xdg_path, "shiva/config.py") if not os.path.exists(local_py): return False return self._config.from_pyfile(local_py) def from_env(self): if not os.getenv("SHIVA_CONFIG"): return False return self._config.from_envvar("SHIVA_CONFIG") def from_local(self): with ignored(ImportError): self._config.from_object("shiva.config.local") return True return False def load_debug(self): if not self._config.get("DEBUG"): return False loaded = False with ignored(ImportError): from shiva.config import debug loaded = self._config.from_object(debug) xdg_path = self.get_xdg_path() if not xdg_path: return False debug_py = os.path.join(xdg_path, "shiva/debug.py") if not os.path.exists(debug_py): return False return self._config.from_pyfile(debug_py) or loaded def extract_conf(self, *args): """ Receives one or more objects, iterates over their elements, extracts all the uppercase properties and injects them into the Configurator object. """ for obj in args: for key in dir(obj): if key.isupper(): setattr(self, key, getattr(obj, key)) if hasattr(obj, "iterkeys") and callable(getattr(obj, "iterkeys")): for key in obj.iterkeys(): if key.isupper(): setattr(self, key, obj[key])
def get_user_config(): from flask import Config config = Config('/') config.from_object('alerta.settings') config.from_pyfile('/etc/alertad.conf', silent=True) config.from_envvar('ALERTA_SVR_CONF_FILE', silent=True) config['DEBUG'] = get_config('DEBUG', default=True, type=bool, config=config) config['BASE_URL'] = get_config('BASE_URL', default='', type=str, config=config) config['USE_PROXYFIX'] = get_config('USE_PROXYFIX', default=False, type=bool, config=config) config['SECRET_KEY'] = get_config('SECRET_KEY', default='', type=str, config=config) database_url = ( # The following database settings are deprecated. os.environ.get('MONGO_URI', None) or os.environ.get('MONGODB_URI', None) or os.environ.get('MONGOHQ_URL', None) or os.environ.get('MONGOLAB_URI', None)) # Use app config for DATABASE_URL if no env var from above override it config['DATABASE_URL'] = get_config('DATABASE_URL', default=database_url, type=str, config=config) config['DATABASE_NAME'] = get_config('DATABASE_NAME', default=None, type=str, config=config) config['AUTH_REQUIRED'] = get_config('AUTH_REQUIRED', default=None, type=bool, config=config) config['AUTH_PROVIDER'] = get_config('AUTH_PROVIDER', default=None, type=str, config=config) config['ADMIN_USERS'] = get_config('ADMIN_USERS', default=[], type=list, config=config) config['SIGNUP_ENABLED'] = get_config('SIGNUP_ENABLED', default=True, type=bool, config=config) config['CUSTOMER_VIEWS'] = get_config('CUSTOMER_VIEWS', default=False, type=bool, config=config) config['OAUTH2_CLIENT_ID'] = get_config('OAUTH2_CLIENT_ID', default=None, type=str, config=config) config['OAUTH2_CLIENT_SECRET'] = get_config('OAUTH2_CLIENT_SECRET', default=None, type=str, config=config) config['ALLOWED_EMAIL_DOMAINS'] = get_config('ALLOWED_EMAIL_DOMAINS', default=[], type=list, config=config) config['AZURE_TENANT'] = get_config('AZURE_TENANT', default=None, type=str, config=config) config['GITHUB_URL'] = get_config('GITHUB_URL', default=None, type=str, config=config) config['ALLOWED_GITHUB_ORGS'] = get_config('ALLOWED_GITHUB_ORGS', default=[], type=list, config=config) config['GITLAB_URL'] = get_config('GITLAB_URL', default=None, type=str, config=config) if 'ALLOWED_GITLAB_GROUPS' in os.environ: config['ALLOWED_OIDC_ROLES'] = get_config('ALLOWED_GITLAB_GROUPS', default=[], type=list, config=config) config['KEYCLOAK_URL'] = get_config('KEYCLOAK_URL', default=None, type=str, config=config) config['KEYCLOAK_REALM'] = get_config('KEYCLOAK_REALM', default=None, type=str, config=config) if 'ALLOWED_KEYCLOAK_ROLES' in os.environ: config['ALLOWED_OIDC_ROLES'] = get_config('ALLOWED_KEYCLOAK_ROLES', default=[], type=list, config=config) config['OIDC_ISSUER_URL'] = get_config('OIDC_ISSUER_URL', default=None, type=str, config=config) config['ALLOWED_OIDC_ROLES'] = get_config('ALLOWED_OIDC_ROLES', default=[], type=list, config=config) config['CORS_ORIGINS'] = get_config('CORS_ORIGINS', default=[], type=list, config=config) config['MAIL_FROM'] = get_config('MAIL_FROM', default=None, type=str, config=config) config['SMTP_PASSWORD'] = get_config('SMTP_PASSWORD', default=None, type=str, config=config) config['GOOGLE_TRACKING_ID'] = get_config('GOOGLE_TRACKING_ID', default=None, type=str, config=config) config['PLUGINS'] = get_config('PLUGINS', default=[], type=list, config=config) # blackout plugin config['BLACKOUT_DURATION'] = get_config('BLACKOUT_DURATION', default=None, type=int, config=config) config['NOTIFICATION_BLACKOUT'] = get_config('NOTIFICATION_BLACKOUT', default=None, type=bool, config=config) config['BLACKOUT_ACCEPT'] = get_config('BLACKOUT_ACCEPT', default=[], type=list, config=config) # reject plugin config['ORIGIN_BLACKLIST'] = get_config('ORIGIN_BLACKLIST', default=[], type=list, config=config) config['ALLOWED_ENVIRONMENTS'] = get_config('ALLOWED_ENVIRONMENTS', default=[], type=list, config=config) # Runtime config check if config['CUSTOMER_VIEWS'] and not config['AUTH_REQUIRED']: raise RuntimeError( 'Must enable authentication to use customer views') if config['CUSTOMER_VIEWS'] and not config['ADMIN_USERS']: raise RuntimeError( 'Customer views is enabled but there are no admin users') return config
def get_user_config(): valid = Validate() from flask import Config config = Config('/') config.from_object('alerta.settings') config.from_pyfile('/etc/alertad.conf', silent=True) config.from_envvar('ALERTA_SVR_CONF_FILE', silent=True) if 'DEBUG' in os.environ: config['DEBUG'] = valid.validate_boolean(os.environ['DEBUG']) if 'BASE_URL' in os.environ: config['BASE_URL'] = valid.validate_url(os.environ['BASE_URL']) if 'USE_PROXYFIX' in os.environ: config['USE_PROXYFIX'] = valid.validate_boolean( os.environ['USE_PROXYFIX']) if 'SECRET_KEY' in os.environ: config['SECRET_KEY'] = valid.validate_string( os.environ['SECRET_KEY']) database_url = ( os.environ.get('DATABASE_URL', None) # The following database settings are deprecated. or os.environ.get('MONGO_URI', None) or os.environ.get('MONGODB_URI', None) or os.environ.get( 'MONGOHQ_URL', None) or os.environ.get('MONGOLAB_URI', None)) # Use app config for DATABASE_URL if no env var from above override it config['DATABASE_URL'] = database_url or config['DATABASE_URL'] if config['DATABASE_URL'] in os.environ: config['DATABASE_URL'] = valid.validate_url( os.environ['DATABASE_URL']) if 'DATABASE_NAME' in os.environ: config['DATABASE_NAME'] = valid.validate_string( os.environ['DATABASE_NAME']) if 'AUTH_REQUIRED' in os.environ: config['AUTH_REQUIRED'] = valid.validate_boolean( os.environ['AUTH_REQUIRED']) if 'AUTH_PROVIDER' in os.environ: config['AUTH_PROVIDER'] = valid.validate_string( os.environ['AUTH_PROVIDER']) if 'ADMIN_USERS' in os.environ: config['ADMIN_USERS'] = valid.validate_list( os.environ['ADMIN_USERS'], 'string') if 'SIGNUP_ENABLED' in os.environ: config['SIGNUP_ENABLED'] = valid.validate_boolean( os.environ['SIGNUP_ENABLED']) if 'CUSTOMER_VIEWS' in os.environ: config['CUSTOMER_VIEWS'] = valid.validate_boolean( os.environ['CUSTOMER_VIEWS']) if 'OAUTH2_CLIENT_ID' in os.environ: config['OAUTH2_CLIENT_ID'] = valid.validate_string( os.environ['OAUTH2_CLIENT_ID']) if 'OAUTH2_CLIENT_SECRET' in os.environ: config['OAUTH2_CLIENT_SECRET'] = valid.validate_string( os.environ['OAUTH2_CLIENT_SECRET']) if 'ALLOWED_EMAIL_DOMAINS' in os.environ: config['ALLOWED_EMAIL_DOMAINS'] = valid.validate_list( os.environ['ALLOWED_EMAIL_DOMAINS'], 'string') if 'AZURE_TENANT' in os.environ: config['AZURE_TENANT'] = valid.validate_string( os.environ['AZURE_TENANT']) if 'GITHUB_URL' in os.environ: config['GITHUB_URL'] = valid.validate_url(os.environ['GITHUB_URL']) if 'ALLOWED_GITHUB_ORGS' in os.environ: config['ALLOWED_GITHUB_ORGS'] = valid.validate_list( os.environ['ALLOWED_GITHUB_ORGS'], 'string') if 'GITLAB_URL' in os.environ: config['GITLAB_URL'] = valid.validate_url(os.environ['GITLAB_URL']) if 'ALLOWED_GITLAB_GROUPS' in os.environ: config['ALLOWED_OIDC_ROLES'] = valid.validate_list( os.environ['ALLOWED_GITLAB_GROUPS'], 'string') if 'KEYCLOAK_URL' in os.environ: config['KEYCLOAK_URL'] = valid.validate_url( os.environ['KEYCLOAK_URL']) if 'KEYCLOAK_REALM' in os.environ: config['KEYCLOAK_REALM'] = valid.validate_string( os.environ['KEYCLOAK_REALM']) if 'ALLOWED_KEYCLOAK_ROLES' in os.environ: config['ALLOWED_OIDC_ROLES'] = valid.validate_list( os.environ['ALLOWED_KEYCLOAK_ROLES'], 'string') if 'OIDC_ISSUER_URL' in os.environ: config['OIDC_ISSUER_URL'] = valid.validate_url( os.environ['OIDC_ISSUER_URL']) if 'ALLOWED_OIDC_ROLES' in os.environ: config['ALLOWED_OIDC_ROLES'] = valid.validate_list( os.environ['ALLOWED_OIDC_ROLES'], 'string') if 'CORS_ORIGINS' in os.environ: config['CORS_ORIGINS'] = valid.validate_list( os.environ['CORS_ORIGINS'], 'url') if 'MAIL_FROM' in os.environ: config['MAIL_FROM'] = valid.validate_email(os.environ['MAIL_FROM']) if 'SMTP_PASSWORD' in os.environ: config['SMTP_PASSWORD'] = valid.validate_string( os.environ['SMTP_PASSWORD']) if 'GOOGLE_TRACKING_ID' in os.environ: config['GOOGLE_TRACKING_ID'] = valid.validate_string( os.environ['GOOGLE_TRACKING_ID']) if 'PLUGINS' in os.environ: config['PLUGINS'] = valid.validate_list(os.environ['PLUGINS'], 'string') if 'ALERT_TIMEOUT' in os.environ: config['ALERT_TIMEOUT'] = valid.validate_integer( os.environ['ALERT_TIMEOUT']) if 'HEARTBEAT_TIMEOUT' in os.environ: config['HEARTBEAT_TIMEOUT'] = valid.validate_integer( os.environ['HEARTBEAT_TIMEOUT']) if 'API_KEY_EXPIRE_DAYS' in os.environ: config['API_KEY_EXPIRE_DAYS'] = valid.validate_integer( os.environ['API_KEY_EXPIRE_DAYS']) # Runtime config check if config['CUSTOMER_VIEWS'] and not config['AUTH_REQUIRED']: raise RuntimeError( 'Must enable authentication to use customer views') if config['CUSTOMER_VIEWS'] and not config['ADMIN_USERS']: raise RuntimeError( 'Customer views is enabled but there are no admin users') return config
def get_user_config(): from flask import Config config = Config('/') config.from_object('alerta.settings') config.from_pyfile('/etc/alertad.conf', silent=True) config.from_envvar('ALERTA_SVR_CONF_FILE', silent=True) if 'DEBUG' in os.environ: config['DEBUG'] = True if 'BASE_URL' in os.environ: config['BASE_URL'] = os.environ['BASE_URL'] if 'USE_PROXYFIX' in os.environ: config['USE_PROXYFIX'] = True if os.environ['USE_PROXYFIX'] == 'True' else False if 'SECRET_KEY' in os.environ: config['SECRET_KEY'] = os.environ['SECRET_KEY'] database_url = ( os.environ.get('DATABASE_URL', None) or # The following database settings are deprecated. os.environ.get('MONGO_URI', None) or os.environ.get('MONGODB_URI', None) or os.environ.get('MONGOHQ_URL', None) or os.environ.get('MONGOLAB_URI', None) ) # Use app config for DATABASE_URL if no env var from above override it config['DATABASE_URL'] = database_url or config['DATABASE_URL'] if 'DATABASE_NAME' in os.environ: config['DATABASE_NAME'] = os.environ['DATABASE_NAME'] if 'AUTH_REQUIRED' in os.environ: config['AUTH_REQUIRED'] = True if os.environ['AUTH_REQUIRED'] == 'True' else False if 'AUTH_PROVIDER' in os.environ: config['AUTH_PROVIDER'] = os.environ['AUTH_PROVIDER'] if 'ADMIN_USERS' in os.environ: config['ADMIN_USERS'] = os.environ['ADMIN_USERS'].split(',') if 'SIGNUP_ENABLED' in os.environ: config['SIGNUP_ENABLED'] = True if os.environ['SIGNUP_ENABLED'] == 'True' else False if 'CUSTOMER_VIEWS' in os.environ: config['CUSTOMER_VIEWS'] = True if os.environ['CUSTOMER_VIEWS'] == 'True' else False if 'OAUTH2_CLIENT_ID' in os.environ: config['OAUTH2_CLIENT_ID'] = os.environ['OAUTH2_CLIENT_ID'] if 'OAUTH2_CLIENT_SECRET' in os.environ: config['OAUTH2_CLIENT_SECRET'] = os.environ['OAUTH2_CLIENT_SECRET'] if 'ALLOWED_EMAIL_DOMAINS' in os.environ: config['ALLOWED_EMAIL_DOMAINS'] = os.environ['ALLOWED_EMAIL_DOMAINS'].split(',') if 'AZURE_TENANT' in os.environ: config['AZURE_TENANT'] = os.environ['AZURE_TENANT'] if 'GITHUB_URL' in os.environ: config['GITHUB_URL'] = os.environ['GITHUB_URL'] if 'ALLOWED_GITHUB_ORGS' in os.environ: config['ALLOWED_GITHUB_ORGS'] = os.environ['ALLOWED_GITHUB_ORGS'].split(',') if 'GITLAB_URL' in os.environ: config['GITLAB_URL'] = os.environ['GITLAB_URL'] if 'ALLOWED_GITLAB_GROUPS' in os.environ: config['ALLOWED_OIDC_ROLES'] = os.environ['ALLOWED_GITLAB_GROUPS'].split(',') if 'KEYCLOAK_URL' in os.environ: config['KEYCLOAK_URL'] = os.environ['KEYCLOAK_URL'] if 'KEYCLOAK_REALM' in os.environ: config['KEYCLOAK_REALM'] = os.environ['KEYCLOAK_REALM'] if 'ALLOWED_KEYCLOAK_ROLES' in os.environ: config['ALLOWED_OIDC_ROLES'] = os.environ['ALLOWED_KEYCLOAK_ROLES'].split(',') if 'OIDC_ISSUER_URL' in os.environ: config['OIDC_ISSUER_URL'] = os.environ['OIDC_ISSUER_URL'] if 'ALLOWED_OIDC_ROLES' in os.environ: config['ALLOWED_OIDC_ROLES'] = os.environ['ALLOWED_OIDC_ROLES'].split(',') if 'PINGFEDERATE_OPENID_ACCESS_TOKEN_URL' in os.environ: config['PINGFEDERATE_OPENID_ACCESS_TOKEN_URL'] = os.environ['PINGFEDERATE_OPENID_ACCESS_TOKEN_URL'].split( ',') if 'PINGFEDERATE_OPENID_PAYLOAD_USERNAME' in os.environ: config['PINGFEDERATE_OPENID_PAYLOAD_USERNAME'] = os.environ['PINGFEDERATE_OPENID_PAYLOAD_USERNAME'].split( ',') if 'PINGFEDERATE_OPENID_PAYLOAD_EMAIL' in os.environ: config['PINGFEDERATE_OPENID_PAYLOAD_EMAIL'] = os.environ['PINGFEDERATE_OPENID_PAYLOAD_EMAIL'].split(',') if 'PINGFEDERATE_OPENID_PAYLOAD_GROUP' in os.environ: config['PINGFEDERATE_OPENID_PAYLOAD_GROUP'] = os.environ['PINGFEDERATE_OPENID_PAYLOAD_GROUP'].split(',') if 'PINGFEDERATE_PUBKEY_LOCATION' in os.environ: config['PINGFEDERATE_PUBKEY_LOCATION'] = os.environ['PINGFEDERATE_PUBKEY_LOCATION'].split(',') if 'PINGFEDERATE_TOKEN_ALGORITHM' in os.environ: config['PINGFEDERATE_TOKEN_ALGORITHM'] = os.environ['PINGFEDERATE_TOKEN_ALGORITHM'].split(',') if 'CORS_ORIGINS' in os.environ: config['CORS_ORIGINS'] = os.environ['CORS_ORIGINS'].split(',') if 'MAIL_FROM' in os.environ: config['MAIL_FROM'] = os.environ['MAIL_FROM'] if 'SMTP_PASSWORD' in os.environ: config['SMTP_PASSWORD'] = os.environ['SMTP_PASSWORD'] if 'GOOGLE_TRACKING_ID' in os.environ: config['GOOGLE_TRACKING_ID'] = os.environ['GOOGLE_TRACKING_ID'] if 'PLUGINS' in os.environ: config['PLUGINS'] = os.environ['PLUGINS'].split(',') # Runtime config check if config['CUSTOMER_VIEWS'] and not config['AUTH_REQUIRED']: raise RuntimeError('Must enable authentication to use customer views') if config['CUSTOMER_VIEWS'] and not config['ADMIN_USERS']: raise RuntimeError('Customer views is enabled but there are no admin users') return config
''' if __name__ == '__main__': global mongo_host global mongo_port global mongo_db_name args = argparser.parse_args() config = Config(os.path.dirname(os.path.realpath(__file__))) # Load default config config.from_object('config.default') # Load instance configuration if exists config.from_pyfile('config.py', silent=True) # Load configuration file specified in BRAVO_CONFIG_FILE environment variable if exists config.from_envvar('BRAVO_CONFIG_FILE', silent=True) mongo_host = config['MONGO']['host'] mongo_port = config['MONGO']['port'] mongo_db_name = config['MONGO']['name'] igv_cache_collection_name = config['IGV_CACHE_COLLECTION'] if args.command == 'genes': sys.stdout.write( 'Start loading genes to {} database.\n'.format(mongo_db_name)) load_gene_models(args.canonical_transcripts_file, args.omim_file, args.genenames_file, args.gencode_file) sys.stdout.write( 'Done loading genes to {} database.\n'.format(mongo_db_name)) elif args.command == 'users': sys.stdout.write('Creating users collection in {} database.\n'.format(
from flask.ext.login import LoginManager, login_required, \ login_user, logout_user from matchmaker import app from models import User, BotIdentity # Wire everything up login_manager = LoginManager() login_manager.init_app(app) oauth = OAuth(app) # Casino GitHub OAuth oauth_config = Config("") oauth_config.from_object('matchmaker.default_oauth') oauth_config.from_envvar('CASINO_OAUTH', silent=True) github = oauth.remote_app( 'github', **{k.lower(): v for k, v in oauth_config.items()} ) @app.route('/login') def login(): return github.authorize( callback=url_for('authorized', _external=True, _scheme=app.config.get("PREFERRED_URL_SCHEME")) ) @app.route('/logout')