Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2eefd56
added container analysis samples and tests
daniel-sanche Feb 16, 2018
4510418
added v1 libraries
daniel-sanche Jun 11, 2019
210451c
updated region tags
daniel-sanche Jun 11, 2019
121796a
removed doc comments
daniel-sanche Jun 11, 2019
84caf87
removed update samples
daniel-sanche Jun 11, 2019
17269c2
updated parameters to be consistent with other languages
daniel-sanche Jun 11, 2019
f688b38
resolved compiler errors
daniel-sanche Jun 11, 2019
4669433
got client working for development
daniel-sanche Jun 12, 2019
0894f76
added sample note
daniel-sanche Jun 12, 2019
c5cb60a
updated create_occurrence
daniel-sanche Jun 12, 2019
132fc5c
got pubsub working
daniel-sanche Jun 12, 2019
d5498f1
implemented poll_discovery_occurrence
daniel-sanche Jun 13, 2019
2e70dd2
use runtimeerror
daniel-sanche Jun 13, 2019
ca20894
implemented find_vulnerabilities and find_high_severity
daniel-sanche Jun 13, 2019
104c27a
moved imports into functions
daniel-sanche Jun 13, 2019
e2a7d35
replaces " with '
daniel-sanche Jun 13, 2019
37a6247
added comments to samples
daniel-sanche Jun 13, 2019
8144f75
use released libraries
daniel-sanche Jun 20, 2019
0c2e311
updated client creation in samples
daniel-sanche Jun 20, 2019
de15238
fixed broken tests
daniel-sanche Jun 20, 2019
bed1dcb
fixed linter issues
daniel-sanche Jun 20, 2019
95ba536
Merge branch 'master' into container-analysis-ga
daniel-sanche Jun 20, 2019
2940dda
updated topic
daniel-sanche Jul 3, 2019
fdd94cc
added README
daniel-sanche Jul 3, 2019
6c252b3
fixed typo
daniel-sanche Jul 3, 2019
e8f79f8
readme fixes
daniel-sanche Jul 4, 2019
67f2b0f
updated pubsub version
daniel-sanche Jul 4, 2019
601dbb5
reverted pubsub topic
daniel-sanche Jul 4, 2019
0c318db
create topic if needed
daniel-sanche Jul 8, 2019
b3203e7
add instructions for authentication to README
daniel-sanche Jul 8, 2019
cccf56c
Merge branch 'master' into container-analysis-ga
daniel-sanche Jul 9, 2019
8e603f3
replaced pytest with nox in README
daniel-sanche Jul 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated region tags
  • Loading branch information
daniel-sanche committed Jun 11, 2019
commit 210451c5819b74a744965ae6b95892100c7e4960
49 changes: 24 additions & 25 deletions container_registry/container_analysis/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from google.cloud.pubsub import SubscriberClient


# [START create_note]
# [START containeranalysis_create_note]
def create_note(note_id, project_id):
"""Creates and returns a new note

Expand All @@ -44,10 +44,10 @@ def create_note(note_id, project_id):
note = containeranalysis_pb2.Note(vulnerability_type=type)
response = client.create_note(parent, note_id, note)
return response
# [END create_note]
# [END containeranalysis_create_note]


# [START create_occurrence]
# [START ccontaineranalysis_create_occurrence]
def create_occurrence(image_url, parent_note_id, project_id):
"""Creates and returns a new occurrence

Expand All @@ -72,10 +72,9 @@ def create_occurrence(image_url, parent_note_id, project_id):
resource_url=image_url,
vulnerability_details=vul)
return client.create_occurrence(project_name, occurrence)
# [END create_occurrence]
# [END containeranalysis_create_occurrence]


# [START update_note]
# [START containeranalysis_update_note]
def update_note(updated, note_id, project_id):
"""Makes an update to an existing note

Expand All @@ -93,10 +92,10 @@ def update_note(updated, note_id, project_id):
note_name = client.note_path(project_id, note_id)

client.update_note(note_name, updated)
# [END update_note]
# [END containeranalysis_update_note]


# [START update_occurrence]
# [START containeranalysis_update_occurrence]
def update_occurrence(updated, occurrence_name):
"""Makes an update to an existing occurrence

Expand All @@ -112,10 +111,10 @@ def update_occurrence(updated, occurrence_name):
"""
client = container_analysis_client.ContainerAnalysisClient()
client.update_occurrence(occurrence_name, updated)
# [END update_occurrence]
# [END containeranalysis_update_occurrence]


# [START delete_note]
# [START containeranalysis_delete_note]
def delete_note(note_id, project_id):
"""Deletes an existing note

Expand All @@ -132,10 +131,10 @@ def delete_note(note_id, project_id):
note_name = client.note_path(project_id, note_id)

client.delete_note(note_name)
# [END delete_note]
# [END containeranalysis_delete_note]


# [START delete_occurrence]
# [START containeranalysis_delete_occurrence]
def delete_occurrence(occurrence_name):
"""Deletes an existing occurrence

Expand All @@ -150,10 +149,10 @@ def delete_occurrence(occurrence_name):
"""
client = container_analysis_client.ContainerAnalysisClient()
client.delete_occurrence(occurrence_name)
# [END delete_occurrence]
# [END containeranalysis_delete_occurrence]


# [START get_note]
# [START containeranalysis_get_note]
def get_note(note_id, project_id):
"""Retrieves a note based on it's noteId and projectId

Expand All @@ -171,10 +170,10 @@ def get_note(note_id, project_id):
note_name = client.note_path(project_id, note_id)
response = client.get_note(note_name)
return response
# [END get_note]
# [END containeranalysis_get_note]


# [START get_occurrence]
# [START containeranalysis_get_occurrence]
def get_occurrence(occurrence_name):
"""Retrieves an occurrence based on it's name

Expand All @@ -190,10 +189,10 @@ def get_occurrence(occurrence_name):
"""
client = container_analysis_client.ContainerAnalysisClient()
return client.get_occurrence(occurrence_name)
# [END get_occurrence]
# [END containeranalysis_get_occurrence]


# [START discovery_info]
# [START containeranalysis_discovery_info]
def get_discovery_info(image_url, project_id):
"""prints the Discovery occurrence created for a specified image
This occurrence contains information about the initial scan on the image
Expand All @@ -214,10 +213,10 @@ def get_discovery_info(image_url, project_id):
response = client.list_occurrences(project_name, filter_=filterStr)
for occ in response:
print(occ)
# [END discovery_info]
# [END containeranalysis_discovery_info]


# [START occurrences_for_note]
# [START containeranalysis_occurrences_for_note]
def get_occurrences_for_note(note_id, project_id):
"""Retrieves all the occurrences associated with a specified note

Expand All @@ -241,10 +240,10 @@ def get_occurrences_for_note(note_id, project_id):
# in this sample, we will simply count each one
count += 1
return count
# [END occurrences_for_note]
# [END containeranalysis_occurrences_for_note]


# [START occurrences_for_image]
# [START containeranalysis_occurrences_for_image]
def get_occurrences_for_image(image_url, project_id):
"""Retrieves all the occurrences associated with a specified image

Expand All @@ -269,10 +268,10 @@ def get_occurrences_for_image(image_url, project_id):
# in this sample, we will simply count each one
count += 1
return count
# [END occurrences_for_image]
# [END containeranalysis_occurrences_for_image]


# [START pubsub]
# [START containeranalysis_pubsub]
def pubsub(subscription_id, timeout, project_id):
"""Handle incoming occurrences using a pubsub subscription

Expand Down Expand Up @@ -338,4 +337,4 @@ def create_occurrence_subscription(subscription_id, project_id):
else:
success = False
return success
# [END pubsub]
# [END containeranalysis_pubsub]