예제 #1
0
def update_organizations(config):
    values = config['values']

    # lowercase orgs before selection
    organizations = {org.lower(): values for org, values
                     in config['organizations'].iteritems()}

    # select only organizations in arguments
    organizations = filter_keys(organizations, values.get('org'))

    config['organizations'] = organizations
예제 #2
0
def _get_selected_tasks(task_cls, tasks_from_options, excluded_tasks):
    available_tasks = {
        task.__name__.lower(): task
        for task in DEFAULT_TASKS if issubclass(task, task_cls)
    }
    requested_task_names = [name.lower() for name in tasks_from_options]
    excluded_task_names = {name.lower() for name in excluded_tasks}
    filtered_tasks = filter_keys(available_tasks, requested_task_names)
    return [
        task for (task_name, task) in filtered_tasks.items()
        if task and task_name not in excluded_task_names
    ]
예제 #3
0
def update_environments(config):
    values = config['values']

    # select only the organizations requested
    environments = filter_keys(config['environments'], values.get('env'))

    # read authentication tokens
    tokens = {}
    auth_filename = values.get('auth_file')
    if auth_filename:
        auth_filename = auth_filename.format(WORKSPACE=os.environ['WORKSPACE'])
        if os.path.exists(auth_filename):
            with open(auth_filename) as auth_file:
                tokens.update(json.load(auth_file))

    # update "known" environments with the values from the auth file.
    # this would not be necessary if the configuration file had all the values

    field_map = {
        'sql_password': '******',
        'mongo_user': '******',
        'mongo_password': '******',
        'secret_key': 'secret_key'
    }

    for env in ['prod', 'edge']:
        if env in environments:
            data = environments.get(env, {})
            for config_name, token_name in field_map.iteritems():
                data[config_name] = tokens.get(token_name)

            # different settings for edge
            if env == 'edge':
                data['sql_password'] = tokens.get('rds_pass_edge')
                data['mongo_user'] = tokens.get('mongo_user_edge')
                data['mongo_password'] = tokens.get('mongo_pass_edge')

            environments[env] = data

    config['environments'] = environments