From 742bba032f7ec4690819f9643846c12adb9034d6 Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Tue, 29 Oct 2024 14:25:30 +0200 Subject: [PATCH] feat(main.py): Store events in eventhistory collection Any event must be stored to eventhistory collection Signed-off-by: Denys Fedoryshchenko --- api/main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api/main.py b/api/main.py index 762beda7..c46d0723 100644 --- a/api/main.py +++ b/api/main.py @@ -37,6 +37,7 @@ PublishEvent, parse_node_obj, KernelVersion, + EventHistory, ) from .auth import Authentication from .db import Database @@ -486,6 +487,13 @@ 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 @@ -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 @@ -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 @@ -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