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 30, 2024
1 parent 1c2dc13 commit b0956ec
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 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 @@ -487,6 +488,15 @@ async def delete_group(group_id: str,
await db.delete_by_id(UserGroup, group_id)


# -----------------------------------------------------------------------------
# EventHistory
def _get_eventhistory(evdict):
"""Get EventHistory object from dictionary"""
evhist = EventHistory()
evhist.data = evdict
return evhist


# -----------------------------------------------------------------------------
# Nodes

Expand Down Expand Up @@ -676,6 +686,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 @@ -721,6 +733,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 @@ -761,6 +775,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 b0956ec

Please sign in to comment.