def _ValidateEntityContent(self, entity: syaml.YAML) -> None: """Validates the contents of a single entity. The logic will select the appropriate validation schema based on the config_mode of the container and the defined EntityOperation, if any. Args: entity: YAML object for the entityContents Raises: KeyError: if self._config_mode is not set to a known value. """ if ConfigMode.INITIALIZE == self._config_mode: schema = syaml.Map(_ENTITY_INIT_SCHEMA) elif ConfigMode.UPDATE == self._config_mode: schema = syaml.Map(_ENTITY_UPDATE_SCHEMA) if ENTITY_OPERATION_KEY in entity: if entity[ENTITY_OPERATION_KEY] == EntityOperation.ADD.value: schema = syaml.Map(_ENTITY_ADD_SCHEMA) elif entity[ENTITY_OPERATION_KEY] == EntityOperation.DELETE.value: schema = syaml.Map(_ENTITY_DELETE_SCHEMA) else: raise KeyError('No valid _config_mode is set') entity.revalidate(schema) if TRANSLATION_KEY in entity.data.keys(): if ENTITY_CLOUD_DEVICE_ID_KEY not in entity.data.keys(): raise KeyError('cloud_device_id required when translation is present.')
def _ValidateEntityContent(self, entity: syaml.YAML) -> None: """Validates the contents of a single entity. The logic will select the appropriate validation schema based on the config_mode of the container and the defined EntityOperation, if any. Args: entity: YAML object for the entityContents Raises: KeyError: if self._config_mode is not set to a known value. """ if ConfigMode.INITIALIZE == self._config_mode: schema = syaml.Map(_ENTITY_INIT_SCHEMA) elif ConfigMode.UPDATE == self._config_mode: schema = syaml.Map(_ENTITY_UPDATE_SCHEMA) if _ENTITY_MODE_KEY in entity: if entity[_ENTITY_MODE_KEY] == EntityOperation.ADD.value: schema = syaml.Map(_ENTITY_ADD_SCHEMA) elif entity[_ENTITY_MODE_KEY] == EntityOperation.DELETE.value: schema = syaml.Map(_ENTITY_DELETE_SCHEMA) else: raise KeyError('No valid _config_mode is set') entity.revalidate(schema)
def is_pipelines_config_valid(strictyaml_pipelines: YAML) -> YAML: """ TODO: Refactor to test and analyzer specific config validation. """ pipelines_schema = Map({ "pipelines": Seq( Map({ "name": Str(), "type": Enum(["test", "analyzer"]), Optional("coverage"): Str(), Optional("commands"): Map({ "partial-scope": Str(), "full-scope": Str() }), Optional("dirs"): Seq( Map({ "path": Str(), Optional("full-scope", default=False): Bool() })), Optional("files"): Seq( Map({ "path": Str(), Optional("full-scope", default=False): Bool() })) })) }) try: strictyaml_pipelines.revalidate(pipelines_schema) return True except YAMLValidationError: return False