Browse Source

schema: Fix metadata schema patterns

This patch set fixes the schema pattern enforced by metadata_document
and metadata_control. Currently, both allow a schema with either
pattern:

- ^metadata/Control/v\d+$
- ^metadata/Document/v\d+$

However, the metadata_control schema should only allow the former
and the metadata_document schema should only allow the latter.

Change-Id: Ic1b88a7158755818002de4c88cdf2d7b716f656d
Felipe Monteiro 5 months ago
parent
commit
d5462d0c70

+ 8
- 8
deckhand/engine/document_validation.py View File

@@ -192,7 +192,7 @@ class GenericValidator(BaseValidator):
192 192
 class DataSchemaValidator(GenericValidator):
193 193
     """Validator for validating ``DataSchema`` documents."""
194 194
 
195
-    __slots__ = ('_default_schema_map', '_external_data_schemas')
195
+    __slots__ = ('_default_schema_map', '_current_data_schemas')
196 196
 
197 197
     def _build_schema_map(self, data_schemas):
198 198
         schema_map = copy.deepcopy(self._default_schema_map)
@@ -218,7 +218,7 @@ class DataSchemaValidator(GenericValidator):
218 218
         global _DEFAULT_SCHEMAS
219 219
 
220 220
         self._default_schema_map = _DEFAULT_SCHEMAS
221
-        self._external_data_schemas = [d.data for d in data_schemas]
221
+        self._current_data_schemas = [d.data for d in data_schemas]
222 222
         self._schema_map = self._build_schema_map(data_schemas)
223 223
 
224 224
     def _generate_validation_error_output(self, schema, document, error,
@@ -424,9 +424,9 @@ class DocumentValidation(object):
424 424
         """
425 425
 
426 426
         self._documents = []
427
-        self._external_data_schemas = [document_wrapper.DocumentDict(d)
428
-                                       for d in existing_data_schemas or []]
429
-        data_schema_map = {d.meta: d for d in self._external_data_schemas}
427
+        self._current_data_schemas = [document_wrapper.DocumentDict(d)
428
+                                      for d in existing_data_schemas or []]
429
+        data_schema_map = {d.meta: d for d in self._current_data_schemas}
430 430
 
431 431
         raw_properties = ('data', 'metadata', 'schema')
432 432
 
@@ -441,11 +441,11 @@ class DocumentValidation(object):
441 441
 
442 442
             document = document_wrapper.DocumentDict(raw_document)
443 443
             if document.schema.startswith(types.DATA_SCHEMA_SCHEMA):
444
-                self._external_data_schemas.append(document)
444
+                self._current_data_schemas.append(document)
445 445
                 # If a newer version of the same DataSchema was passed in,
446 446
                 # only use the new one and discard the old one.
447 447
                 if document.meta in data_schema_map:
448
-                    self._external_data_schemas.remove(
448
+                    self._current_data_schemas.remove(
449 449
                         data_schema_map.pop(document.meta))
450 450
 
451 451
             self._documents.append(document)
@@ -453,7 +453,7 @@ class DocumentValidation(object):
453 453
         self._pre_validate = pre_validate
454 454
 
455 455
         self._validators = [
456
-            DataSchemaValidator(self._external_data_schemas),
456
+            DataSchemaValidator(self._current_data_schemas),
457 457
         ]
458 458
         if self._pre_validate:
459 459
             # Only perform this additional validation "offline". The controller

+ 2
- 5
deckhand/engine/schemas/metadata_control.yaml View File

@@ -8,11 +8,8 @@ data:
8 8
   type: object
9 9
   properties:
10 10
     schema:
11
-      anyOf:
12
-        - type: string
13
-          pattern: ^metadata/Document/v\d+$
14
-        - type: string
15
-          pattern: ^metadata/Control/v\d+$
11
+      type: string
12
+      pattern: ^metadata/Control/v\d+$
16 13
     name:
17 14
       type: string
18 15
     labels:

+ 2
- 5
deckhand/engine/schemas/metadata_document.yaml View File

@@ -44,11 +44,8 @@ data:
44 44
   type: object
45 45
   properties:
46 46
     schema:
47
-      anyOf:
48
-        - type: string
49
-          pattern: ^metadata/Document/v\d+$
50
-        - type: string
51
-          pattern: ^metadata/Control/v\d+$
47
+      type: string
48
+      pattern: ^metadata/Document/v\d+$
52 49
     name:
53 50
       type: string
54 51
     labels:

Loading…
Cancel
Save