@@ -20,12 +20,12 @@ def create_note(note_id, project_id):
2020 # note_id = 'my-note'
2121 # project_id = 'my-gcp-project'
2222
23- from grafeas .grafeas_v1 . gapic . enums import Version
23+ from grafeas .grafeas_v1 import Version
2424 from google .cloud .devtools import containeranalysis_v1
2525
2626 client = containeranalysis_v1 .ContainerAnalysisClient ()
2727 grafeas_client = client .get_grafeas_client ()
28- project_name = grafeas_client . project_path ( project_id )
28+ project_name = f"projects/ { project_id } "
2929 note = {
3030 'vulnerability' : {
3131 'details' : [
@@ -42,7 +42,7 @@ def create_note(note_id, project_id):
4242 ]
4343 }
4444 }
45- response = grafeas_client .create_note (project_name , note_id , note )
45+ response = grafeas_client .create_note (parent = project_name , note_id = note_id , note = note )
4646 return response
4747# [END containeranalysis_create_note]
4848
@@ -59,7 +59,7 @@ def delete_note(note_id, project_id):
5959 grafeas_client = client .get_grafeas_client ()
6060 note_name = f"projects/{ project_id } /notes/{ note_id } "
6161
62- grafeas_client .delete_note (note_name )
62+ grafeas_client .delete_note (name = note_name )
6363# [END containeranalysis_delete_note]
6464
6565
@@ -72,13 +72,13 @@ def create_occurrence(resource_url, note_id, occurrence_project, note_project):
7272 # occurrence_project = 'my-gcp-project'
7373 # note_project = 'my-gcp-project'
7474
75- from grafeas .grafeas_v1 . gapic . enums import Version
75+ from grafeas .grafeas_v1 import Version
7676 from google .cloud .devtools import containeranalysis_v1
7777
7878 client = containeranalysis_v1 .ContainerAnalysisClient ()
7979 grafeas_client = client .get_grafeas_client ()
8080 formatted_note = f"projects/{ note_project } /notes/{ note_id } "
81- formatted_project = grafeas_client . project_path ( occurrence_project )
81+ formatted_project = f"projects/ { occurrence_project } "
8282
8383 occurrence = {
8484 'note_name' : formatted_note ,
@@ -99,7 +99,7 @@ def create_occurrence(resource_url, note_id, occurrence_project, note_project):
9999 }
100100 }
101101
102- return grafeas_client .create_occurrence (formatted_project , occurrence )
102+ return grafeas_client .create_occurrence (parent = formatted_project , occurrence = occurrence )
103103# [END containeranalysis_create_occurrence]
104104
105105
@@ -114,7 +114,7 @@ def delete_occurrence(occurrence_id, project_id):
114114 client = containeranalysis_v1 .ContainerAnalysisClient ()
115115 grafeas_client = client .get_grafeas_client ()
116116 parent = f"projects/{ project_id } /occurrences/{ occurrence_id } "
117- grafeas_client .delete_occurrence (parent )
117+ grafeas_client .delete_occurrence (name = parent )
118118# [END containeranalysis_delete_occurrence]
119119
120120
@@ -129,7 +129,7 @@ def get_note(note_id, project_id):
129129 client = containeranalysis_v1 .ContainerAnalysisClient ()
130130 grafeas_client = client .get_grafeas_client ()
131131 note_name = f"projects/{ project_id } /notes/{ note_id } "
132- response = grafeas_client .get_note (note_name )
132+ response = grafeas_client .get_note (name = note_name )
133133 return response
134134# [END containeranalysis_get_note]
135135
@@ -145,7 +145,7 @@ def get_occurrence(occurrence_id, project_id):
145145 client = containeranalysis_v1 .ContainerAnalysisClient ()
146146 grafeas_client = client .get_grafeas_client ()
147147 parent = f"projects/{ project_id } /occurrences/{ occurrence_id } "
148- return grafeas_client .get_occurrence (parent )
148+ return grafeas_client .get_occurrence (name = parent )
149149# [END containeranalysis_get_occurrence]
150150
151151
@@ -162,8 +162,8 @@ def get_discovery_info(resource_url, project_id):
162162 filter_str = 'kind="DISCOVERY" AND resourceUrl="{}"' .format (resource_url )
163163 client = containeranalysis_v1 .ContainerAnalysisClient ()
164164 grafeas_client = client .get_grafeas_client ()
165- project_name = grafeas_client . project_path ( project_id )
166- response = grafeas_client .list_occurrences (project_name ,
165+ project_name = f"projects/ { project_id } "
166+ response = grafeas_client .list_occurrences (parent = project_name ,
167167 filter_ = filter_str )
168168 for occ in response :
169169 print (occ )
@@ -183,7 +183,7 @@ def get_occurrences_for_note(note_id, project_id):
183183 grafeas_client = client .get_grafeas_client ()
184184 note_name = f"projects/{ project_id } /notes/{ note_id } "
185185
186- response = grafeas_client .list_note_occurrences (note_name )
186+ response = grafeas_client .list_note_occurrences (name = note_name )
187187 count = 0
188188 for o in response :
189189 # do something with the retrieved occurrence
@@ -205,10 +205,10 @@ def get_occurrences_for_image(resource_url, project_id):
205205 filter_str = 'resourceUrl="{}"' .format (resource_url )
206206 client = containeranalysis_v1 .ContainerAnalysisClient ()
207207 grafeas_client = client .get_grafeas_client ()
208- project_name = grafeas_client . project_path ( project_id )
208+ project_name = f"projects/ { project_id } "
209209
210- response = grafeas_client .list_occurrences (project_name ,
211- filter_ = filter_str )
210+ response = grafeas_client .list_occurrences (parent = project_name ,
211+ filter = filter_str )
212212 count = 0
213213 for o in response :
214214 # do something with the retrieved occurrence
@@ -288,14 +288,14 @@ def poll_discovery_finished(resource_url, timeout_seconds, project_id):
288288 # project_id = 'my-gcp-project'
289289
290290 import time
291- from grafeas .grafeas_v1 . gapic . enums import DiscoveryOccurrence
291+ from grafeas .grafeas_v1 import DiscoveryOccurrence
292292 from google .cloud .devtools import containeranalysis_v1
293293
294294 deadline = time .time () + timeout_seconds
295295
296296 client = containeranalysis_v1 .ContainerAnalysisClient ()
297297 grafeas_client = client .get_grafeas_client ()
298- project_name = grafeas_client . project_path ( project_id )
298+ project_name = f"projects/ { project_id } "
299299
300300 discovery_occurrence = None
301301 while discovery_occurrence is None :
@@ -309,7 +309,7 @@ def poll_discovery_finished(resource_url, timeout_seconds, project_id):
309309 filter_str = 'kind="DISCOVERY" AND resourceUrl="{}"' \
310310 .format (resource_url )
311311 # [START containeranalysis_poll_discovery_occurrence_finished]
312- result = grafeas_client .list_occurrences (project_name , filter_str )
312+ result = grafeas_client .list_occurrences (parent = project_name , filter = filter_str )
313313 # only one occurrence should ever be returned by ListOccurrences
314314 # and the given filter
315315 for item in result :
@@ -322,7 +322,7 @@ def poll_discovery_finished(resource_url, timeout_seconds, project_id):
322322 and status != DiscoveryOccurrence .AnalysisStatus .FINISHED_FAILED \
323323 and status != DiscoveryOccurrence .AnalysisStatus .FINISHED_SUCCESS :
324324 time .sleep (1 )
325- updated = grafeas_client .get_occurrence (discovery_occurrence .name )
325+ updated = grafeas_client .get_occurrence (name = discovery_occurrence .name )
326326 status = updated .discovery .analysis_status
327327 if time .time () > deadline :
328328 raise RuntimeError ('timeout while waiting for terminal state' )
@@ -340,11 +340,11 @@ def find_vulnerabilities_for_image(resource_url, project_id):
340340
341341 client = containeranalysis_v1 .ContainerAnalysisClient ()
342342 grafeas_client = client .get_grafeas_client ()
343- project_name = grafeas_client . project_path ( project_id )
343+ project_name = f"projects/ { project_id } "
344344
345345 filter_str = 'kind="VULNERABILITY" AND resourceUrl="{}"' \
346346 .format (resource_url )
347- return list (grafeas_client .list_occurrences (project_name , filter_str ))
347+ return list (grafeas_client .list_occurrences (parent = project_name , filter = filter_str ))
348348# [END containeranalysis_vulnerability_occurrences_for_image]
349349
350350
@@ -355,16 +355,16 @@ def find_high_severity_vulnerabilities_for_image(resource_url, project_id):
355355 # resource_url = 'https://gcr.io/my-project/my-image@sha256:123'
356356 # project_id = 'my-gcp-project'
357357
358- from grafeas .grafeas_v1 . gapic . enums import Severity
358+ from grafeas .grafeas_v1 import Severity
359359 from google .cloud .devtools import containeranalysis_v1
360360
361361 client = containeranalysis_v1 .ContainerAnalysisClient ()
362362 grafeas_client = client .get_grafeas_client ()
363- project_name = grafeas_client . project_path ( project_id )
363+ project_name = f"projects/ { project_id } "
364364
365365 filter_str = 'kind="VULNERABILITY" AND resourceUrl="{}"' \
366366 .format (resource_url )
367- vulnerabilities = grafeas_client .list_occurrences (project_name , filter_str )
367+ vulnerabilities = grafeas_client .list_occurrences (parent = project_name , filter = filter_str )
368368 filtered_list = []
369369 for v in vulnerabilities :
370370 if v .effective_severity == Severity .HIGH or v .effective_severity == Severity .CRITICAL :
0 commit comments