Add global settings endpoint (#52)
* backend: - add /api/settings endpoint for misc system-wide settings - setting 'registrationEnabled' if open registration should be enabled, set via REGISTRATION_ENABLED=1 env var - setting 'jwtTokenLifetimeMinutes' returns the jwt token expiry in seconds, configured in minutes via JWT_TOKEN_LIFETIME_MINUTES env var (default: 60)
This commit is contained in:
parent
05c1129fb8
commit
11b797d535
@ -10,7 +10,7 @@ from fastapi import FastAPI
|
|||||||
from db import init_db
|
from db import init_db
|
||||||
|
|
||||||
from emailsender import EmailSender
|
from emailsender import EmailSender
|
||||||
from users import init_users_api, init_user_manager
|
from users import init_users_api, init_user_manager, JWT_TOKEN_LIFETIME
|
||||||
from archives import init_archives_api
|
from archives import init_archives_api
|
||||||
|
|
||||||
from storages import init_storages_api
|
from storages import init_storages_api
|
||||||
@ -30,6 +30,11 @@ def main():
|
|||||||
|
|
||||||
mdb = init_db()
|
mdb = init_db()
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
"registrationEnabled": os.environ.get("REGISTRATION_ENABLED") == "1",
|
||||||
|
"jwtTokenLifetime": JWT_TOKEN_LIFETIME
|
||||||
|
}
|
||||||
|
|
||||||
user_manager = init_user_manager(mdb, email)
|
user_manager = init_user_manager(mdb, email)
|
||||||
|
|
||||||
fastapi_users = init_users_api(app, user_manager)
|
fastapi_users = init_users_api(app, user_manager)
|
||||||
@ -74,6 +79,10 @@ def main():
|
|||||||
|
|
||||||
app.include_router(archive_ops.router)
|
app.include_router(archive_ops.router)
|
||||||
|
|
||||||
|
@app.get("/api/settings")
|
||||||
|
async def get_settings():
|
||||||
|
return settings
|
||||||
|
|
||||||
@app.get("/healthz")
|
@app.get("/healthz")
|
||||||
async def healthz():
|
async def healthz():
|
||||||
return {}
|
return {}
|
||||||
|
@ -23,7 +23,7 @@ from fastapi_users.db import MongoDBUserDatabase
|
|||||||
# ============================================================================
|
# ============================================================================
|
||||||
PASSWORD_SECRET = os.environ.get("PASSWORD_SECRET", uuid.uuid4().hex)
|
PASSWORD_SECRET = os.environ.get("PASSWORD_SECRET", uuid.uuid4().hex)
|
||||||
|
|
||||||
JWT_LIFETIME = int(os.environ.get("JWT_LIFETIME", 3600))
|
JWT_TOKEN_LIFETIME = int(os.environ.get("JWT_TOKEN_LIFETIME_MINUTES", 60)) * 60
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@ -185,7 +185,7 @@ def init_users_api(app, user_manager):
|
|||||||
""" init fastapi_users """
|
""" init fastapi_users """
|
||||||
jwt_authentication = JWTAuthentication(
|
jwt_authentication = JWTAuthentication(
|
||||||
secret=PASSWORD_SECRET,
|
secret=PASSWORD_SECRET,
|
||||||
lifetime_seconds=JWT_LIFETIME,
|
lifetime_seconds=JWT_TOKEN_LIFETIME,
|
||||||
tokenUrl="/auth/jwt/login",
|
tokenUrl="/auth/jwt/login",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,6 +23,11 @@ data:
|
|||||||
|
|
||||||
NO_DELETE_JOBS: "{{ .Values.no_delete_jobs | default '0' }}"
|
NO_DELETE_JOBS: "{{ .Values.no_delete_jobs | default '0' }}"
|
||||||
|
|
||||||
|
REGISTRATION_ENABLED: "{{ .Values.registration_enabled | default '0' }}"
|
||||||
|
|
||||||
|
JWT_TOKEN_LIFETIME_MINUTES: "{{ .Values.jwt_token_lifetime_minutes | default '60' }}"
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
|
# Settings
|
||||||
|
# =========================================
|
||||||
name: browsertrix-cloud
|
name: browsertrix-cloud
|
||||||
|
|
||||||
|
registration_enabled: 1
|
||||||
|
jwt_token_lifetime_minutes: 60
|
||||||
|
|
||||||
|
|
||||||
# API Image
|
# API Image
|
||||||
# =========================================
|
# =========================================
|
||||||
api_image: "webrecorder/browsertrix-api"
|
api_image: "webrecorder/browsertrix-api"
|
||||||
|
@ -29,3 +29,8 @@ CRAWLER_IMAGE=webrecorder/browsertrix-crawler
|
|||||||
|
|
||||||
CRAWL_ARGS="--timeout 90 --logging stats,behaviors,debug --generateWACZ --screencastPort 9037"
|
CRAWL_ARGS="--timeout 90 --logging stats,behaviors,debug --generateWACZ --screencastPort 9037"
|
||||||
|
|
||||||
|
REGISTRATION_ENABLED=1
|
||||||
|
|
||||||
|
JWT_TOKEN_LIFETIME_MINUTES=60
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user