Created
June 29, 2019 12:10
-
-
Save suhlig/c295e3980f6e8c5d72e0870247517823 to your computer and use it in GitHub Desktop.
List all cf apps across all orgs and spaces
This file contains 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
#!/usr/bin/env ruby | |
require 'json' | |
require 'shellwords' | |
HIERARCHY = %w(/ org space app) | |
def curl(url) | |
while url | |
JSON.parse(`cf curl #{Shellwords.escape(url)}`).tap do |result| | |
raise "Error #{result['error_code']}: #{result['description']}" if result['error_code'] | |
yield result # streaming: handle each page as we get it | |
url = result['next_url'] | |
end | |
end | |
end | |
def indent(level) | |
' ' * level | |
end | |
def dump(entity, level = 0) | |
type = HIERARCHY[level] | |
puts "#{indent(level)} #{type} #{entity['name']} #{entity['state']}" | |
child_type = HIERARCHY[level + 1] | |
curl(entity["#{child_type}s_url"]) do |entities| | |
# warn "#{indent(level + 1)} #{entities['total_results']} #{child_type}s" | |
entities['resources'].each do |child| | |
dump(child['entity'], level + 1) | |
end | |
end | |
end | |
dump('orgs_url' => '/v2/organizations') | |
__END__ | |
TODO: | |
--skip-org | |
--skip-space |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment