-
Notifications
You must be signed in to change notification settings - Fork 8
/
report.py
executable file
·64 lines (50 loc) · 2.09 KB
/
report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
"""Display a report of GCP resources."""
# import modules
from lib.google import Google
def display_billing_accounts(google):
"""Display the billing accounts for the authenticated user."""
billing_accounts = google.get_billing_accounts()
print '\nBilling Accounts (%s)' % str(len(billing_accounts))
for ba in sorted(billing_accounts, key=lambda x: x['displayName']):
display_name = str(ba['displayName'])
name = str(ba['name'])
print ' * %s [%s]' % (display_name, name)
def display_folders(google, parent, depth=0):
"""Display the folders for the given parent."""
folders = google.get_folders(parent)
for folder in sorted(folders, key=lambda x: x['displayName']):
display_name = str(folder['displayName'])
name = str(folder['name'])
indent = ' ' * depth
print ' %s- %s [%s]' % (indent, display_name, name)
display_folders(google, name, depth+1)
def display_orgs(google):
"""Display the organizations for the authenticated user."""
organizations = google.get_organizations()
print '\nOrganizations (%s)' % str(len(organizations))
for org in sorted(organizations, key=lambda x: x['displayName']):
customerId = str(org['owner']['directoryCustomerId'])
display_name = str(org['displayName'])
name = str(org['name'])
print '\n * %s [%s] (%s)' % (display_name, name, customerId)
display_folders(google, name)
def display_projects(google):
"""Display the projects for the authenticated user."""
projects = google.get_projects()
print '\nProjects (%s)' % str(len(projects))
for project in sorted(projects, key=lambda x: x['name']):
name = str(project['name'])
projectId = str(project['projectId'])
print ' * %s [%s]' % (name, projectId)
def main():
"""Main function."""
# authenticate to google
print 'Authenticating to Google...'
google = Google()
google.auth()
display_orgs(google)
# display_billing_accounts(google)
# display_projects(google)
if __name__ == "__main__":
main()