finalsa-common-models 2.0.0__tar.gz → 2.0.2__tar.gz
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-2.0.0 → finalsa_common_models-2.0.2}/PKG-INFO +1 -1
- finalsa_common_models-2.0.2/finalsa/common/models/__init__.py +18 -0
- finalsa_common_models-2.0.2/finalsa/common/models/models/__init__.py +15 -0
- finalsa_common_models-2.0.2/finalsa/common/models/models/functions.py +79 -0
- finalsa_common_models-2.0.2/finalsa/common/models/models/meta.py +30 -0
- {finalsa_common_models-2.0.0 → finalsa_common_models-2.0.2}/finalsa/common/models/models/sqs_response.py +3 -3
- {finalsa_common_models-2.0.0 → finalsa_common_models-2.0.2}/pyproject.toml +1 -1
- finalsa_common_models-2.0.0/finalsa/common/models/__init__.py +0 -14
- finalsa_common_models-2.0.0/finalsa/common/models/models/__init__.py +0 -10
- finalsa_common_models-2.0.0/finalsa/common/models/models/functions.py +0 -42
- finalsa_common_models-2.0.0/finalsa/common/models/models/meta.py +0 -10
- {finalsa_common_models-2.0.0 → finalsa_common_models-2.0.2}/.gitignore +0 -0
- {finalsa_common_models-2.0.0 → finalsa_common_models-2.0.2}/LICENSE.md +0 -0
- {finalsa_common_models-2.0.0 → finalsa_common_models-2.0.2}/README.md +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from finalsa.common.models.models import (
|
|
2
|
+
Meta,
|
|
3
|
+
SqsReponse,
|
|
4
|
+
parse_sns_message_attributes,
|
|
5
|
+
parse_sqs_message_attributes,
|
|
6
|
+
to_sqs_message_attributes,
|
|
7
|
+
to_sns_message_attributes,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"Meta",
|
|
13
|
+
"SqsReponse",
|
|
14
|
+
"parse_sns_message_attributes",
|
|
15
|
+
"parse_sqs_message_attributes",
|
|
16
|
+
"to_sqs_message_attributes",
|
|
17
|
+
"to_sns_message_attributes",
|
|
18
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .functions import parse_sns_message_attributes, parse_sqs_message_attributes, to_sqs_message_attributes, to_sns_message_attributes
|
|
2
|
+
from .sqs_response import SqsReponse
|
|
3
|
+
from .meta import Meta, AsyncMeta, Authorization, HttpMeta
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"Meta",
|
|
7
|
+
"AsyncMeta",
|
|
8
|
+
"Authorization",
|
|
9
|
+
"HttpMeta",
|
|
10
|
+
"SqsReponse",
|
|
11
|
+
"parse_sns_message_attributes",
|
|
12
|
+
"parse_sqs_message_attributes",
|
|
13
|
+
"to_sqs_message_attributes",
|
|
14
|
+
"to_sns_message_attributes"
|
|
15
|
+
]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from decimal import Decimal
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def parse_sns_message_attributes(attributes: Dict) -> Dict:
|
|
8
|
+
message_attributes = {}
|
|
9
|
+
if not attributes:
|
|
10
|
+
return message_attributes
|
|
11
|
+
for key, value in attributes.items():
|
|
12
|
+
if value['Type'] == 'String':
|
|
13
|
+
message_attributes[key] = value['Value']
|
|
14
|
+
elif value['Type'] == 'Number':
|
|
15
|
+
message_attributes[key] = int(value['Value'])
|
|
16
|
+
elif value['Type'] == 'Binary':
|
|
17
|
+
message_attributes[key] = bytes(value['Value'], 'utf-8')
|
|
18
|
+
return message_attributes
|
|
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
|
|
32
|
+
|
|
33
|
+
def to_sqs_message_attributes(attributes: Dict) -> Dict:
|
|
34
|
+
att_dict = {}
|
|
35
|
+
for key, value in attributes.items():
|
|
36
|
+
if isinstance(value, str):
|
|
37
|
+
att_dict[key] = {
|
|
38
|
+
'DataType': 'String', 'StringValue': value}
|
|
39
|
+
elif isinstance(value, Decimal):
|
|
40
|
+
att_dict[key] = {
|
|
41
|
+
'DataType': 'Number', 'StringValue': str(value)}
|
|
42
|
+
elif isinstance(value, UUID):
|
|
43
|
+
att_dict[key] = {
|
|
44
|
+
'DataType': 'String', 'StringValue': str(value)}
|
|
45
|
+
elif isinstance(value, datetime):
|
|
46
|
+
att_dict[key] = {
|
|
47
|
+
'DataType': 'String', 'StringValue': value.isoformat()}
|
|
48
|
+
elif isinstance(value, int):
|
|
49
|
+
att_dict[key] = {
|
|
50
|
+
'DataType': 'Number', 'StringValue': str(value)}
|
|
51
|
+
elif isinstance(value, bytes):
|
|
52
|
+
att_dict[key] = {
|
|
53
|
+
'DataType': 'Binary', 'BinaryValue': value}
|
|
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
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import Optional, List
|
|
4
|
+
|
|
5
|
+
class Authorization(BaseModel):
|
|
6
|
+
token: str
|
|
7
|
+
user_id: str
|
|
8
|
+
roles: Optional[List[str]] = None
|
|
9
|
+
groups: Optional[List[str]] = None
|
|
10
|
+
permissions: Optional[List[str]] = None
|
|
11
|
+
scopes: Optional[List[str]] = None
|
|
12
|
+
expiration: Optional[datetime] = None
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Meta(BaseModel):
|
|
16
|
+
authorization: Optional[Authorization] = None
|
|
17
|
+
timestamp: datetime
|
|
18
|
+
correlation_id: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class HttpMeta(Meta):
|
|
22
|
+
ip: str
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class AsyncMeta(Meta):
|
|
26
|
+
topic: str
|
|
27
|
+
subtopic: Optional[str] = None
|
|
28
|
+
produced_at: Optional[datetime] = None
|
|
29
|
+
consumed_at: Optional[datetime] = None
|
|
30
|
+
retry_count: int = 0
|
|
@@ -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
|
)
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
from typing import Dict
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
from decimal import Decimal
|
|
4
|
-
from uuid import UUID
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def parse_message_attributes(attributes: Dict) -> Dict:
|
|
8
|
-
message_attributes = {}
|
|
9
|
-
if not attributes:
|
|
10
|
-
return message_attributes
|
|
11
|
-
for key, value in attributes.items():
|
|
12
|
-
if value['Type'] == 'String':
|
|
13
|
-
message_attributes[key] = value['Value']
|
|
14
|
-
elif value['Type'] == 'Number':
|
|
15
|
-
message_attributes[key] = int(value['Value'])
|
|
16
|
-
elif value['Type'] == 'Binary':
|
|
17
|
-
message_attributes[key] = bytes(value['Value'], 'utf-8')
|
|
18
|
-
return message_attributes
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def to_message_attributes(attributes: Dict) -> Dict:
|
|
22
|
-
att_dict = {}
|
|
23
|
-
for key, value in attributes.items():
|
|
24
|
-
if isinstance(value, str):
|
|
25
|
-
att_dict[key] = {
|
|
26
|
-
'DataType': 'String', 'StringValue': value}
|
|
27
|
-
elif isinstance(value, Decimal):
|
|
28
|
-
att_dict[key] = {
|
|
29
|
-
'DataType': 'Number', 'StringValue': str(value)}
|
|
30
|
-
elif isinstance(value, UUID):
|
|
31
|
-
att_dict[key] = {
|
|
32
|
-
'DataType': 'String', 'StringValue': str(value)}
|
|
33
|
-
elif isinstance(value, datetime):
|
|
34
|
-
att_dict[key] = {
|
|
35
|
-
'DataType': 'String', 'StringValue': value.isoformat()}
|
|
36
|
-
elif isinstance(value, int):
|
|
37
|
-
att_dict[key] = {
|
|
38
|
-
'DataType': 'Number', 'StringValue': str(value)}
|
|
39
|
-
elif isinstance(value, bytes):
|
|
40
|
-
att_dict[key] = {
|
|
41
|
-
'DataType': 'Binary', 'BinaryValue': value}
|
|
42
|
-
return att_dict
|
|
File without changes
|
|
File without changes
|
|
File without changes
|