Explorar o código

Adds SchemaValidationException

Alessandro Pilotti %!s(int64=9) %!d(string=hai) anos
pai
achega
d1434a8c93
Modificáronse 2 ficheiros con 14 adicións e 1 borrados
  1. 4 0
      coriolis/exception.py
  2. 10 1
      coriolis/schemas.py

+ 4 - 0
coriolis/exception.py

@@ -292,3 +292,7 @@ class OperatingSystemNotFound(NotFound):
 
 class ConnectionValidationException(CoriolisException):
     pass
+
+
+class SchemaValidationException(CoriolisException):
+    pass

+ 10 - 1
coriolis/schemas.py

@@ -10,6 +10,8 @@ import jsonschema
 
 from oslo_log import log as logging
 
+from coriolis import exception
+
 LOG = logging.getLogger(__name__)
 
 
@@ -45,7 +47,14 @@ def validate_value(val, schema):
 
     NOTE: silently passes empty schemas.
     """
-    jsonschema.validate(val, schema)
+    try:
+        jsonschema.validate(val, schema)
+    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_string(json_string, schema):