Skip to content

Commit 76e89c3

Browse files
adding validation
1 parent 120e7c8 commit 76e89c3

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

socketlabs/injectionapi/core/sendvalidator.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def validate_base_message(message: MessageBase):
3939
if not has_valid_custom_headers(message.custom_headers):
4040
return SendResult.MessageValidationInvalidCustomHeaders
4141

42+
if message.metadata is not None and len(message.metadata) > 0:
43+
if not has_valid_metadata(message.metadata):
44+
return SendResult.MessageValidationInvalidMetadata
45+
4246
return SendResult.Success
4347

4448

@@ -294,6 +298,23 @@ def has_valid_custom_headers(custom_headers: list):
294298
return True
295299

296300

301+
def has_valid_metadata(metadata: list):
302+
"""
303+
Check if the list of metadata is valid
304+
:param metadata: list of Metadata to validate
305+
:type metadata: list
306+
:return the result
307+
:rtype bool
308+
"""
309+
if metadata is None:
310+
return True
311+
for item in metadata:
312+
valid = item.isvalid()
313+
if valid is False:
314+
return False
315+
return True
316+
317+
297318
def validate_basic_message(message: BasicMessage):
298319
"""
299320
Validate a basic email message before sending to the Injection API.

socketlabs/injectionapi/sendresult.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from enum import Enum
22

33

4-
class SendResult(Enum):
5-
"""
6-
Enumerated result of the client send
4+
class SendResult(Enum):
5+
"""
6+
Enumerated result of the client send
77
"""
88

99
""" An error has occurred that was unforeseen """
@@ -117,6 +117,9 @@ class SendResult(Enum):
117117
""" SDK Validation Error : Invalid Custom Headers were found in the message """
118118
MessageValidationInvalidCustomHeaders = 36
119119

120+
""" SDK Validation Error : Message contains invalid metadata """
121+
MessageValidationInvalidMetadata = 37
122+
120123
def __str__(self):
121124
"""
122125
String representation of the SendResult Enum
@@ -167,6 +170,8 @@ def __str__(self):
167170
35: "SDK Validation Error : No message body was found in the message",
168171
36: "SDK Validation Error : "
169172
"Invalid Custom Headers were found in the message",
173+
37: "SDK Validation Error : "
174+
"Message contains invalid metadata",
170175
}
171176
return switcher.get(self.value, "An error has occurred that was unforeseen")
172177

0 commit comments

Comments
 (0)