From e0fb82613a6efd284b7bbd728a0b4cd28c7f63eb70d251da761bd9895765e176 Mon Sep 17 00:00:00 2001 From: tlg Date: Thu, 9 Jul 2026 13:53:29 +0200 Subject: [PATCH] fix(projekt-matching): idempotent langflow api-key creation Co-Authored-By: Claude Fable 5 --- projekt-matching/deploy/build_flows.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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()