コード例 #1
0
def parse_notifiers_config(value):
    result = []
    for data in value:
        try:
            instance = manager.get(data['type'])
        except KeyError:
            raise ApiError(
                message='Invalid notifier: {}'.format(data['type']),
                name='invalid_notifier',
            )

        config = data.get('config', {})
        all_options = chain(instance.get_default_options().items(),
                            instance.get_options().items())
        for option, option_values in all_options:
            value = config.get(option)
            if option_values.get('required') and not value:
                raise ApiError(
                    message='Missing required option "{}" for notifier: {}'.format(option, data['type']),
                    name='invalid_notifier',
                )
        result.append({
            'type': data['type'],
            'config': config,
        })
    return result
コード例 #2
0
ファイル: utils.py プロジェクト: sandrociceros/freight
def parse_checks_config(value):
    result = []
    for data in value:
        try:
            instance = manager.get(data["type"])
        except KeyError:
            raise ApiError(message=f"Invalid check: {data['type']}",
                           name="invalid_check")

        config = data.get("config", {})
        all_options = chain(
            list(instance.get_default_options().items()),
            list(instance.get_options().items()),
        )
        for option, option_values in all_options:
            value = config.get(option)
            if value and option_values.get("type"):
                try:
                    config[option] = option_values["type"](value)
                except (ValueError, TypeError):
                    raise ApiError(
                        message=
                        f'Option "{option}" is not a valid type for check: {data["type"]}',
                        name="invalid_check",
                    )
            if option_values.get("required") and not value:
                raise ApiError(
                    message=
                    f'Missing required option "{option}" for check: {data["type"]}',
                    name="invalid_check",
                )
        result.append({"type": data["type"], "config": config})
    return result
コード例 #3
0
ファイル: utils.py プロジェクト: thoas/freight
def parse_environments_config(value):
    if not isinstance(value, dict):
        raise ApiError(
            message='Invalid data type for environments',
            name='invalid_environment',
        )

    result = {}
    for env_name, data in value.iteritems():
        if not isinstance(data, dict):
            raise ApiError(
                message='Invalid data type for environment "{}"'.format(env_name),
                name='invalid_environment',
            )

        result[env_name] = {
            'default_ref': data.get('default_ref', 'master'),
        }
    return result
コード例 #4
0
def parse_environments_config(value):
    if not isinstance(value, dict):
        raise ApiError(message="Invalid data type for environments",
                       name="invalid_environment")

    result = {}
    for env_name, data in list(value.items()):
        if not isinstance(data, dict):
            raise ApiError(
                message=f'Invalid data type for environment "{env_name}"',
                name="invalid_environment",
            )

        result[env_name] = {
            # TODO(dcramer): this is a mess, we should unify the API to just look
            # like JSON
            "default_ref":
            data.get("defaultRef", data.get("default_ref", "master"))
        }
    return result
コード例 #5
0
def parse_provider_config(type, config):
    try:
        instance = manager.get(type)
    except KeyError:
        raise ApiError(
            message='Invalid provider: {}'.format(type),
            name='invalid_provider',
        )

    result = {}
    all_options = chain(instance.get_default_options().items(),
                        instance.get_options().items())
    for option, option_values in all_options:
        value = config.get(option)
        if option_values.get('required') and not value:
            raise ApiError(
                message='Missing required option "{}" for provider: {}'.format(
                    option, type),
                name='invalid_provider',
            )
        result[option] = value
    return result
コード例 #6
0
def parse_environments_config(value):
    if not isinstance(value, dict):
        raise ApiError(
            message='Invalid data type for environments',
            name='invalid_environment',
        )

    result = {}
    for env_name, data in value.iteritems():
        if not isinstance(data, dict):
            raise ApiError(
                message='Invalid data type for environment "{}"'.format(
                    env_name),
                name='invalid_environment',
            )

        result[env_name] = {
            # TODO(dcramer): this is a mess, we should unify the API to just look
            # like JSON
            'default_ref':
            data.get('defaultRef', data.get('default_ref', 'master')),
        }
    return result
コード例 #7
0
ファイル: utils.py プロジェクト: thoas/freight
def parse_checks_config(value):
    result = []
    for data in value:
        try:
            instance = manager.get(data['type'])
        except KeyError:
            raise ApiError(
                message='Invalid check: {}'.format(data['type']),
                name='invalid_check',
            )

        config = data.get('config', {})
        all_options = chain(instance.get_default_options().items(),
                            instance.get_options().items())
        for option, option_values in all_options:
            value = config.get(option)
            if value and option_values.get('type'):
                try:
                    config[option] = option_values['type'](value)
                except (ValueError, TypeError):
                    raise ApiError(
                        message='Option "{}" is not a valid type for check: {}'
                        .format(option, data['type']),
                        name='invalid_check',
                    )
            if option_values.get('required') and not value:
                raise ApiError(
                    message='Missing required option "{}" for check: {}'.
                    format(option, data['type']),
                    name='invalid_check',
                )
        result.append({
            'type': data['type'],
            'config': config,
        })
    return result