"""General constants for lambda functions.""" from enum import Enum import re from config import IGNORE_ALL_EVENTS from config import OWS_PROFILE_ID from config import OWS_PROFILE_ROLES from config import OWS_PROFILE_TYPE DEFAULT_HEADERS = { 'Orchard-Profile-Type': OWS_PROFILE_TYPE, 'Orchard-Profile-Id': OWS_PROFILE_ID, 'Orchard-Roles': OWS_PROFILE_ROLES, 'Accept-Encoding': 'gzip', } IGNORE_MESSAGE = ( f'Ignoring events because IGNORE_ALL_EVENTS environment variable is set to {IGNORE_ALL_EVENTS}.' 'To continue processing please remove this variable from lambda function configuration.' ) IGNORE_EMPTY_PAYLOAD = 'Ignoring events because it"s an empty payload.' FILE_KEY_REGEXP = re.compile( r""" (?P[L]) (?P\d+) (?:\|(?P\d+))?_ (?P\d{1,4})_ (?P[a-zA-Z0-9-_.*'()]+\.(?P\w{3,4}))$""", re.VERBOSE, ) # File size in bytes MAX_ALLOWED_FILE_SIZE_MB = 20 MAX_ALLOWED_FILE_SIZE = MAX_ALLOWED_FILE_SIZE_MB * 1024 * 1024 class Status(str, Enum): """Status.""" STATUS_COMPLETED = 'COMPLETED' STATUS_FAIL = 'FAIL' class FeatureFlag(str, Enum): """Feature Flag Enum.""" EMAIL_ON_FAIL = 'moneyhub_internal_attachments_email' S3_EVENT = 'moneyhub_internal_attachments_s3_event' class FileType(str, Enum): """File type.""" PDF = 'pdf' CSV = 'csv' XLS = 'xls' XLSX = 'xlsx' PNG = 'png' JPG = 'jpg' DOC = 'doc' DOCX = 'docx' class Error(str, Enum): """Error statuses.""" CANNOT_PARSE_BODY = 'Failed to parse event body with error: {error}' FILE_KEY_VERIFICATION_MESSAGE = 'File Key does not match the pattern: {}' MISSING_KEY_EXCEPTION = 'Failed to parse event body. Missing key: {key}' MOVE_ERROR = 'Error during move operation, saving the original path.' S3_COPY_ERROR_TEMPLATE = 'Error while copying {src} to {dst}' S3_DELETE_ERROR_TEMPLATE = 'Error while deleting {src}' INVALID_PATH_MSG = ( 'Invalid file path. Files must be uploaded into the root directory of the bucket' ) INVALID_NAME_MSG = ( 'File name does not match the pattern: LlabelID:contractId_periodID_filename.extension' ) INVALID_SIZE_MSG = f'Invalid size. Must be less then {MAX_ALLOWED_FILE_SIZE_MB} Mb.' INVALID_EXTENSION_MSG = ( f'Invalid extension. Please use one of the following: {", ".join(FileType)}' ) # Request Methods class RequestMethod(str, Enum): """Request methods enum.""" POST = 'post' # Email constants EMAIL_PROCESSING_ERROR = 'Something went wrong while processing the statement attachment.' EMAIL_ATTACHMENT_ERROR_SUBJECT = 'Statement attachment upload error.' EMAIL_ATTACHMENT_ERROR_BODY = """

Hi Everybody,

Unfortunately, it looks {full_file_name} was uploaded on {upload_timestamp} to the statement attachments upload directory and it does not conform to our upload criteria.

As a result this statement attachment will not show up in workstation for the associated label.

{error_detail}

To resolve this issue, please refer to the Upload Policy section of the Statement Attachments Workflow to confirm the file name and format are correct.

If anything is incorrect, please remove the file from the statement attachments upload directory, make the necessary changes and re-upload the document.

If there is still an issue, please email AccountingSquad@TheOrchard.com with the filename and upload timestamp as mentioned above.

Sincerely,
The Orchard Accounting Bot

"""