"""Validation logic. ==================== Validation of ownership change request, received from SQS. """ import json from oto import response import validictory from salessheets.constants import errors from salessheets.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 = json.loads(message['Body']) validictory.validate(payload, schema) if not message['MessageAttributes']['Correlation-Id']: return response.create_error_response( code=errors.ERROR_CORRELLATION_ID_INVALID, message=errors.ERROR_CORRELLATION_ID_INVALID_MESSAGE ) except (AttributeError, ValueError) as e: return response.create_error_response( code=errors.ERROR_MISSING_FIELDS_IN_SQS_MESSAGE, message=str(e) ) return response.Response()