Skip to content

Commit

Permalink
feat(main.py): Add events endpoint
Browse files Browse the repository at this point in the history
Add initial implementation of events endpoint

Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
  • Loading branch information
nuclearcat committed Oct 30, 2024
1 parent 7c0b59a commit 4ef8b8d
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,46 @@ def _get_eventhistory(evdict):
return evhist


# TBD: Restrict response by Pydantic model
@app.get('/events')
async def get_events(request: Request):
"""Get all the events if no request parameters have passed.
Format: [{event1}, {event2}, ...] or if recursive is set to true,
then we add to each event the node information.
Get all the matching events otherwise.
Query parameters can be used to filter the events:
- limit: Number of events to return
- from: Start timestamp (unix epoch) to filter events
- kind: Event kind to filter events
- recursive: Retrieve node together with event
This API endpoint is under development and may change in future.
"""
metrics.add('http_requests_total', 1)
query_params = dict(request.query_params)
recursive = query_params.pop('recursive', None)

Check warning on line 517 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unused variable 'recursive'
limit = query_params.pop('limit', None)
kind = query_params.pop('kind', None)
from_ts = query_params.pop('from', None)
if from_ts:
query_params['timestamp'] = {'$gte': int(from_ts)}
if kind:
query_params['data.kind'] = kind
if limit:
query_params['limit'] = int(limit)
# if parameter test present - return empty response
#print(query_params)

Check warning on line 528 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

block comment should start with '# '
#resp = await db.find_by_attributes(EventHistory, query_params)

Check warning on line 529 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

block comment should start with '# '
#print(resp)

Check warning on line 530 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

block comment should start with '# '
#if recursive:

Check warning on line 531 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

block comment should start with '# '
# for item in resp.items:
# node = await db.find_by_id(Node, item['data']['id'])
# item['node'] = node

Check warning on line 534 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Trailing whitespace

Check warning on line 534 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

trailing whitespace
#return JSONResponse(content=resp)

Check warning on line 535 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

block comment should start with '# '
return JSONResponse(content={})


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

def _get_node_event_data(operation, node, is_hierarchy=False):
return {
'op': operation,
Expand Down

0 comments on commit 4ef8b8d

Please sign in to comment.