perf(npm): cache NPM JWT instead of re-authenticating on every API call

Every NPM helper (proxy host create/update/delete, streams, certs) did a
fresh POST /api/tokens login before its actual request, adding an avoidable
round-trip to every proxy/stream operation.

- Cache the JWT per (api_url, email), sized from its 'exp' claim
- Transparently re-authenticate and retry once on a 401 (e.g. after an NPM
  restart invalidates a cached token), so a stale cache entry can't cause a
  hard failure

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
2026-07-23 14:51:23 +02:00
co-authored by Claude Sonnet 5
parent ac843da4ca
commit c5189d88fe
2 changed files with 91 additions and 17 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ logger = logging.getLogger(__name__)
app = FastAPI(
title="NetBird MSP Appliance",
description="Multi-tenant NetBird management platform for MSPs",
version="1.1.0",
version="1.1.1",
docs_url="/api/docs",
redoc_url="/api/redoc",
openapi_url="/api/openapi.json",