in control-tower-account-factory/src/handler.py [0:0]
def __get_account_list(self, accounts=None, deployment_ou_list=None):
"""get list of the accounts to process"""
self._log_info('Get accounts list')
account_list = (accounts if accounts else [])
if deployment_ou_list:
try:
response_roots = self.org_client.list_roots()
root_ou_id = response_roots['Roots'][0]['Id']
ou_list = self.__get_ou_ids(root_ou_id)
for organization_unit in ou_list:
if organization_unit not in deployment_ou_list:
continue
org_id = ou_list[organization_unit]
paginator = self.org_client.get_paginator('list_accounts_for_parent')
org_iterator = paginator.paginate(
ParentId=org_id
)
for page in org_iterator:
for account in page['Accounts']:
if account['Id'] not in account_list:
account_list.append(account['Id'])
except ClientError as error:
self._log_error(f'Error obtain account list. Error: {error.response["Error"]}')
self._send_notification('Error obtain account list', f'Error: {error.response["Error"]}')
return account_list