Moved scripts

This commit is contained in:
2026-04-12 02:35:05 -05:00
parent c9e77915b0
commit f4653456f3
5 changed files with 3 additions and 3 deletions

89
deploy/pangolin-upsert.sh Normal file
View File

@@ -0,0 +1,89 @@
#!/usr/bin/env bash
# Idempotently register an HTTP resource + target in Pangolin
set -euo pipefail
SUBDOMAIN=""
PORT=""
RESOURCE_NAME=""
TARGET_IP=""
while [[ $# -gt 0 ]]; do
case $1 in
--subdomain) SUBDOMAIN="$2"; shift 2 ;;
--port) PORT="$2"; shift 2 ;;
--resource-name) RESOURCE_NAME="$2"; shift 2 ;;
--target-ip) TARGET_IP="$2"; shift 2 ;;
*) echo "Unknown arg: $1"; exit 1 ;;
esac
done
API="${PANGOLIN_API_URL}/v1"
AUTH="Authorization: Bearer ${PANGOLIN_API_KEY}"
echo "→ Pangolin upsert: ${RESOURCE_NAME}${SUBDOMAIN} on port ${PORT}"
# Check if resource already exists
EXISTING=$(curl -sf \
-H "${AUTH}" \
"${API}/org/${PANGOLIN_ORG_ID}/resources?limit=1000" \
| jq -r --arg name "${RESOURCE_NAME}" \
'.data.resources[] | select(.name == $name) | .resourceId' \
|| echo "")
if [[ -n "${EXISTING}" ]]; then
echo " Resource already exists (id=${EXISTING}), updating…"
RESOURCE_ID="${EXISTING}"
curl -sf -X POST \
-H "${AUTH}" \
-H "Content-Type: application/json" \
-d "{\"subdomain\": \"${SUBDOMAIN}\"}" \
"${API}/resource/${RESOURCE_ID}" \
> /dev/null
# Remove existing targets so we can re-register with potentially new port
TARGETS=$(curl -sf \
-H "${AUTH}" \
"${API}/resource/${RESOURCE_ID}/targets" \
| jq -r '.data.targets[].targetId' || echo "")
for TID in ${TARGETS}; do
curl -sf -X DELETE \
-H "${AUTH}" \
"${API}/target/${TID}" > /dev/null
echo " Removed old target ${TID}"
done
else
echo " Creating new resource…"
CREATE_RESP=$(curl -sf -X PUT \
-H "${AUTH}" \
-H "Content-Type: application/json" \
-d "{
\"name\": \"${RESOURCE_NAME}\",
\"http\": true,
\"subdomain\": \"${SUBDOMAIN}\",
\"domainId\": \"${PANGOLIN_DOMAIN_ID}\",
\"protocol\": \"tcp\"
}" \
"${API}/org/${PANGOLIN_ORG_ID}/resource")
RESOURCE_ID=$(echo "${CREATE_RESP}" | jq -r '.data.resourceId')
FULL_DOMAIN=$(echo "${CREATE_RESP}" | jq -r '.data.fullDomain')
echo " Created resource ${RESOURCE_ID}${FULL_DOMAIN}"
fi
# Add target
echo " Adding target localhost:${PORT} on site ${PANGOLIN_SITE_ID}"
TARGET_RESP=$(curl -sf -X PUT \
-H "${AUTH}" \
-H "Content-Type: application/json" \
-d "{
\"ip\": \"${TARGET_IP}\",
\"port\": ${PORT},
\"method\": \"http\",
\"siteId\": ${PANGOLIN_SITE_ID}
}" \
"${API}/resource/${RESOURCE_ID}/target")
TARGET_ID=$(echo "${TARGET_RESP}" | jq -r '.data.targetId')
echo "✓ Target ${TARGET_ID} registered for resource ${RESOURCE_ID}"