docs/demo/show-egress-ips.sh probes each healthy proxy from the discovery API against an IP-echo site; create-kubernetes-proxies.sh and create-gcp-proxies.sh bulk-create demo Proxies, the gcp one spreading them across randomly picked EU zones. Co-Authored-By: Claude <noreply@anthropic.com>
75 lines
2.2 KiB
Bash
Executable File
75 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Demo: list proxies from the discovery API and show the egress IP each
|
|
# healthy one provides, by calling an IP-echo site through it.
|
|
#
|
|
# Usage:
|
|
# ./show-egress-ips.sh <BASE_URL> e.g. ./show-egress-ips.sh localhost:8090
|
|
#
|
|
# Optional environment:
|
|
# TOKEN bearer token for the discovery API (see docs/api.md)
|
|
# IP_ECHO_URL site that returns the caller's IP as JSON
|
|
# (default: https://api.ipify.org?format=json)
|
|
set -euo pipefail
|
|
|
|
if [ $# -ne 1 ]; then
|
|
echo "usage: $(basename "$0") <BASE_URL> (e.g. localhost:8090)" >&2
|
|
exit 1
|
|
fi
|
|
BASE_URL="$1"
|
|
IP_ECHO_URL="${IP_ECHO_URL:-https://api.ipify.org?format=json}"
|
|
|
|
for tool in curl jq; do
|
|
if ! command -v "${tool}" &> /dev/null; then
|
|
echo "ERROR: ${tool} is required but not installed" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
auth_args=()
|
|
if [ -n "${TOKEN:-}" ]; then
|
|
auth_args=(-H "Authorization: Bearer ${TOKEN}")
|
|
fi
|
|
|
|
echo "Fetching proxies from ${BASE_URL}/v1/proxies ..."
|
|
if ! proxies_json=$(curl -sS --fail "${auth_args[@]}" "${BASE_URL}/v1/proxies"); then
|
|
echo "ERROR: could not fetch proxy list from ${BASE_URL}" >&2
|
|
exit 1
|
|
fi
|
|
if ! echo "${proxies_json}" | jq -e . > /dev/null; then
|
|
echo "ERROR: response from ${BASE_URL}/v1/proxies is not valid JSON" >&2
|
|
exit 1
|
|
fi
|
|
|
|
total=$(echo "${proxies_json}" | jq -r '.count')
|
|
echo "Found ${total} proxies"
|
|
echo ""
|
|
|
|
probed=0
|
|
skipped=0
|
|
failed=0
|
|
while IFS= read -r proxy; do
|
|
id=$(echo "${proxy}" | jq -r '.id')
|
|
ip=$(echo "${proxy}" | jq -r '.ip')
|
|
port=$(echo "${proxy}" | jq -r '.port')
|
|
healthy=$(echo "${proxy}" | jq -r '.healthy')
|
|
|
|
if [ "${healthy}" != "true" ]; then
|
|
echo "--- skipping ${id} (unhealthy) ---"
|
|
echo ""
|
|
skipped=$((skipped + 1))
|
|
continue
|
|
fi
|
|
|
|
echo "=== via ${id} — http://${ip}:${port} ==="
|
|
if response=$(curl -sS --max-time 10 -x "http://${ip}:${port}" "${IP_ECHO_URL}"); then
|
|
echo "${response}" | jq . 2> /dev/null || echo "${response}"
|
|
probed=$((probed + 1))
|
|
else
|
|
echo "WARNING: request through ${id} failed" >&2
|
|
failed=$((failed + 1))
|
|
fi
|
|
echo ""
|
|
done < <(echo "${proxies_json}" | jq -c '.proxies[]')
|
|
|
|
echo "Done: ${total} proxies — ${probed} probed, ${skipped} skipped (unhealthy), ${failed} failed"
|