예제 #1
0
def validate_schema(file_path, file_type):
    """Check if the specified config file has a valid schema

    :param file_path: path to file to validate
    :param file_type: what schema type should we validate against
    """
    schema = get_schema(file_type)
    if (schema is None):
        print '%s: %s' % (SCHEMA_NOT_FOUND, file_path)
        return
    validator = Draft4Validator(schema, format_checker=FormatChecker())
    basename = os.path.basename(file_path)
    extension = os.path.splitext(basename)[1]
    try:
        config_file = get_file_contents(file_path)
    except IOError:
        print '%s: %s' % (FAILED_READING_FILE, file_path)
        return False
    if extension == '.yaml':
        config_file_object = yaml.load(config_file)
    elif extension == '.json':
        config_file_object = json.loads(config_file)
    else:
        config_file_object = config_file
    try:
        validator.validate(config_file_object)
    except ValidationError as e:
        print '%s: %s' % (SCHEMA_INVALID, file_path)
        print '  Validation Message: %s' % e.message
        return False
    else:
        print '%s: %s' % (SCHEMA_VALID, basename)
        return True
예제 #2
0
def validate_schema(file_path, file_type):
    """Check if the specified config file has a valid schema

    :param file_path: path to file to validate
    :param file_type: what schema type should we validate against
    """
    schema = get_schema(file_type)
    if (schema is None):
        paasta_print(f'{SCHEMA_NOT_FOUND}: {file_path}')
        return
    validator = Draft4Validator(schema, format_checker=FormatChecker())
    basename = os.path.basename(file_path)
    extension = os.path.splitext(basename)[1]
    try:
        config_file = get_file_contents(file_path)
        if extension == '.yaml':
            config_file_object = yaml.safe_load(config_file)
        elif extension == '.json':
            config_file_object = json.loads(config_file)
        else:
            config_file_object = config_file
    except Exception:
        paasta_print(f'{FAILED_READING_FILE}: {file_path}')
        raise
    try:
        validator.validate(config_file_object)
    except ValidationError:
        paasta_print(f'{SCHEMA_INVALID}: {file_path}')

        errors = validator.iter_errors(config_file_object)
        paasta_print('  Validation Message: %s' %
                     exceptions.best_match(errors).message)
    else:
        paasta_print(f'{SCHEMA_VALID}: {basename}')
        return True
예제 #3
0
파일: validate.py 프로젝트: timopek/paasta
def validate_schema(file_path, file_type):
    """Check if the specified config file has a valid schema

    :param file_path: path to file to validate
    :param file_type: what schema type should we validate against
    """
    schema = get_schema(file_type)
    if (schema is None):
        print '%s: %s' % (SCHEMA_NOT_FOUND, file_path)
        return
    validator = Draft4Validator(schema, format_checker=FormatChecker())
    basename = os.path.basename(file_path)
    extension = os.path.splitext(basename)[1]
    try:
        config_file = get_file_contents(file_path)
    except IOError:
        print '%s: %s' % (FAILED_READING_FILE, file_path)
        return 1
    if extension == '.yaml':
        config_file_object = yaml.load(config_file)
    elif extension == '.json':
        config_file_object = json.loads(config_file)
    else:
        config_file_object = config_file
    try:
        validator.validate(config_file_object)
    except ValidationError as e:
        print '%s: %s' % (SCHEMA_INVALID, file_path)
        print '  Validation Message: %s' % e.message
        return 1
    else:
        print '%s: %s' % (SCHEMA_VALID, basename)
        return 0
def get_config_file_dict(file_path):
    basename = os.path.basename(file_path)
    extension = os.path.splitext(basename)[1]
    try:
        config_file = get_file_contents(file_path)
        if extension == ".yaml":
            return yaml.safe_load(config_file)
        elif extension == ".json":
            return json.loads(config_file)
        else:
            return config_file
    except Exception:
        paasta_print(f"{FAILED_READING_FILE}: {file_path}")
        raise
예제 #5
0
def validate_schema(file_path, file_type):
    """Check if the specified config file has a valid schema

    :param file_path: path to file to validate
    :param file_type: what schema type should we validate against
    """
    try:
        schema = get_schema(file_type)
    except Exception as e:
        paasta_print(f"{SCHEMA_ERROR}: {file_type}, error: {e!r}")
        return

    if schema is None:
        paasta_print(f"{SCHEMA_NOT_FOUND}: {file_path}")
        return
    validator = Draft4Validator(schema, format_checker=FormatChecker())
    basename = os.path.basename(file_path)
    extension = os.path.splitext(basename)[1]
    try:
        config_file = get_file_contents(file_path)
        if extension == ".yaml":
            config_file_object = yaml.safe_load(config_file)
        elif extension == ".json":
            config_file_object = json.loads(config_file)
        else:
            config_file_object = config_file
    except Exception:
        paasta_print(f"{FAILED_READING_FILE}: {file_path}")
        raise
    try:
        validator.validate(config_file_object)
        if file_type == "kubernetes" and not validate_instance_names(
                config_file_object, file_path):
            return
    except ValidationError:
        paasta_print(f"{SCHEMA_INVALID}: {file_path}")

        errors = validator.iter_errors(config_file_object)
        paasta_print("  Validation Message: %s" %
                     exceptions.best_match(errors).message)
    except Exception as e:
        paasta_print(f"{SCHEMA_ERROR}: {file_type}, error: {e!r}")
        return
    else:
        paasta_print(f"{SCHEMA_VALID}: {basename}")
        return True
예제 #6
0
파일: check.py 프로젝트: seco/paasta
def makefile_has_docker_tag(makefile_path):
    contents = get_file_contents(makefile_path)
    return re.search(r"DOCKER_TAG\s*\?=", contents, re.MULTILINE) is not None
예제 #7
0
파일: check.py 프로젝트: seco/paasta
def makefile_has_a_tab(makefile_path):
    contents = get_file_contents(makefile_path)
    return '\t' in contents
예제 #8
0
파일: check.py 프로젝트: sbcoba/paasta
def makefile_has_docker_tag(makefile_path):
    contents = get_file_contents(makefile_path)
    return re.search(r"^DOCKER_TAG\s*\?=", contents, re.MULTILINE) is not None
예제 #9
0
파일: check.py 프로젝트: sbcoba/paasta
def makefile_has_a_tab(makefile_path):
    contents = get_file_contents(makefile_path)
    return '\t' in contents