diff --git a/.github/workflows/azd-deploy.yml b/.github/workflows/azd-deploy.yml index da601d6..da0582d 100644 --- a/.github/workflows/azd-deploy.yml +++ b/.github/workflows/azd-deploy.yml @@ -1382,7 +1382,53 @@ jobs: fi done - policy_payload="$(ORIGINS_JSON="$TF_VAR_allowed_origins" python -c 'import json, os; origins=json.loads(os.environ["ORIGINS_JSON"]); origin_xml="".join(f" {origin}\\n" for origin in origins); xml=("\\n" " \\n" " \\n" " \\n" " \\n" " http://localhost:3000\\n" " http://localhost:5173\\n" f"{origin_xml}" " \\n" " \\n" " *\\n" " \\n" " \\n" "
*
\\n" "
\\n" "
\\n" "
\\n" " \\n" " \\n" " \\n" " \\n" " \\n" " \\n" " \\n" " \\n" " \\n" "
"); print(json.dumps({"properties": {"format": "rawxml", "value": xml}}))')" + policy_payload="$(ORIGINS_JSON="$TF_VAR_allowed_origins" python - <<'PY' + import json + import os + from xml.sax.saxutils import escape + + required_origins = [ + origin + for origin in json.loads(os.environ["ORIGINS_JSON"]) + if origin + ] + origins = [ + "http://localhost:3000", + "http://localhost:5173", + *required_origins, + ] + cors_xml = ( + '' + '' + + "".join(f"{escape(origin)}" for origin in origins) + + '' + '*' + '
*
' + '
' + ) + xml = "\n".join( + [ + "", + " ", + " ", + f" {cors_xml}", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + "", + ] + ) + "\n" + + print(json.dumps({"properties": {"format": "rawxml", "value": xml}})) + PY + )" az rest \ --method put \ --uri "https://management.azure.com/subscriptions/${ARM_SUBSCRIPTION_ID}/resourceGroups/${RG}/providers/Microsoft.ApiManagement/service/${APIM_NAME}/apis/${API_ID}/policies/policy?api-version=2022-08-01" \ @@ -2435,28 +2481,27 @@ jobs: for origin in json.loads(os.environ.get("REQUIRED_CORS_ORIGINS_JSON", "[]")) if origin ] - origin_lines = [ - " http://localhost:3000", - " http://localhost:5173", - *[f" {escape(origin)}" for origin in required_origins], + origins = [ + "http://localhost:3000", + "http://localhost:5173", + *required_origins, ] + cors_xml = ( + '' + '' + + "".join(f"{escape(origin)}" for origin in origins) + + '' + '*' + '
*
' + '
' + ) xml = "\n".join( [ "", " ", " ", - " ", - " ", - *origin_lines, - " ", - " ", - " *", - " ", - " ", - "
*
", - "
", - "
", + f" {cors_xml}", "
", " ", " ",