fix(projekt-matching): idempotent langflow api-key creation

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tlg
2026-07-09 13:53:29 +02:00
parent e1be3ff17e
commit e0fb82613a

View File

@@ -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()