def check_required_keys(config, toolbox):
    """ Validates that all required keys for an [radius_client] section are present in the config.

    Args:
        config (ConfigDict): The config object to check the required config for
        toolbox (ConfigTestToolbox): Toolbox used to execute the tests

    Returns:
        list of BaseResult
    """
    problems = []
    try:
        util.get_host_list(config)
    except ConfigError:
        problems.append(MissingKey(key='host'))

    if not toolbox.test_config_has_key(config, 'secret', optionally_protected=True):
        problems.append(MissingKey(key='secret/secret_protected'))

    return problems
def check_required_keys(config, toolbox):
    """
    Validates that all required keys for an [radius_server_eap] section
    are present in the config.

    Args:
        config (ConfigDict): The config object to check the required config for
        toolbox (ConfigTestToolbox): Toolbox used to execute the tests

    Returns:
        list of ConfigResult
    """
    problems = []
    for key in ('ikey', 'api_host', 'certs', 'pkey'):
        if not toolbox.test_config_has_key(config, key):
            problems.append(MissingKey(key=key))

    for key in ['skey']:
        if not toolbox.test_config_has_key(
                config, key, optionally_protected=True):
            problems.append(MissingKey(key=key))

    if not toolbox.test_config_has_any_dynamic_key(
            config, 'radius_secret', optionally_protected=True):
        problems.append(MissingKey(key='radius_secret_1'))

    if not toolbox.test_config_has_any_dynamic_key(config, 'radius_ip'):
        problems.append(MissingKey(key='radius_ip_1'))

    # we can't use the base keys for these two keys because radius sections
    # are a bit quirky
    if toolbox.test_config_has_key(config, 'radius_ip'):
        problems.append(UnexpectedKey(key='radius_ip'))

    if toolbox.test_config_has_key(config,
                                   'radius_secret',
                                   optionally_protected=True):
        problems.append(
            UnexpectedKey(key='radius_secret / radius_secret_protected'))

    return problems
Beispiel #3
0
def check_common_required_radius_keys(config, toolbox):
    """ Validates that all required keys for an [radius_server_*] section are present in the config.
    Any radius server section specific keys must be checked after.

    Args:
        config (ConfigDict): The config object to check the required config for
        toolbox (ConfigTestToolbox): Toolbox used to execute the tests

    Returns:
        list of ConfigResults
    """
    problems = []
    for key in ("ikey", "api_host"):
        if not toolbox.test_config_has_key(config, key):
            problems.append(MissingKey(key=key))

    for key in ["skey"]:
        if not toolbox.test_config_has_key(
                config, key, optionally_protected=True):
            problems.append(MissingKey(key=key))

    if not toolbox.test_config_has_any_dynamic_key(
            config, "radius_secret", optionally_protected=True):
        problems.append(MissingKey(key="radius_secret_1"))

    if not toolbox.test_config_has_any_dynamic_key(config, "radius_ip"):
        problems.append(MissingKey(key="radius_ip_1"))

    # we can't use the base keys for these two keys because radius sections
    # are a bit quirky
    if toolbox.test_config_has_key(config, "radius_ip"):
        problems.append(UnexpectedKey(key="radius_ip"))

    if toolbox.test_config_has_key(config,
                                   "radius_secret",
                                   optionally_protected=True):
        problems.append(
            UnexpectedKey(key="radius_secret / radius_secret_protected"))

    return problems
Beispiel #4
0
def check_required_keys(config, toolbox):
    """
    Validates that all required keys for a [cloud] section are present in
    the config.

    Args:
        config (ConfigDict): The config object to check the required config for
        toolbox (ConfigTestToolbox): Toolbox used to execute the tests

    Returns:
        list of BaseResult
    """
    problems = []
    for key in ['ikey', 'api_host']:
        if not toolbox.test_config_has_key(config, key):
            problems.append(MissingKey(key=key))

    if not toolbox.test_config_has_key(config, 'skey',
                                       optionally_protected=True):
        problems.append(MissingKey(key='skey'))

    return problems
Beispiel #5
0
def check_required_keys(config, toolbox):
    """
    Validates that all required keys for an [ad_client] section are present
    in the config.

    Args:
        config (ConfigDict): The config object to check the required config for
        toolbox (ConfigTestToolbox): Toolbox used to execute the tests

    Returns:
        list of BaseResult
    """
    problems = []

    try:
        util.get_host_list(config)
    except ConfigError:
        problems.append(MissingKey(key="host"))

    # service_account_username, service_account_password are optional
    # for auth_type = AD_AUTH_TYPE_SSPI; mandatory otherwise. Just use
    # get() to fetch the auth_type here in order to bypass validation on
    # the value. Validation will happen in check_config_values and we don't
    # want duplicate errors if the auth_type config is invalid.
    auth_type = config.get("auth_type") or const.AD_AUTH_TYPE_NTLM_V2
    if auth_type.lower() != const.AD_AUTH_TYPE_SSPI:
        if not toolbox.test_config_has_key(config, "service_account_username"):
            problems.append(MissingKey(key="service_account_username"))

        if not toolbox.test_config_has_key(
                config, "service_account_password", optionally_protected=True):
            problems.append(
                MissingKey(key="service_account_password/"
                           "service_account_password_protected"))

    if not toolbox.test_config_has_key(config, "search_dn"):
        problems.append(MissingKey(key="search_dn"))

    return problems
Beispiel #6
0
def check_optional_keys(config, toolbox):
    """
    Validates that all optional keys for a [cloud] section exist if
    any are specified.

    Args:
        config (ConfigDict): The config object to check the required config for
        toolbox (ConfigTestToolbox): Toolbox used to execute the tests

    Returns:
        list of BaseResult
    """
    problems = []
    has_username = toolbox.test_config_has_key(
        config, 'service_account_username')
    has_password = toolbox.test_config_has_key(
        config, 'service_account_password', optionally_protected=True)

    if has_username and not has_password:
        problems.append(MissingKey(key='service_account_password'))
    elif has_password and not has_username:
        problems.append(MissingKey(key='service_account_username'))
    return problems
Beispiel #7
0
def check_config_dependencies(config):
    """ Validates dependencies between config options within an [main] section

    Args:
        config (ConfigDict): The config object to validate dependencies on

    Returns:
        list of ConfigResults

    """
    problems = []
    if "http_proxy_port" in config and "http_proxy_host" not in config:
        problems.append(MissingKey(key="http_proxy_host"))

    return problems
Beispiel #8
0
def check_required_keys(config, toolbox):
    """ Validates that all required keys for an [radius_server_auto] section are present in the config.

    Args:
        config (ConfigDict): The config object to check the required config for
        toolbox (ConfigTestToolbox): Toolbox used to execute the tests

    Returns:
        list of ConfigResults
    """
    problems = base.check_common_required_radius_keys(config, toolbox)

    if not toolbox.test_config_has_key(config, 'type'):
        problems.append(MissingKey(key='type'))

    return problems
def check_required_keys(config, toolbox):
    """
    Validates that all required keys for an [http_proxy] section
    are present in the config.

    Args:
        config (ConfigDict): The config object to check the required config for
        toolbox (ConfigTestToolbox): Toolbox used to execute the tests

    Returns:
        list of ConfigResult
    """
    problems = []
    if not toolbox.test_config_has_key(config, "api_host"):
        problems.append(MissingKey(key="api_host"))
    return problems
def check_config_dependencies(config, toolbox):
    """ Validates dependencies between config options within an [radius_client] section

    Args:
        config (ConfigDict): The config object to validate dependencies on
        toolbox (ConfigTestToolbox): The toolbox used to execute the tests

    Returns:
        list of zero or more MissingKey objects
    """
    problems = []

    # Check that a port given has a matching host
    for port in util.get_dynamic_keys(config, 'port'):
        host = 'host' + port.lstrip('port')
        if not toolbox.test_items_paired(config, port, host):
            problems.append(MissingKey(key=host))

    return problems