Esempio n. 1
0
def test_get_env(preserve_env):
    # used in cloudformation!
    os.environ['ENV'] = 'LOCAL'
    assert get_env() == 'local'

    del os.environ['ENV']
    assert get_env() == None

    os.environ['ENV'] = 'NONE_SENSE'
    assert get_env() == 'none_sense'
Esempio n. 2
0
def write_template_to_file(conf, template_body):
    """Writes the template to disk
    """
    template_file_name = _get_stack_name(conf) + '-generated-cf-template.json'
    with open(template_file_name, 'w') as opened_file:
        opened_file.write(template_body)
    print('wrote cf-template for %s to disk: %s' % (
        get_env(), template_file_name))
    return template_file_name
Esempio n. 3
0
def get_tooldata(awsclient,
                 tool,
                 command,
                 config=None,
                 config_base_name=None,
                 location=None):
    """Helper for main tests to assemble tool data.
    used in testing to read from 'gcdt_<env>.json' files

    :param awsclient:
    :param tool:
    :param command:
    :param config: provide custom config or empty to read from file
    :param config_base_name:
    :param location:
    :return:
    """
    from gcdt_lookups.lookups import _resolve_lookups
    if config is None:
        if config_base_name is None:
            config_base_name = 'gcdt'
        if location is None:
            location = '.'
        env = get_env()
        gcdt_config_file = os.path.join(location,
                                        '%s_%s.json' % (config_base_name, env))
        context = {'_awsclient': awsclient, 'tool': tool, 'command': command}
        config = fix_old_kumo_config(read_json_config(gcdt_config_file))[tool]
        _resolve_lookups(
            context, config,
            config.get('lookups', ['secret', 'ssl', 'stack', 'baseami']))

    tooldata = {
        'context': {
            'tool': tool,
            'command': command,
            'version': __version__,
            'user': '******',
            '_awsclient': awsclient
        },
        'config': config
    }
    return tooldata