Skip to content

Instantly share code, notes, and snippets.

@danhigham
Created June 25, 2018 04: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 danhigham/4af295f025c1e297364f78d7ddc19d7a to your computer and use it in GitHub Desktop.
Save danhigham/4af295f025c1e297364f78d7ddc19d7a to your computer and use it in GitHub Desktop.
Dump CF Meta
#!/usr/bin/python
import json, subprocess
def cf_curl_json(cmd):
return json.loads(subprocess.Popen(("cf curl %s | jq '.resources[].entity' | jq --slurp '.'" % cmd),
stdout=subprocess.PIPE, shell=True).communicate()[0])
ORGS_SPACEURLS = [ (str(org['name']), str(org['spaces_url'])) for org in cf_curl_json("/v2/organizations") ]
for org, spaces_url in ORGS_SPACEURLS:
ORG_SPACE_APPURLS = [ (org, str(space['name']), str(space['apps_url'])) for space in cf_curl_json(spaces_url) ]
for org, space, app_url in ORG_SPACE_APPURLS:
ORG_SPACE_APP_BUILDPACK = [ (org, space, str(a['name']), str(a['buildpack'])) for a in cf_curl_json(app_url) ]
for app in ORG_SPACE_APP_BUILDPACK:
print ("%s, %s, %s, %s" % app)
#!/bin/bash
ORGS_JSON=$( cf curl /v2/organizations | jq '.resources[].entity' | jq --slurp '.' )
declare -a orgs=($( echo $ORGS_JSON | jq '.[].name' ))
for org in "${orgs[@]}"
do
spaces_url=$(echo $ORGS_JSON | jq -r ".[] | select(.name == $org).spaces_url" )
SPACES_JSON=$( cf curl $spaces_url | jq '.resources[].entity' | jq --slurp '.' )
declare -a spaces=($( echo $SPACES_JSON | jq '.[].name' ))
for space in "${spaces[@]}"
do
apps_url=$(echo $SPACES_JSON | jq -r ".[] | select(.name == $space).apps_url" )
APPS_JSON=$( cf curl $apps_url | jq '.resources[].entity' | jq --slurp '.' )
declare -a apps=($( echo $APPS_JSON | jq '.[].name' ))
for app in "${apps[@]}"
do
buildpack=$(echo $APPS_JSON | jq -r ".[] | select(.name == $app).buildpack" )
echo "$org, $space, $app, $buildpack"
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment