created a simple management ui

This commit is contained in:
Oscar Krause 2022-12-29 10:12:31 +01:00
parent 2b7fed3381
commit ed1b55f5f1
2 changed files with 38 additions and 0 deletions

View File

@ -25,6 +25,10 @@ Status endpoint, used for *healthcheck*. Shows also current version and commit h
OpenAPI specifications rendered from `GET /openapi.json`. OpenAPI specifications rendered from `GET /openapi.json`.
### `GET /-/manage`
Shows a very basic UI to delete origins or leases.
### `GET /-/origins?leases=false` ### `GET /-/origins?leases=false`
List registered origins. List registered origins.

View File

@ -75,6 +75,40 @@ async def status(request: Request):
return JSONResponse({'status': 'up', 'version': VERSION, 'commit': COMMIT, 'debug': DEBUG}) 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') @app.get('/-/origins')
async def _origins(request: Request, leases: bool = False): async def _origins(request: Request, leases: bool = False):
session = sessionmaker(bind=db)() session = sessionmaker(bind=db)()