Created
September 12, 2019 02:00
-
-
Save fj/6784d4e53d72dc4a33b678807fdd8589 to your computer and use it in GitHub Desktop.
Paginate the CF API.
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 | |
set -e | |
# requires `jq` | |
function load_all_pages { | |
URL="$1" | |
DATA="" | |
until [ "$URL" == "null" ]; do | |
RESP=$(cf curl "$URL") | |
DATA+=$(echo "$RESP" | jq .resources) | |
URL=$(echo "$RESP" | jq -r .next_url) | |
done | |
# dump the data | |
echo "$DATA" | jq .[] | jq -s | |
} | |
# example usage: | |
function load_all_apps { | |
SPACE_GUID="$1" | |
load_all_pages "/v2/spaces/$SPACE_GUID/apps" | |
} | |
APPS=$(load_all_apps "$SPACE_GUID") | |
echo $APPS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment