Пример #1
0
def config_check_service(environments, root, path):
    try:
        service = validate.path_val(root, path, 'object')
        env_name = validate.path_val(root, path + ['environment'], 'string',
                                     'default')
        default = env_name == 'default'
        env = environments.get(env_name)
        if env is None:
            if default:
                raise validate.ConfigError(
                    ('The service at %s has no environment field, and no ' +
                     'environment called "default" exists.') %
                    validate.render_path(path))
            else:
                raise validate.ConfigError(
                    'In %s, unrecognized environment %s' %
                    (validate.render_path(path), env_name))
        compiler = service_compilers.get(env['kind'])
        compiler.validateService(root, path)
        for child_name, child in compiler.children(service):
            config_check_service(environments, root, path + [child_name])
    except validate.ConfigError as e:
        if e.note is None:
            e.note = (
                'Did you mean for %s to be a visible field (: instead of ::)?'
                % validate.render_path(path))
        raise
Пример #2
0
def config_check(config):
    validate.path_val(config, [], 'object')
    environments = validate.path_val(config, ['environments'], 'object', {})

    # Check environments
    environments = config['environments']
    for env_name, env in environments.iteritems():
        kind_name = validate.path_val(config,
                                      ['environments', env_name, 'kind'],
                                      'string')
        compiler = service_compilers.get(kind_name)
        if not compiler:
            raise validate.ConfigError(
                'Unrecognized kind "%s" in environment %s' %
                (kind_name, env_name))
        compiler.validateEnvironment(config, ['environments', env_name])

    # Check services
    for service_name, service in services(config):
        config_check_service(environments, config, [service_name])