Skip to content

Instantly share code, notes, and snippets.

@DinoChiesa
Last active April 16, 2024 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DinoChiesa/d9b3714f983e99aa8e3d0c6f27ba2aec to your computer and use it in GitHub Desktop.
Save DinoChiesa/d9b3714f983e99aa8e3d0c6f27ba2aec to your computer and use it in GitHub Desktop.
Fetch an API Proxy from Apigee X or hybrid, and unzip the bundle in the local filesystem
#!/bin/bash
# -*- mode:shell-script; coding:utf-8; -*-
#
# Works with Apigee X/hybrid.
#
proxyname="$1"
[[ -z "$proxyname" ]] && printf "specify a proxy name as argument\n" && exit 1
MISSING_ENV_VARS=()
[[ -z "$APIGEE_TOKEN" ]] && MISSING_ENV_VARS+=('APIGEE_TOKEN')
[[ -z "$APIGEE_PROJECT" ]] && MISSING_ENV_VARS+=('APIGEE_PROJECT')
[[ ${#MISSING_ENV_VARS[@]} -ne 0 ]] && {
printf -v joined '%s,' "${MISSING_ENV_VARS[@]}"
printf "You must set these environment variables: %s\n" "${joined%,}"
exit 1
}
cliout=($(apigeecli apis fetch -n "$proxyname" --token "$APIGEE_TOKEN" --org "$APIGEE_PROJECT"))
zipname=${cliout[1]}
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