This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
92 lines (82 loc) · 2.45 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Query Logger Backend Server."""
import httpx
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
import uvicorn
APP = FastAPI(
title="ARS Query Logger",
description="ARS Query Logs for the last 24 hours",
version="1.0.3",
translator_teams=["SRI"],
contact={
"name": "Max Wang",
"email": "[email protected]",
"x-id": "maximusunc",
"x-role": "responsible developer",
},
)
@APP.get("/api/ars")
async def get_ars_urls():
"""GET list of ARS urls for each environment."""
ars_urls = []
try:
async with httpx.AsyncClient(timeout=10) as client:
response = await client.get("https://smart-api.info/api/query?q=4c12efd48ced755ac4b72b1922202ec2")
response = response.json()
for hit in response["hits"]:
for server in hit["servers"]:
ars_urls.append(server)
except Exception as e:
print(e)
return ars_urls
@APP.get("/api/logs")
async def get_logs(ars_url: str, ara: str):
"""GET the ARS log of all queries in the last 24 hours for a specific ARA."""
async with httpx.AsyncClient(timeout=60) as client:
url = f"{ars_url}/ars/api/reports/{ara}"
response = await client.get(
url=url,
)
return response.json()
@APP.get("/api/actors")
async def get_aras(ars_url: str):
"""
Get list of aras by ars actor.
Example actor:
{
"model": "tr_ars.actor",
"pk": 1,
"fields": {
"name": "ara-aragorn-runquery",
"channel": [
"general",
"workflow"
],
"agent": "ara-aragorn",
"urlRemote": "https://aragorn.renci.org/aragorn/asyncquery",
"path": "http://ars-dev.transltr.io/ara-aragorn/api/runquery",
"active": true
}
}
"""
actors = []
try:
async with httpx.AsyncClient(timeout=10) as client:
response = await client.get(f"{ars_url}/ars/api/actors")
response = response.json()
for actor in response:
# loop through all actors and send back all active ones
if actor["fields"]["active"]:
infores = actor["fields"].get("inforesid")
if infores:
actors.append(infores.split("infores:")[1])
else:
actors.append(actor["fields"]["agent"].split("-", 1)[1])
except Exception as e:
print(e)
# return only unique inforeses
return list(set(actors))
# servers UI
APP.mount("/", StaticFiles(directory="ui/build", html=True), name="ui")
if __name__ == "__main__":
uvicorn.run("server:APP", port=9734, reload=True)