Skip to content

Commit 595b494

Browse files
committed
Fiw swagger ui authentication.
1 parent be2df54 commit 595b494

File tree

1 file changed

+27
-1
lines changed
  • usr/lib/python3/dist-packages/linuxmusterApi

1 file changed

+27
-1
lines changed

usr/lib/python3/dist-packages/linuxmusterApi/main.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from fastapi.responses import HTMLResponse, FileResponse
1212
from fastapi.middleware.cors import CORSMiddleware
1313
from fastapi.staticfiles import StaticFiles
14+
from fastapi.openapi.utils import get_openapi
1415

1516

1617
config = {}
@@ -37,7 +38,7 @@
3738

3839
app = FastAPI(
3940
title = "Linuxmuster.net API",
40-
version="7.2.21",
41+
version="7.3.12",
4142
description = description,
4243
swagger_ui_parameters = {"tryItOutEnabled": True, "swagger_favicon_url": "/static/favicon.png"},
4344
license_info={
@@ -124,6 +125,31 @@ def home():
124125
app.include_router(printers.router, prefix="/v1")
125126
app.include_router(server.router, prefix="/v1")
126127

128+
def custom_openapi():
129+
if app.openapi_schema:
130+
return app.openapi_schema
131+
openapi_schema = get_openapi(
132+
title = "Linuxmuster.net API",
133+
version = "7.3.13",
134+
summary = "Linuxmuster.net API",
135+
description = description,
136+
routes=app.routes,
137+
)
138+
openapi_schema["components"]["securitySchemes"] = {
139+
'HTTPBasic': {'type': 'http', 'scheme': 'basic'},
140+
'ApiKeyUserAuth': {'type': 'apiKey', 'in': 'header', 'name': 'X-API-Key'},
141+
'ApiKeyHostAuth': {'type': 'apiKey', 'in': 'header', 'name': 'X-HOST-Key'},
142+
}
143+
for path, details in openapi_schema["paths"].items():
144+
if path != '/v1/auth/' and path != '/':
145+
for method in details.keys():
146+
details[method]['security'] = [{'ApiKeyUserAuth': [], 'ApiKeyHostAuth': []}]
147+
148+
app.openapi_schema = openapi_schema
149+
return app.openapi_schema
150+
151+
app.openapi = custom_openapi
152+
127153
if __name__ == "__main__":
128154
secret = config.get('secret', None)
129155
if not secret:

0 commit comments

Comments
 (0)