in cfn_policy_validator/validation/validator.py [0:0]
def _wait_for_findings(self, previews_to_await):
findings = []
for preview in previews_to_await:
number_of_attempts = 0
while True:
LOGGER.info(f'Waiting on access preview {preview.id} to finish creating attempt {number_of_attempts+1}..')
response = self.client.get_access_preview(
accessPreviewId=preview.id,
analyzerArn=self.analyzer_arn
)
LOGGER.info(f'GetAccessPreview response: {response}')
status = response['accessPreview']['status']
if status == 'CREATING':
number_of_attempts = number_of_attempts + 1
if number_of_attempts >= self.maximum_number_of_access_preview_attempts:
raise ApplicationError(f'Timed out after 5 minutes waiting for access analyzer preview to create.')
time.sleep(2)
else:
break
LOGGER.info(f'Access preview creation completed for {preview.name} with status {status}')
if status == 'FAILED':
reason = response["accessPreview"]["statusReason"]["code"]
if reason == 'INVALID_CONFIGURATION':
self._raise_invalid_configuration_error_for(preview.name, preview.validation_findings)
raise ApplicationError(f'Failed to create access preview for {preview.name}. Reason: {reason}')
paginator = self.client.get_paginator('list_access_preview_findings')
for page in paginator.paginate(accessPreviewId=preview.id, analyzerArn=self.analyzer_arn):
findings.append(AccessPreviewFindings(preview.resource, page['findings']))
return findings