Ejemplo n.º 1
0
def config():
    url_prompt = 'CMP URL (default is "%s"): ' % DEFAULT_CMP_URL
    user_prompt = 'CMP API Key: '
    pass_prompt = 'CMP API Secret: '

    url = ""
    key = "KEY"
    secret = "SECRET"
    if os.sys.stdin.isatty():
        url = raw_input(url_prompt)
        key = raw_input(user_prompt)
        secret = getpass.getpass(pass_prompt)

    config = {
        'verify_ssl': True,
        'regions': {
            'default': {
                'cmp_url': url or DEFAULT_CMP_URL,
                'cmp_api_key': key,
                'cmp_api_secret': secret,
            }
        }
    }
    write_yaml_file(CONFIG_FILE, config)
    return config
Ejemplo n.º 2
0
def add_config_region(name, url, key, secret):
    config = read_yaml_file(CONFIG_FILE)
    config["regions"][str(name)] = {
        "cmp_url": str(url),
        "cmp_api_key": str(key),
        "cmp_api_secret": str(secret),
    }
    write_yaml_file(CONFIG_FILE, config)
    return config
Ejemplo n.º 3
0
def add_config_region(name, url, key, secret, extra_headers):
    new_region = {
        "cmp_url": str(url),
        "cmp_api_key": str(key),
        "cmp_api_secret": str(secret),
    }
    if extra_headers:
        new_region["extra_headers"] = \
            {str(k): str(v) for k, v in extra_headers}

    config = read_yaml_file(CONFIG_FILE)
    config["regions"][str(name)] = new_region
    write_yaml_file(CONFIG_FILE, config)
    return config
Ejemplo n.º 4
0
def assert_config_exists():
    if not os.path.isfile(CONFIG_FILE):
        click.echo(
            "The flexer config file is not found. Running config...",
            err=True,
        )
        config = {
            'verify_ssl': True,
            'regions': {
                'default': {
                    'cmp_url': DEFAULT_CMP_URL,
                    'cmp_api_key': '',
                    'cmp_api_secret': '',
                }
            }
        }
        write_yaml_file(CONFIG_FILE, config)