in lib/custom_resources/create_and_attach_scp.py [0:0]
def get_current_policies(org_client):
"""
:param org_client: Organization client with the assumed role into the master
:return: Map of current policies {[Name]:[Id]}
"""
current_policies = {}
p_response_ = org_client.list_policies(Filter='SERVICE_CONTROL_POLICY')
for policy in p_response_['Policies']:
current_policies[policy['Name']] = policy['Id']
if 'NextToken' in p_response_:
token_ = p_response_['NextToken']
LOGGER.info("Next token is {}".format(token_))
while token_ is not None:
try:
paginated_response_ = org_client.list_policies(Filter='SERVICE_CONTROL_POLICY', NextToken=token_)
for policy in paginated_response_['Policies']:
current_policies[policy['Name']] = policy['Id']
if 'NextToken' in paginated_response_:
token_ = paginated_response_['NextToken']
else:
token_ = None
except BaseException as e:
LOGGER.error(e)
raise BaseException("Failed the listing of the policies")
return current_policies