"""Helper validates the SQS message payload describing a transcoding job.""" from jsonschema import validate from jsonschema import ValidationError from transcoding.connectors import logger from transcoding.constants import exceptions as transcoding_exceptions from transcoding.validation.schema import passthrough_transcoding_job_schema from transcoding.validation.schema import transcoding_job_schema def validate_transcoding_job_schema(message, pass_through): """Validate sqs message. Args: message (dict): Message to validate. pass_through (bool): Whether the message is for passthrough transcoding job or not. Returns: bool: True if valid. Raises: TranscodingFatalError: In case of validation error error. """ app_logger = logger.get_current_logger() try: validation_schema = passthrough_transcoding_job_schema if pass_through else transcoding_job_schema validate(message, validation_schema) except ValidationError as e: app_logger.exception(str(e)) raise transcoding_exceptions.TranscodingFatalError(str(e)) return True