Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# [END containeranalysis_poll_discovery_occurrence_finished]
# The above filter isn't testable, since it looks for occurrences in a
# locked down project fall back to a more permissive filter for testing
filter_str = 'kind="DISCOVERY" AND resourceUrl="{}"'\
.format(resource_url)
# [START containeranalysis_poll_discovery_occurrence_finished]
result = grafeas_client.list_occurrences(project_name, filter_str)
# only one occurrence should ever be returned by ListOccurrences
# and the given filter
for item in result:
discovery_occurrence = item
if time.time() > deadline:
raise RuntimeError('timeout while retrieving discovery occurrence')
status = DiscoveryOccurrence.AnalysisStatus.PENDING
while status != DiscoveryOccurrence.AnalysisStatus.FINISHED_UNSUPPORTED \
and status != DiscoveryOccurrence.AnalysisStatus.FINISHED_FAILED \
and status != DiscoveryOccurrence.AnalysisStatus.FINISHED_SUCCESS:
time.sleep(1)
updated = grafeas_client.get_occurrence(discovery_occurrence.name)
status = updated.discovery.analysis_status
if time.time() > deadline:
raise RuntimeError('timeout while waiting for terminal state')
return discovery_occurrence
# [END containeranalysis_poll_discovery_occurrence_finished]
time.sleep(1)
sys.stdout.write(".")
resource_url = get_resource_url(resource_url)
filter_str = 'resourceUrl="{}" \
AND noteProjectId="goog-analysis" \
AND noteId="PACKAGE_VULNERABILITY"'.format(resource_url)
result = grafeas_client.list_occurrences(project_name, filter_str)
# only one occurrence should ever be returned by ListOccurrences
# and the given filter
for item in result:
discovery_occurrence = item
if time.time() > deadline:
raise RuntimeError('timeout while retrieving discovery occurrence')
status = DiscoveryOccurrence.AnalysisStatus.PENDING
while status != DiscoveryOccurrence.AnalysisStatus.FINISHED_UNSUPPORTED \
and status != DiscoveryOccurrence.AnalysisStatus.FINISHED_FAILED \
and status != DiscoveryOccurrence.AnalysisStatus.FINISHED_SUCCESS:
time.sleep(1)
sys.stdout.write(".")
updated = grafeas_client.get_occurrence(discovery_occurrence.name)
status = updated.discovery.analysis_status
if time.time() > deadline:
raise RuntimeError('timeout while waiting for terminal state')
print("")
return discovery_occurrence