UPD: refactored
This commit is contained in:
parent
f870383327
commit
a05c21d63f
|
@ -7,9 +7,9 @@ import boto3
|
|||
def recurseChildren(ouid, level):
|
||||
children = client.list_organizational_units_for_parent(ParentId=ouid).get('OrganizationalUnits')
|
||||
if len(children) == 0:
|
||||
childAccounts = getChildAccounts(ouid)
|
||||
childAccounts = client.list_accounts_for_parent(ParentId=ouid).get('Accounts')
|
||||
for c in childAccounts:
|
||||
print('.' * level, c[0], c[1])
|
||||
print('.' * level, c.get('Name'), c.get('Id'))
|
||||
return
|
||||
else:
|
||||
for c in children:
|
||||
|
@ -17,18 +17,10 @@ def recurseChildren(ouid, level):
|
|||
recurseChildren(c.get('Id'), level + 1)
|
||||
|
||||
|
||||
def getChildAccounts(ouid):
|
||||
childAccounts = client.list_accounts_for_parent(ParentId=ouid).get('Accounts')
|
||||
reducedList = []
|
||||
for a in childAccounts:
|
||||
tempList = [a.get('Name'), a.get('Id')]
|
||||
reducedList.append(tempList)
|
||||
return reducedList
|
||||
|
||||
|
||||
client = boto3.client('organizations')
|
||||
response = client.list_roots()
|
||||
|
||||
# print(json.dumps(response))
|
||||
rootId = response['Roots'][0]['Id']
|
||||
print('Root ', rootId)
|
||||
|
||||
|
|
Loading…
Reference in New Issue