diff --git a/projekt-matching/deploy/build_flows.py b/projekt-matching/deploy/build_flows.py index 391e488..bcd190c 100644 --- a/projekt-matching/deploy/build_flows.py +++ b/projekt-matching/deploy/build_flows.py @@ -79,6 +79,20 @@ def upsert_variable(hdr, name, value, vtype): def get_api_key(hdr): + # Idempotent delete+recreate: the key VALUE is only returned at creation + # time, so reuse is impossible -- instead remove any previous + # "projekt-matching" keys (each earlier run left one behind otherwise) + # and mint a fresh one. Callers then refresh both the env file and the + # PM_LANGFLOW_API_KEY Credential variable, so nothing still references + # the deleted keys. Live API shape (Langflow 1.10.0): GET /api_key/ + # returns {"total_count", "user_id", "api_keys": [{"id", "name", ...}]}; + # DELETE /api_key/{id} removes one key. + r = requests.get(f"{BASE}/api_key/", headers=hdr, timeout=15) + r.raise_for_status() + for key in r.json().get("api_keys", []): + if key["name"] == "projekt-matching": + requests.delete(f"{BASE}/api_key/{key['id']}", headers=hdr, + timeout=15).raise_for_status() r = requests.post(f"{BASE}/api_key/", headers=hdr, json={"name": "projekt-matching"}, timeout=15) r.raise_for_status()