forked from oscar.krause/fastapi-dls
created a simple management ui
This commit is contained in:
parent
2b7fed3381
commit
ed1b55f5f1
@ -25,6 +25,10 @@ Status endpoint, used for *healthcheck*. Shows also current version and commit h
|
||||
|
||||
OpenAPI specifications rendered from `GET /openapi.json`.
|
||||
|
||||
### `GET /-/manage`
|
||||
|
||||
Shows a very basic UI to delete origins or leases.
|
||||
|
||||
### `GET /-/origins?leases=false`
|
||||
|
||||
List registered origins.
|
||||
|
34
app/main.py
34
app/main.py
@ -75,6 +75,40 @@ async def status(request: Request):
|
||||
return JSONResponse({'status': 'up', 'version': VERSION, 'commit': COMMIT, 'debug': DEBUG})
|
||||
|
||||
|
||||
@app.get('/-/manage')
|
||||
async def _manage(request: Request):
|
||||
response = '''
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>FastAPI-DLS Management</title>
|
||||
</head>
|
||||
<body>
|
||||
<button onclick="deleteOrigins()">delete origins and their leases</button>
|
||||
<button onclick="deleteLease()">delete specific lease</button>
|
||||
|
||||
<script>
|
||||
function deleteOrigins() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("DELETE", '/-/origins', true);
|
||||
xhr.send();
|
||||
}
|
||||
function deleteLease(lease_ref) {
|
||||
if(lease_ref === undefined)
|
||||
lease_ref = window.prompt("Please enter 'lease_ref' which should be deleted");
|
||||
if(lease_ref === null || lease_ref === "")
|
||||
return
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("DELETE", `/-/lease/${lease_ref}`, true);
|
||||
xhr.send();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
'''
|
||||
return HTMLResponse(response)
|
||||
|
||||
|
||||
@app.get('/-/origins')
|
||||
async def _origins(request: Request, leases: bool = False):
|
||||
session = sessionmaker(bind=db)()
|
||||
|
Loading…
Reference in New Issue
Block a user