mirror of
https://github.com/zvx-echo6/navi.git
synced 2026-08-26 17:31:37 +00:00
PR-A of the 2-PR whoami migration. Net-new, additive endpoint in navi-admin
matching recon's existing handler shape exactly. Recon's handler stays live in
this PR; once nginx routes /api/auth/whoami to :8427 (out-of-band) and recon's
handler is removed (PR-B), navi-admin is the sole owner.
- New services/navi_admin/auth_route.py with its own blueprint (navi_admin_auth):
GET /api/auth/whoami reads X-Authentik-Username, returns {authenticated,
username}. NOT @require_auth — it's the "am I logged in?" check, must answer
the unauthenticated case (mirrors recon).
- app.py: register the new blueprint (2 lines).
- test_auth.py: header-present + header-absent cases.
Kept in its own blueprint/file so admin_route.py's "all routes @require_auth"
invariant stays true. recon and nginx untouched (additive only).
Co-authored-by: Matt Johnson <mj@k7zvx.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40 lines
976 B
Python
40 lines
976 B
Python
"""navi-admin Flask application factory + gunicorn entry.
|
|
|
|
Gunicorn entry:
|
|
gunicorn 'services.navi_admin.app:create_app()' --bind 127.0.0.1:8427 --workers 2
|
|
"""
|
|
import time
|
|
|
|
from flask import Flask
|
|
|
|
from shared.git_sha import git_short_sha
|
|
|
|
from . import admin_route
|
|
from . import auth_route
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
|
|
app.config['VERSION'] = git_short_sha()
|
|
app.config['METRICS'] = {
|
|
'start_time': time.time(),
|
|
'request_count': 0,
|
|
'last_error_at': None,
|
|
}
|
|
|
|
@app.before_request
|
|
def _count_request():
|
|
app.config['METRICS']['request_count'] += 1
|
|
|
|
@app.after_request
|
|
def _track_errors(response):
|
|
if response.status_code >= 500:
|
|
app.config['METRICS']['last_error_at'] = time.strftime(
|
|
'%Y-%m-%dT%H:%M:%SZ', time.gmtime()
|
|
)
|
|
return response
|
|
|
|
app.register_blueprint(admin_route.bp)
|
|
app.register_blueprint(auth_route.bp)
|
|
return app
|