#!/bin/bash set -euo pipefail # Seed the DelmiaRecipeDownload inbound method (prod's script verbatim, minus its dead `suf` # line โ€” see docs/api-specs/Delmia-Recipe-Download-API.md ยง4) and one API key scoped to it. # Prints the one-time token as DELMIA_API_KEY=... โ€” capture it; it cannot be retrieved again. # Not idempotent (method name must be unique): delete with `api-method delete --id`. Key display # names are NOT unique โ€” re-running mints another key with the same name; delete the stale one with # `security api-key delete --key-id`. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" CLI="$PROJECT_ROOT/src/ZB.MOM.WW.ScadaBridge.CLI/bin/Debug/net10.0/scadabridge" A=(--url "${SCADABRIDGE_URL:-http://localhost:9000}" --format=json --username "${SCADABRIDGE_USERNAME:-multi-role}" --password "${SCADABRIDGE_PASSWORD:-password}") KEY_NAME="${KEY_NAME:-delmia-notifier}" json_id() { python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])'; } read -r -d '' METHOD_CODE <<'CS' || true try { System.Func P = k => Parameters.ContainsKey(k) ? Parameters[k] : null; var code = (P("MachineCode") as string ?? "").Trim(); if (string.IsNullOrEmpty(code)) return new { Result = false, ResultText = "MachineCode is required" }; return await Route.To(code).Call("ProcessRecipeDownload", new { DownloadPath = P("DownloadPath"), WorkOrderNumber = P("WorkOrderNumber"), PartNumber = P("PartNumber"), JobStepNumber = P("JobStepNumber"), Username = P("Username"), }); } catch (Exception ex) { return new { Result = false, ResultText = "RecipeDownload failed: " + ex.Message }; } CS echo "1/2 Creating inbound method DelmiaRecipeDownload (timeout 45 s)..." METHOD_ID=$("$CLI" api-method create "${A[@]}" --name DelmiaRecipeDownload --timeout 45 \ --parameters '{"type":"object","properties":{"MachineCode":{"type":"string"},"DownloadPath":{"type":"string"},"WorkOrderNumber":{"type":"string"},"PartNumber":{"type":"string"},"JobStepNumber":{"type":"string"},"Username":{"type":"string"}},"required":[]}' \ --return-def '{"type":"object","properties":{"Result":{"type":"boolean"},"ResultText":{"type":"string"}},"required":["Result","ResultText"]}' \ --script "$METHOD_CODE" | json_id) echo " id=$METHOD_ID name=DelmiaRecipeDownload" echo "2/2 Creating API key '$KEY_NAME' scoped to DelmiaRecipeDownload..." KEY_JSON=$("$CLI" security api-key create "${A[@]}" --name "$KEY_NAME" --methods DelmiaRecipeDownload) TOKEN=$(echo "$KEY_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin)["token"])' 2>/dev/null || echo "$KEY_JSON" | grep -o 'sbk_[A-Za-z0-9_-]*' | head -1) echo "DELMIA_API_KEY=$TOKEN"