Skip to content

Commit

Permalink
feat(main.py): Store events in eventhistory collection
Browse files Browse the repository at this point in the history
Any event must be stored to eventhistory collection

Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed Oct 29, 2024
1 parent 3d6c00a commit 742bba0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
PublishEvent,
parse_node_obj,
KernelVersion,
EventHistory,
)
from .auth import Authentication
from .db import Database
Expand Down Expand Up @@ -486,6 +487,13 @@ async def delete_group(group_id: str,

await db.delete_by_id(UserGroup, group_id)

# -----------------------------------------------------------------------------
# EventHistory
def _get_eventhistory(evdict):

Check warning on line 492 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

expected 2 blank lines, found 1
"""Get EventHistory object from dictionary"""
evhist = EventHistory()
evhist.data = evdict
return evhist

# -----------------------------------------------------------------------------
# Nodes
Expand Down Expand Up @@ -650,6 +658,8 @@ async def post_node(node: Node,
if data.get('owner', None):
attributes['owner'] = data['owner']
await pubsub.publish_cloudevent('node', data, attributes)
evhist = _get_eventhistory(data)
await db.create(evhist)
return obj


Expand Down Expand Up @@ -695,6 +705,8 @@ async def put_node(node_id: str, node: Node,
if data.get('owner', None):
attributes['owner'] = data['owner']
await pubsub.publish_cloudevent('node', data, attributes)
evhist = _get_eventhistory(data)
await db.create(evhist)
return obj


Expand Down Expand Up @@ -735,6 +747,8 @@ async def put_nodes(
if data.get('owner', None):
attributes['owner'] = data['owner']
await pubsub.publish_cloudevent('node', data, attributes)
evhist = _get_eventhistory(data)
await db.create(evhist)
return obj_list


Expand Down

0 comments on commit 742bba0

Please sign in to comment.