"""Validation of ownership change request, received from SQS.""" from oto import response import validictory from label_copy_export.constants import error from label_copy_export.validation.schema import schema def validate_sqs_message(message): """Validate input message with library. Args: message (object): JSONMessageExt object. Returns: Response: validation response. """ try: payload = message.get_body() validictory.validate(payload, schema) if not message.correlation_id: return response.create_error_response( code=error.ERROR_CORRELLATION_ID_INVALID, message=error.ERROR_CORRELLATION_ID_INVALID_MESSAGE ) except (AttributeError, ValueError) as e: return response.create_error_response( code=error.ERROR_MISSING_FIELDS_IN_SQS_MESSAGE, message=str(e) ) return response.Response()