From bc8b0288ca8f8a31d195003d4d0b5c9331dd577c Mon Sep 17 00:00:00 2001 From: Ida Date: Wed, 20 May 2026 16:43:17 +0200 Subject: [PATCH] fix: tests on github --- .github/scripts/load_config_key_from_azure.py | 74 +++++++++++++++++++ .github/workflows/int_gateway-int.yml | 13 +--- .github/workflows/main_gateway-prod.yml | 19 +---- 3 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 .github/scripts/load_config_key_from_azure.py diff --git a/.github/scripts/load_config_key_from_azure.py b/.github/scripts/load_config_key_from_azure.py new file mode 100644 index 00000000..08da7be4 --- /dev/null +++ b/.github/scripts/load_config_key_from_azure.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# Copyright (c) 2026 Patrick Motsch +"""Load CONFIG_KEY from Azure App Service for CI pytest (Kudu API + publish profile).""" +from __future__ import annotations + +import base64 +import json +import os +import sys +import urllib.request +import xml.etree.ElementTree as ET + + +def main() -> None: + profile_xml = os.environ.get("AZURE_PUBLISH_PROFILE") + setting_name = os.environ.get("SETTING_NAME", "CONFIG_KEY") + if not profile_xml: + print("::error::AZURE_PUBLISH_PROFILE is not set", file=sys.stderr) + sys.exit(1) + + root = ET.fromstring(profile_xml) + pub = None + for element in root.findall(".//publishProfile"): + url = (element.get("publishUrl") or "").lower() + if "scm" in url: + pub = element + break + if pub is None: + pub = root.find(".//publishProfile") + if pub is None: + print("::error::No publishProfile in publish profile XML", file=sys.stderr) + sys.exit(1) + + host = (pub.get("publishUrl") or "").split(":")[0] + user = pub.get("userName") + pwd = pub.get("userPWD") + if not (host and user and pwd): + print("::error::Could not parse SCM credentials from publish profile", file=sys.stderr) + sys.exit(1) + + api = f"https://{host}/api/settings" + req = urllib.request.Request(api) + cred = base64.b64encode(f"{user}:{pwd}".encode()).decode() + req.add_header("Authorization", f"Basic {cred}") + try: + with urllib.request.urlopen(req, timeout=60) as resp: + settings = json.load(resp) + except Exception as exc: + print(f"::error::Kudu settings request failed: {exc}", file=sys.stderr) + sys.exit(1) + + if not isinstance(settings, dict) or setting_name not in settings: + preview = sorted(settings.keys())[:25] if isinstance(settings, dict) else [] + print( + f"::error::{setting_name} not in Azure App Service application settings " + f"(sample keys: {preview})", + file=sys.stderr, + ) + sys.exit(1) + + value = settings[setting_name] + if not value or not str(value).strip(): + print(f"::error::{setting_name} is empty in Azure App Service", file=sys.stderr) + sys.exit(1) + + github_env = os.environ.get("GITHUB_ENV") + if github_env: + with open(github_env, "a", encoding="utf-8") as handle: + handle.write(f"{setting_name}<