Skip to content

Commit fd03b00

Browse files
authored
feat!: move to microgen (#33)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-containeranalysis/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕
1 parent 6c2d764 commit fd03b00

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

container_registry/container_analysis/snippets/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
google-cloud-pubsub==1.7.0
22
google-cloud-containeranalysis==1.0.3
3-
grafeas==0.4.1
3+
grafeas==1.0.0
44
pytest==5.3.0; python_version > "3.0"
55
pytest==4.6.6; python_version < "3.0"
66
flaky==3.7.0

container_registry/container_analysis/snippets/samples.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

container_registry/container_analysis/snippets/samples_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
from google.cloud.devtools import containeranalysis_v1
2626
from google.cloud.pubsub import PublisherClient, SubscriberClient
2727

28-
from grafeas.grafeas_v1.gapic.enums import DiscoveryOccurrence
29-
from grafeas.grafeas_v1.gapic.enums import NoteKind
30-
from grafeas.grafeas_v1.gapic.enums import Severity
31-
from grafeas.grafeas_v1.gapic.enums import Version
28+
from grafeas.grafeas_v1 import DiscoveryOccurrence
29+
from grafeas.grafeas_v1 import NoteKind
30+
from grafeas.grafeas_v1 import Severity
31+
from grafeas.grafeas_v1 import Version
3232
import pytest
3333

3434
import samples
@@ -207,7 +207,7 @@ def test_poll_discovery_occurrence(self):
207207
}
208208
}
209209
grafeas_client.\
210-
create_note(grafeas_client.project_path(PROJECT_ID), note_id, note)
210+
create_note(parent=f"projects/{PROJECT_ID}", note_id=note_id, note=note)
211211
occurrence = {
212212
'note_name': f"projects/{PROJECT_ID}/notes/{note_id}",
213213
'resource_uri': self.image_url,
@@ -217,8 +217,8 @@ def test_poll_discovery_occurrence(self):
217217
}
218218
}
219219
created = grafeas_client.\
220-
create_occurrence(grafeas_client.project_path(PROJECT_ID),
221-
occurrence)
220+
create_occurrence(parent=f"projects/{PROJECT_ID}",
221+
occurrence=occurrence)
222222

223223
# poll again
224224
disc = samples.poll_discovery_finished(self.image_url, 10, PROJECT_ID)
@@ -278,7 +278,7 @@ def test_find_high_severity_vulnerabilities(self):
278278
}
279279
}
280280
grafeas_client.\
281-
create_note(grafeas_client.project_path(PROJECT_ID), note_id, note)
281+
create_note(parent=f"projects/{PROJECT_ID}", note_id=note_id, note=note)
282282
occurrence = {
283283
'note_name': f"projects/{PROJECT_ID}/notes/{note_id}",
284284
'resource_uri': self.image_url,
@@ -299,8 +299,8 @@ def test_find_high_severity_vulnerabilities(self):
299299
}
300300
}
301301
created = grafeas_client.\
302-
create_occurrence(grafeas_client.project_path(PROJECT_ID),
303-
occurrence)
302+
create_occurrence(parent=f"projects/{PROJECT_ID}",
303+
occurrence=occurrence)
304304
# query again
305305
tries = 0
306306
count = 0

0 commit comments

Comments
 (0)