Skip to content

Commit

Permalink
Allow all origins in safeapi.
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislavsulc committed Jun 4, 2024
1 parent 81737e2 commit 0f2c883
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions mupifDB/api/safeapi.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import fastapi
from fastapi.middleware.cors import CORSMiddleware
import pymongo
import Pyro5.api
import mupif as mp
import os

app = fastapi.FastAPI(openapi_tags=[{'name':'Stats'}])
app = fastapi.FastAPI(openapi_tags=[{'name': 'Stats'}])

mongoClient = pymongo.MongoClient("mongodb://localhost:27017")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

mongoClient = pymongo.MongoClient("mongodb://localhost:27017")


@app.get("/status2/", tags=["Stats"])
def get_status2():
ns = None
try:
ns = mp.pyroutil.connectNameserver();
ns = mp.pyroutil.connectNameserver()
nameserverStatus = 'OK'
except:
nameserverStatus = 'Failed'
Expand All @@ -31,33 +39,37 @@ def get_status2():
print(str(e))

# get DMS status
if mongoClient: DMSStatus = 'OK'
else: DMSStatus = 'Failed'
if mongoClient:
DMSStatus = 'OK'
else:
DMSStatus = 'Failed'

return {'nameserver': nameserverStatus, 'dms': DMSStatus, 'scheduler': schedulerStatus, 'name':os.environ["MUPIF_VPN_NAME"]}
return {'nameserver': nameserverStatus, 'dms': DMSStatus, 'scheduler': schedulerStatus, 'name': os.environ["MUPIF_VPN_NAME"]}


@app.get("/scheduler-status2/", tags=["Stats"])
def get_scheduler_status2():
ns = mp.pyroutil.connectNameserver();
ns = mp.pyroutil.connectNameserver()
return mp.monitor.schedulerInfo(ns)


@app.get("/ns-status2/", tags=["Stats"])
def get_ns_status2():
ns = mp.pyroutil.connectNameserver();
ns = mp.pyroutil.connectNameserver()
return mp.monitor.nsInfo(ns)


@app.get("/vpn-status2/", tags=["Stats"])
def get_vpn_status2():
return mp.monitor.vpnInfo(hidePriv=False)


@app.get("/jobmans-status2/", tags=["Stats"])
def get_jobmans_status2():
ns = mp.pyroutil.connectNameserver();
ns = mp.pyroutil.connectNameserver()
return mp.monitor.jobmanInfo(ns)


if __name__ == '__main__':
import uvicorn
uvicorn.run('safeapi:app', host='0.0.0.0', port=8081, reload=True)

0 comments on commit 0f2c883

Please sign in to comment.