From 297f4b0adf378fb50f34e1cd70d4dbb5dc8f4c40 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 5 Nov 2026 16:26:29 +0500 Subject: [PATCH] =?UTF-8?q?uralkal:=20zitadel-action=20=E2=80=94=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20403=20=D0=BD=D0=B0=20admin=20API=20=D0=B1=D0=B5?= =?UTF-8?q?=D1=80=D1=91=D1=82=20=D0=BE=D1=80=D0=B3=D0=B0=D0=BD=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8E=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20/management/v1/orgs/me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uralkal/zitadel-action-configmap.yaml | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/apps/django/uralkal/zitadel-action-configmap.yaml b/apps/django/uralkal/zitadel-action-configmap.yaml index 64660dc..daadca5 100644 --- a/apps/django/uralkal/zitadel-action-configmap.yaml +++ b/apps/django/uralkal/zitadel-action-configmap.yaml @@ -77,20 +77,34 @@ data: client = httpx.Client(base_url=ZITADEL, headers=HEADERS, timeout=30) - def call(method, path, body=None, org_id=None): + def call(method, path, body=None, org_id=None, allow=()): headers = {"x-zitadel-orgid": org_id} if org_id else {} r = client.request(method, path, json=body, headers=headers) + if r.status_code in allow: + return None if r.status_code >= 300: print(f"{method} {path} -> {r.status_code}: {r.text}") sys.exit(1) return r.json() if r.content else {} - orgs = call("POST", "/admin/v1/orgs/_search", {"queries": []}).get("result", []) - org = next((o for o in orgs if o.get("name", "").lower() == ORG_NAME.lower()), None) - if org is None: - print(f"org '{ORG_NAME}' not found, available: {[o.get('name') for o in orgs]}") - sys.exit(1) + me = call("GET", "/auth/v1/users/me")["user"] + print(f"token user {me.get('userName')} id={me.get('id')}") + + org = None + found_orgs = call("POST", "/admin/v1/orgs/_search", {"queries": []}, allow=(403,)) + if found_orgs is not None: + orgs = found_orgs.get("result", []) + org = next((o for o in orgs if o.get("name", "").lower() == ORG_NAME.lower()), None) + if org is None: + print(f"org '{ORG_NAME}' not found, available: {[o.get('name') for o in orgs]}") + sys.exit(1) + else: + org = call("GET", "/management/v1/orgs/me")["org"] + print(f"no instance permissions, using token org '{org.get('name')}'") + if org.get("name", "").lower() != ORG_NAME.lower(): + print(f"token org is '{org.get('name')}', not '{ORG_NAME}'") + sys.exit(1) org_id = org["id"] print(f"org {org['name']} id={org_id}")