my-aws-helpers 2.0.0__tar.gz → 2.2.0__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.
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/PKG-INFO +1 -1
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers/dynamo.py +12 -13
- my_aws_helpers-2.2.0/my_aws_helpers/event.py +73 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers.egg-info/PKG-INFO +1 -1
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers.egg-info/SOURCES.txt +3 -1
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/setup.py +1 -1
- my_aws_helpers-2.2.0/tests/test_event.py +23 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/README.md +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers/api.py +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers/auth.py +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers/cognito.py +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers/errors.py +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers/logging.py +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers/s3.py +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers/sfn.py +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers.egg-info/dependency_links.txt +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers.egg-info/requires.txt +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers.egg-info/top_level.txt +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/my_aws_helpers.egg-info/zip-safe +0 -0
- {my_aws_helpers-2.0.0 → my_aws_helpers-2.2.0}/setup.cfg +0 -0
|
@@ -41,31 +41,31 @@ class MetaData:
|
|
|
41
41
|
return ""
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
class BaseTableObject
|
|
44
|
+
class BaseTableObject:
|
|
45
45
|
"""
|
|
46
46
|
An Abstract class that helps ensure your objects
|
|
47
47
|
conform to the AssetTable schema and
|
|
48
48
|
implement serialisation/deserialisation for Dynamo
|
|
49
49
|
"""
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
sk: str
|
|
53
|
-
|
|
51
|
+
@abstractmethod
|
|
54
52
|
def _get_pk(self):
|
|
55
|
-
|
|
53
|
+
raise NotImplementedError()
|
|
56
54
|
|
|
55
|
+
@abstractmethod
|
|
57
56
|
def _get_sk(self):
|
|
58
|
-
|
|
57
|
+
raise NotImplementedError()
|
|
59
58
|
|
|
60
|
-
@
|
|
61
|
-
|
|
59
|
+
@classmethod
|
|
60
|
+
@abstractmethod
|
|
61
|
+
def _from_dynamo_representation(cls):
|
|
62
62
|
"""
|
|
63
63
|
Deserialises this object from Dynamo Representation
|
|
64
64
|
"""
|
|
65
65
|
pass
|
|
66
66
|
|
|
67
67
|
@abstractmethod
|
|
68
|
-
def _to_dynamo_representation():
|
|
68
|
+
def _to_dynamo_representation(self):
|
|
69
69
|
"""
|
|
70
70
|
Serialises this object to Dynamo Representation
|
|
71
71
|
"""
|
|
@@ -74,10 +74,9 @@ class BaseTableObject(MetaData):
|
|
|
74
74
|
def _optional_get(self, kwargs: dict, key: str, default: Any):
|
|
75
75
|
return kwargs.get(key) if kwargs.get(key) else default
|
|
76
76
|
|
|
77
|
-
def __init__(self
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
self.sk = self._optional_get(kwargs=kwargs, key="sk", default=self._get_sk())
|
|
77
|
+
def __init__(self) -> None:
|
|
78
|
+
pass
|
|
79
|
+
|
|
81
80
|
|
|
82
81
|
|
|
83
82
|
class DynamoSerialiser:
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from my_aws_helpers.dynamo import BaseTableObject, DynamoSerialiser
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from uuid import uuid4
|
|
6
|
+
from copy import copy
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class EventDynamoKeys:
|
|
10
|
+
@staticmethod
|
|
11
|
+
def get_event_pk(id: str):
|
|
12
|
+
return f"id##{id}"
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def get_event_sk(id: str):
|
|
16
|
+
return f"id##{id}"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class EventStatus(str, Enum):
|
|
20
|
+
in_progress = "in_progress"
|
|
21
|
+
success = "success"
|
|
22
|
+
fail = "fail"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Event(BaseTableObject):
|
|
26
|
+
status: str
|
|
27
|
+
message: str
|
|
28
|
+
id: str
|
|
29
|
+
created_timestamp: datetime
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
status: str,
|
|
34
|
+
message: str,
|
|
35
|
+
id: str = None,
|
|
36
|
+
created_timestamp: datetime = None,
|
|
37
|
+
):
|
|
38
|
+
super().__init__()
|
|
39
|
+
self.status: str = self.set_status(status=status)
|
|
40
|
+
self.message: str = message
|
|
41
|
+
self.id: str = id if id else uuid4().hex
|
|
42
|
+
self.created_timestamp: datetime = created_timestamp if created_timestamp else datetime.now()
|
|
43
|
+
|
|
44
|
+
def set_status(self, status: str) -> str:
|
|
45
|
+
if status not in list(EventStatus):
|
|
46
|
+
raise Exception("Status must be a member of EventStatus")
|
|
47
|
+
return status
|
|
48
|
+
|
|
49
|
+
def _get_pk(self):
|
|
50
|
+
return EventDynamoKeys.get_event_pk(self.id)
|
|
51
|
+
|
|
52
|
+
def _get_sk(self):
|
|
53
|
+
return EventDynamoKeys.get_event_sk(self.id)
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def _from_dynamo_representation(cls, obj: dict):
|
|
57
|
+
"""
|
|
58
|
+
Deserialises this object from Dynamo Representation
|
|
59
|
+
"""
|
|
60
|
+
this_obj = copy(obj)
|
|
61
|
+
this_obj.pop('pk')
|
|
62
|
+
this_obj.pop('sk')
|
|
63
|
+
return cls(**this_obj)
|
|
64
|
+
|
|
65
|
+
def _to_dynamo_representation(self):
|
|
66
|
+
"""
|
|
67
|
+
Serialises this object to Dynamo Representation
|
|
68
|
+
"""
|
|
69
|
+
obj = copy(vars(self))
|
|
70
|
+
obj['pk'] = self._get_pk()
|
|
71
|
+
obj['sk'] = self._get_sk()
|
|
72
|
+
return DynamoSerialiser.object_serialiser(obj=obj)
|
|
73
|
+
|
|
@@ -6,6 +6,7 @@ my_aws_helpers/auth.py
|
|
|
6
6
|
my_aws_helpers/cognito.py
|
|
7
7
|
my_aws_helpers/dynamo.py
|
|
8
8
|
my_aws_helpers/errors.py
|
|
9
|
+
my_aws_helpers/event.py
|
|
9
10
|
my_aws_helpers/logging.py
|
|
10
11
|
my_aws_helpers/s3.py
|
|
11
12
|
my_aws_helpers/sfn.py
|
|
@@ -14,4 +15,5 @@ my_aws_helpers.egg-info/SOURCES.txt
|
|
|
14
15
|
my_aws_helpers.egg-info/dependency_links.txt
|
|
15
16
|
my_aws_helpers.egg-info/requires.txt
|
|
16
17
|
my_aws_helpers.egg-info/top_level.txt
|
|
17
|
-
my_aws_helpers.egg-info/zip-safe
|
|
18
|
+
my_aws_helpers.egg-info/zip-safe
|
|
19
|
+
tests/test_event.py
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from my_aws_helpers.event import Event, EventStatus
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_event():
|
|
6
|
+
event = Event(status=EventStatus.success.value, message="test event")
|
|
7
|
+
assert event != None
|
|
8
|
+
|
|
9
|
+
def test_event_wrong_status():
|
|
10
|
+
with pytest.raises(Exception):
|
|
11
|
+
Event(status="not success", message="test event")
|
|
12
|
+
|
|
13
|
+
def test_serialiser():
|
|
14
|
+
event = Event(status=EventStatus.success.value, message="test event")
|
|
15
|
+
dynamo_repr = event._to_dynamo_representation()
|
|
16
|
+
|
|
17
|
+
assert dynamo_repr['pk'] == f"id##{event.id}"
|
|
18
|
+
assert dynamo_repr['sk'] == f"id##{event.id}"
|
|
19
|
+
|
|
20
|
+
obj = Event._from_dynamo_representation(obj = dynamo_repr)
|
|
21
|
+
|
|
22
|
+
assert isinstance(obj, Event) == True
|
|
23
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|