Files
tf_provider/01_generate_yamls.sh
T
“Naeel” 612aa53caf api-gateway: migrate YAML gen + provider core from deck-api (?endpoint=) to lk-api-gateway (REST paths)
- service_spec_gen: callAPI() auto-detects proxy vs REST mode by index.cfm presence
- core/client.go: buildURL() replaces all 4 ?endpoint= harcoded sites
- build-provider.sh: -ldflags -X main.version=${VERSION} for correct binary version
- 01_generate_yamls.sh (devops + root): Python auto-detect proxy vs REST
- 02_generate_resources_and_docs_v2.sh: pass -api-endpoint to doc generators
- 04_build_and_publish_docs.sh: normalize_api_endpoint without forced /index.cfm
- docs_template_gen + v2: -api-endpoint flag, hardcoded deck-api replaced
- provider.go (both): TODO(api-gateway) comments
- profiles/test/profile.env: NUBES_API_ENDPOINT -> lk-api-gateway-test
- HISTORY: 2026-07-02_api_gateway_migration.md
2026-07-02 12:40:47 +04:00

83 lines
2.2 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="${ROOT_DIR:-${SCRIPT_DIR}}"
PROVIDER_DIR="${ROOT_DIR}/universal_rebuild"
SERVICES_FILE="${SERVICES_FILE:-${ROOT_DIR}/devops/config/services_list.txt}"
TOKEN_FILE="${TOKEN_FILE:-}"
NUBES_API_TOKEN="${NUBES_API_TOKEN:-}"
if [[ -z "$NUBES_API_TOKEN" ]]; then
if [[ -z "$TOKEN_FILE" ]]; then
TOKEN_FILE=$(ls -t /home/naeel/terra/*.token 2>/dev/null | head -n 1 || true)
fi
if [[ -n "$TOKEN_FILE" && -f "$TOKEN_FILE" ]]; then
NUBES_API_TOKEN=$(cat "$TOKEN_FILE")
fi
fi
if [[ -z "$NUBES_API_TOKEN" ]]; then
echo "Error: NUBES_API_TOKEN or TOKEN_FILE is required" >&2
exit 2
fi
if [[ ! -f "$SERVICES_FILE" ]]; then
echo "Error: services file not found: $SERVICES_FILE" >&2
exit 2
fi
API_ENDPOINT="${NUBES_API_ENDPOINT:-https://deck-api.ngcloud.ru/api/v1/index.cfm}"
while IFS= read -r sid; do
sid="${sid//[$'\t'\r' ']}"
if [[ -z "$sid" ]]; then
continue
fi
if [[ "$sid" == \#* ]]; then
continue
fi
svc_name=$(python3 - <<PY
import json
import urllib.parse
import urllib.request
sid = "${sid}"
endpoint = "${API_ENDPOINT}"
token = "${NUBES_API_TOKEN}"
# Auto-detect: "index.cfm" → legacy proxy, otherwise → REST gateway.
if "index.cfm" in endpoint:
params = urllib.parse.urlencode({"endpoint": f"/services/{sid}"})
url = f"{endpoint}?{params}"
else:
url = f"{endpoint}/services/{sid}"
req = urllib.request.Request(url)
if token:
req.add_header("Authorization", f"Bearer {token}")
with urllib.request.urlopen(req) as resp:
data = json.loads(resp.read().decode("utf-8"))
svc = data.get("svc", {})
name = svc.get("svcShort") or svc.get("name") or svc.get("title") or f"service_{sid}"
print(name)
PY
)
echo "Generating YAML for ${sid} (${svc_name})"
(
cd "$PROVIDER_DIR"
NUBES_API_TOKEN="$NUBES_API_TOKEN" \
NUBES_SERVICE_ID="$sid" \
NUBES_SERVICE_NAME="$svc_name" \
NUBES_OUTPUT="${PROVIDER_DIR}/resources_yaml/${svc_name}.yaml" \
NUBES_INSTRUCTION_OUTPUT="/dev/null" \
go run ./tools/service_params_gen/main.go
)
done < "$SERVICES_FILE"
echo "Done. YAML files are in ${PROVIDER_DIR}/resources_yaml"