78 lines
2.0 KiB
Bash
78 lines
2.0 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}"
|
|
|
|
params = urllib.parse.urlencode({"endpoint": f"/services/{sid}"})
|
|
url = f"{endpoint}?{params}"
|
|
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" |