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))
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")
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