예제 #1
0
def validate_value(val, schema, format_checker=None):
    """Simple wrapper for jsonschema.validate for usability.

    NOTE: silently passes empty schemas.
    """
    try:
        jsonschema.validate(val, schema, format_checker=format_checker)
    except jsonschema.exceptions.ValidationError as ex:
        raise exception.SchemaValidationException(
            "Schema validation failed: %s" % str(ex))
예제 #2
0
def validate_value(val, schema, format_checker=None):
    """Simple wrapper for jsonschema.validate for usability.

    NOTE: silently passes empty schemas.
    """
    try:
        jsonschema.validate(val, schema, format_checker=format_checker)
    except jsonschema.exceptions.ValidationError as ex:
        LOG.debug("Schema validation failed: %s", ex)
        # Don't pass the value in the exception to avoid including sensitive
        # data (e.g. passwords)
        raise exception.SchemaValidationException("Schema validation failed")
예제 #3
0
def validate_value(val, schema, format_checker=None, raise_on_error=True):
    """Simple wrapper for jsonschema.validate for usability.
    NOTE: silently passes empty schemas.

    If `raise_on_error` is False, returns a boolean indicating whether
    or not the validation was successful.
    """
    try:
        jsonschema.validate(val, schema, format_checker=format_checker)
    except jsonschema.exceptions.ValidationError as ex:
        if raise_on_error:
            raise exception.SchemaValidationException(
                "Schema validation failed: %s" % str(ex))
        else:
            LOG.warn("Schema validation failed, ignoring: %s",
                     utils.get_exception_details())
        return False

    return True