finalsa-common-models 2.0.0__py3-none-any.whl → 2.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- finalsa/common/models/__init__.py +8 -4
- finalsa/common/models/models/__init__.py +5 -3
- finalsa/common/models/models/functions.py +39 -2
- finalsa/common/models/models/sqs_response.py +3 -3
- {finalsa_common_models-2.0.0.dist-info → finalsa_common_models-2.0.1.dist-info}/METADATA +1 -1
- finalsa_common_models-2.0.1.dist-info/RECORD +9 -0
- finalsa_common_models-2.0.0.dist-info/RECORD +0 -9
- {finalsa_common_models-2.0.0.dist-info → finalsa_common_models-2.0.1.dist-info}/WHEEL +0 -0
- {finalsa_common_models-2.0.0.dist-info → finalsa_common_models-2.0.1.dist-info}/licenses/LICENSE.md +0 -0
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
from finalsa.common.models.models import (
|
|
2
2
|
Meta,
|
|
3
3
|
SqsReponse,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
parse_sns_message_attributes,
|
|
5
|
+
parse_sqs_message_attributes,
|
|
6
|
+
to_sqs_message_attributes,
|
|
7
|
+
to_sns_message_attributes,
|
|
6
8
|
)
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
__all__ = [
|
|
10
12
|
"Meta",
|
|
11
13
|
"SqsReponse",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
+
"parse_sns_message_attributes",
|
|
15
|
+
"parse_sqs_message_attributes",
|
|
16
|
+
"to_sqs_message_attributes",
|
|
17
|
+
"to_sns_message_attributes",
|
|
14
18
|
]
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
from .functions import
|
|
1
|
+
from .functions import parse_sns_message_attributes, parse_sqs_message_attributes, to_sqs_message_attributes, to_sns_message_attributes
|
|
2
2
|
from .sqs_response import SqsReponse
|
|
3
3
|
from .meta import Meta
|
|
4
4
|
|
|
5
5
|
__all__ = [
|
|
6
6
|
"Meta",
|
|
7
7
|
"SqsReponse",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"parse_sns_message_attributes",
|
|
9
|
+
"parse_sqs_message_attributes",
|
|
10
|
+
"to_sqs_message_attributes",
|
|
11
|
+
"to_sns_message_attributes"
|
|
10
12
|
]
|
|
@@ -4,7 +4,7 @@ from decimal import Decimal
|
|
|
4
4
|
from uuid import UUID
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def
|
|
7
|
+
def parse_sns_message_attributes(attributes: Dict) -> Dict:
|
|
8
8
|
message_attributes = {}
|
|
9
9
|
if not attributes:
|
|
10
10
|
return message_attributes
|
|
@@ -17,8 +17,20 @@ def parse_message_attributes(attributes: Dict) -> Dict:
|
|
|
17
17
|
message_attributes[key] = bytes(value['Value'], 'utf-8')
|
|
18
18
|
return message_attributes
|
|
19
19
|
|
|
20
|
+
def parse_sqs_message_attributes(attributes: Dict) -> Dict:
|
|
21
|
+
message_attributes = {}
|
|
22
|
+
if not attributes:
|
|
23
|
+
return message_attributes
|
|
24
|
+
for key, value in attributes.items():
|
|
25
|
+
if value['DataType'] == 'String':
|
|
26
|
+
message_attributes[key] = value['StringValue']
|
|
27
|
+
elif value['DataType'] == 'Number':
|
|
28
|
+
message_attributes[key] = int(value['StringValue'])
|
|
29
|
+
elif value['DataType'] == 'Binary':
|
|
30
|
+
message_attributes[key] = bytes(value['StringValue'], 'utf-8')
|
|
31
|
+
return message_attributes
|
|
20
32
|
|
|
21
|
-
def
|
|
33
|
+
def to_sqs_message_attributes(attributes: Dict) -> Dict:
|
|
22
34
|
att_dict = {}
|
|
23
35
|
for key, value in attributes.items():
|
|
24
36
|
if isinstance(value, str):
|
|
@@ -40,3 +52,28 @@ def to_message_attributes(attributes: Dict) -> Dict:
|
|
|
40
52
|
att_dict[key] = {
|
|
41
53
|
'DataType': 'Binary', 'BinaryValue': value}
|
|
42
54
|
return att_dict
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def to_sns_message_attributes(attributes: Dict) -> Dict:
|
|
59
|
+
att_dict = {}
|
|
60
|
+
for key, value in attributes.items():
|
|
61
|
+
if isinstance(value, str):
|
|
62
|
+
att_dict[key] = {
|
|
63
|
+
'Type': 'String', 'Value': value}
|
|
64
|
+
elif isinstance(value, Decimal):
|
|
65
|
+
att_dict[key] = {
|
|
66
|
+
'Type': 'Number', 'Value': str(value)}
|
|
67
|
+
elif isinstance(value, UUID):
|
|
68
|
+
att_dict[key] = {
|
|
69
|
+
'Type': 'String', 'Value': str(value)}
|
|
70
|
+
elif isinstance(value, datetime):
|
|
71
|
+
att_dict[key] = {
|
|
72
|
+
'Type': 'String', 'Value': value.isoformat()}
|
|
73
|
+
elif isinstance(value, int):
|
|
74
|
+
att_dict[key] = {
|
|
75
|
+
'Type': 'Number', 'Value': str(value)}
|
|
76
|
+
elif isinstance(value, bytes):
|
|
77
|
+
att_dict[key] = {
|
|
78
|
+
'Type': 'Binary', 'Value': value}
|
|
79
|
+
return att_dict
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from typing import Dict, Optional, Union
|
|
2
2
|
from pydantic import BaseModel
|
|
3
3
|
from orjson import loads
|
|
4
|
-
from .functions import
|
|
4
|
+
from .functions import parse_sqs_message_attributes, parse_sns_message_attributes
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class SqsReponse(BaseModel):
|
|
@@ -26,7 +26,7 @@ class SqsReponse(BaseModel):
|
|
|
26
26
|
|
|
27
27
|
def __parse_from_sns__(self, payload: Dict) -> Union[str, Dict]:
|
|
28
28
|
self.topic = str(payload['TopicArn'].split(':')[-1]).lower()
|
|
29
|
-
self.message_attributes =
|
|
29
|
+
self.message_attributes = parse_sns_message_attributes(
|
|
30
30
|
payload.get('MessageAttributes', {}))
|
|
31
31
|
try:
|
|
32
32
|
return loads(payload['Message'])
|
|
@@ -59,6 +59,6 @@ class SqsReponse(BaseModel):
|
|
|
59
59
|
attributes=response['Attributes'],
|
|
60
60
|
md5_of_message_attributes=response.get(
|
|
61
61
|
'MD5OfMessageAttributes', ''),
|
|
62
|
-
message_attributes=
|
|
62
|
+
message_attributes=parse_sqs_message_attributes(
|
|
63
63
|
response.get('MessageAttributes', {}))
|
|
64
64
|
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
finalsa/common/models/__init__.py,sha256=FgaW3-ykBoS6QVLLvTdje5zz85Ei0Pe8M7LtB2QOMiU,385
|
|
2
|
+
finalsa/common/models/models/__init__.py,sha256=75LSf90upIL2qlxyHQ_7QFUhKGHM6b3n1RE7-qEWDpk,378
|
|
3
|
+
finalsa/common/models/models/functions.py,sha256=vKUrhl3AVfnYBqqKYpZbZevrBpUx7ywqhtU3KKPqWUE,2983
|
|
4
|
+
finalsa/common/models/models/meta.py,sha256=YX62zKeu_3McVJUhGDrub897XfuGxDDKGw5AejEL48g,213
|
|
5
|
+
finalsa/common/models/models/sqs_response.py,sha256=GKkDyWYeYEUCRHp2H8MjxvzFuwWL1ngzpf5zILhVUNg,2258
|
|
6
|
+
finalsa_common_models-2.0.1.dist-info/METADATA,sha256=6ttMktELBnzxnQoT_SH9_Qf4rMl4G2hND65Qw4cOxq4,3054
|
|
7
|
+
finalsa_common_models-2.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
finalsa_common_models-2.0.1.dist-info/licenses/LICENSE.md,sha256=yqzhfnTBr2S4lUBx-yibVPOIXRUDPrSUN9-_7AsC6OU,1084
|
|
9
|
+
finalsa_common_models-2.0.1.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
finalsa/common/models/__init__.py,sha256=dpbPa6l-MEYqNegIV813SZz2yKU8fI-kcmS8ZuSzQAs,234
|
|
2
|
-
finalsa/common/models/models/__init__.py,sha256=B3PmLZ4CUgrCIXNlBvfRMbfroiX1xgL4-TS-2D2-Tv8,237
|
|
3
|
-
finalsa/common/models/models/functions.py,sha256=4bA57p5ar0btRlygzzLIlImQxOTypH3EQUyzys-ryE8,1551
|
|
4
|
-
finalsa/common/models/models/meta.py,sha256=YX62zKeu_3McVJUhGDrub897XfuGxDDKGw5AejEL48g,213
|
|
5
|
-
finalsa/common/models/models/sqs_response.py,sha256=CIK02um2Cl8spIORbu7uZn6g6YkILvjcCN3OWTTF-xo,2216
|
|
6
|
-
finalsa_common_models-2.0.0.dist-info/METADATA,sha256=Z_p-YJewJdQtIaegzSdv70iSupiy-FxFAeiLGrchovs,3054
|
|
7
|
-
finalsa_common_models-2.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
-
finalsa_common_models-2.0.0.dist-info/licenses/LICENSE.md,sha256=yqzhfnTBr2S4lUBx-yibVPOIXRUDPrSUN9-_7AsC6OU,1084
|
|
9
|
-
finalsa_common_models-2.0.0.dist-info/RECORD,,
|
|
File without changes
|
{finalsa_common_models-2.0.0.dist-info → finalsa_common_models-2.0.1.dist-info}/licenses/LICENSE.md
RENAMED
|
File without changes
|