Example #1
0
def config_check_service(environments, ctx, service_name, service):
    try:
        ctx = ctx + [service_name] 
        validate.value(ctx, service, 'object')
        env_name = validate.obj_field_opt(ctx, service, 'environment', 'string')
        default = env_name is None
        if 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(ctx))
            else:
                raise validate.ConfigError('In %s, unrecognized environment %s'
                                  % (validate.render_path(ctx), env_name))
        compiler = service_compilers.get(env['kind'])
        compiler.validateService(ctx, service_name, service)
        for child_name, child in compiler.children(service):
            config_check_service(environments, ctx, child_name, child)
    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(ctx))
        raise
Example #2
0
def config_check(config):
    validate.value('top level', config, 'object')
    environments = validate.obj_field('top level', config, 'environments', 'object')

    # Check environments
    environments = config.get('environments')
    if not isinstance(environments, dict):
        raise validate.ConfigError('Must have an object in $.environments.')
    for env_name, env in environments.iteritems():
        kind_name = validate.obj_field('environment %s' % env_name, env, '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(env_name, env)

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