Created
April 16, 2024 00:35
-
-
Save DinoChiesa/dc30758d7a875fc8349d1a522c7cb73c to your computer and use it in GitHub Desktop.
Fetch a proxy from Apigee Edge, and unzip the bundle locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -*- mode:shell-script; coding:utf-8; -*- | |
# | |
# Works with Apigee Edge. | |
# | |
proxyname="$1" | |
[[ -z "$proxyname" ]] && printf "specify a proxy name as argument\n" && exit 1 | |
MISSING_ENV_VARS=() | |
[[ -z "$EDGE_TOKEN" ]] && MISSING_ENV_VARS+=('EDGE_TOKEN') | |
[[ -z "$EDGE_ORG" ]] && MISSING_ENV_VARS+=('EDGE_ORG') | |
[[ ${#MISSING_ENV_VARS[@]} -ne 0 ]] && { | |
printf -v joined '%s,' "${MISSING_ENV_VARS[@]}" | |
printf "You must set these environment variables: %s\n" "${joined%,}" | |
exit 1 | |
} | |
# get latest revision | |
REV=$(curl -s -H "Authorization: Bearer ${EDGE_TOKEN}" -X GET "https://api.enterprise.apigee.com/v1/o/${EDGE_ORG}/apis/${proxyname}" | jq -r '.revision[-1]') | |
# export | |
zipname="${proxyname}_r${REV}.zip" | |
curl -s -H "Authorization: Bearer ${EDGE_TOKEN}" \ | |
-X GET \ | |
"https://api.enterprise.apigee.com/v1/o/${EDGE_ORG}/apis/${proxyname}/revisions/${REV}?format=bundle" \ | |
--output "${zipname}" | |
pair=(${zipname//./ }) | |
shortpname=${pair[0]} | |
outdir=${shortpname}-unzipped | |
rm -fr $outdir | |
unzip ${zipname} -d ${outdir} >/dev/null 2>&1 | |
rm "${zipname}" | |
echo "directory: $outdir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment