@@ -54,9 +54,9 @@ public class Samples {
54
54
/**
55
55
* Creates and returns a new vulnerability Note
56
56
* @param client The Grafeas client used to perform the API requests.
57
- * @param noteId A user-specified identifier for the note .
58
- * @param projectId the GCP project the note will be created under
59
- * @return a Note object representing the new note
57
+ * @param noteId A user-specified identifier for the Note .
58
+ * @param projectId the GCP project the Note will be created under
59
+ * @return the newly created Note object
60
60
*/
61
61
public static Note createNote (GrafeasV1Beta1Client client , String noteId , String projectId ) {
62
62
Note .Builder noteBuilder = Note .newBuilder ();
@@ -76,28 +76,29 @@ public static Note createNote(GrafeasV1Beta1Client client, String noteId, String
76
76
/**
77
77
* Creates and returns a new Occurrence of a previously created vulnerability Note
78
78
* @param client The Grafeas client used to perform the API requests.
79
- * @param imageUri the Container Registry URL associated with the image
79
+ * @param imageUrl the Container Registry URL associated with the image
80
80
* example: "https://gcr.io/project/image@sha256:foo"
81
- * @param parentNoteId the identifier of the note associated with this occurrence
82
- * @param projectId the GCP project the occurrence will be created under
83
- * @return an Occurrence object representing the new occurrence
81
+ * @param noteId the identifier of the Note associated with this Occurrence
82
+ * @param occProjectId the GCP project the Occurrence will be created under
83
+ * @param noteProjectId the GCP project the associated Note belongs to
84
+ * @return the newly created Occurrence object
84
85
*/
85
- public static Occurrence createOccurrence (GrafeasV1Beta1Client client , String imageUri ,
86
- String parentNoteId , String projectId ) {
87
- final String parentNoteName = client .formatNoteName (projectId , parentNoteId );
88
- final String projectName = client .formatProjectName (projectId );
86
+ public static Occurrence createOccurrence (GrafeasV1Beta1Client client , String imageUrl ,
87
+ String noteId , String occProjectId , String noteProjectId ) {
88
+ final String noteName = client .formatNoteName (noteProjectId , noteId );
89
+ final String occProjectName = client .formatProjectName (occProjectId );
89
90
90
91
Occurrence .Builder occBuilder = Occurrence .newBuilder ();
91
- occBuilder .setNoteName (parentNoteName );
92
+ occBuilder .setNoteName (noteName );
92
93
Details .Builder detailsBuilder = Details .newBuilder ();
93
94
// Details about the vulnerability instance can be added here
94
95
occBuilder .setVulnerability (detailsBuilder );
95
96
// Attach the occurrence to the associated image uri
96
97
Resource .Builder resourceBuilder = Resource .newBuilder ();
97
- resourceBuilder .setUri (imageUri );
98
+ resourceBuilder .setUri (imageUrl );
98
99
occBuilder .setResource (resourceBuilder );
99
100
Occurrence newOcc = occBuilder .build ();
100
- return client .createOccurrence (projectName , newOcc );
101
+ return client .createOccurrence (occProjectName , newOcc );
101
102
}
102
103
// [END create_occurrence]
103
104
@@ -106,43 +107,43 @@ public static Occurrence createOccurrence(GrafeasV1Beta1Client client, String im
106
107
* Pushes an update to a Note that already exists on the server
107
108
* @param client The Grafeas client used to perform the API requests.
108
109
* @param updated a Note object representing the desired updates to push
109
- * @param noteId the identifier of the existing note
110
+ * @param noteId the identifier of the existing Note
110
111
* @param projectId the GCP project the Note belongs to
111
112
*/
112
- public static void updateNote (GrafeasV1Beta1Client client , Note updated , String noteId ,
113
+ public static Note updateNote (GrafeasV1Beta1Client client , Note updated , String noteId ,
113
114
String projectId ) {
114
115
final String noteName = client .formatNoteName (projectId , noteId );
115
116
UpdateNoteRequest request = UpdateNoteRequest .newBuilder ()
116
117
.setName (noteName )
117
118
.setNote (updated )
118
119
.build ();
119
- client .updateNote (request );
120
+ return client .updateNote (request );
120
121
}
121
122
// [END update_note]
122
123
123
124
// [START update_occurrence]
124
125
/**
125
126
* Pushes an update to an Occurrence that already exists on the server
126
127
* @param client The Grafeas client used to perform the API requests.
127
- * @param occurrenceName the name of the occurrence to delete.
128
- * format: "projects/{projectId} /occurrences/{occurrence_id} "
128
+ * @param occurrenceName the name of the Occurrence to delete.
129
+ * format: "projects/[PROJECT_ID] /occurrences/[OCCURRENCE_ID] "
129
130
* @param updated an Occurrence object representing the desired updates to push
130
131
*/
131
- public static void updateOccurrence (GrafeasV1Beta1Client client , String occurrenceName ,
132
+ public static Occurrence updateOccurrence (GrafeasV1Beta1Client client , String occurrenceName ,
132
133
Occurrence updated ) {
133
134
UpdateOccurrenceRequest request = UpdateOccurrenceRequest .newBuilder ()
134
135
.setName (occurrenceName )
135
136
.setOccurrence (updated )
136
137
.build ();
137
- client .updateOccurrence (request );
138
+ return client .updateOccurrence (request );
138
139
}
139
140
// [END update_occurrence]
140
141
141
142
// [START delete_note]
142
143
/**
143
144
* Deletes an existing Note from the server
144
145
* @param client The Grafeas client used to perform the API requests.
145
- * @param noteId the identifier of the note to delete
146
+ * @param noteId the identifier of the Note to delete
146
147
* @param projectId the GCP project the Note belongs to
147
148
*/
148
149
public static void deleteNote (GrafeasV1Beta1Client client , String noteId , String projectId ) {
@@ -155,8 +156,8 @@ public static void deleteNote(GrafeasV1Beta1Client client, String noteId, String
155
156
/**
156
157
* Deletes an existing Occurrence from the server
157
158
* @param client The Grafeas client used to perform the API requests.
158
- * @param occurrenceName the name of the occurrence to delete
159
- * format: "projects/{projectId} /occurrences/{occurrence_id} "
159
+ * @param occurrenceName the name of the Occurrence to delete
160
+ * format: "projects/[PROJECT_ID] /occurrences/[OCCURRENCE_ID] "
160
161
*/
161
162
public static void deleteOccurrence (GrafeasV1Beta1Client client , String occurrenceName ) {
162
163
client .deleteOccurrence (occurrenceName );
@@ -166,29 +167,33 @@ public static void deleteOccurrence(GrafeasV1Beta1Client client, String occurren
166
167
167
168
// [START get_occurrence]
168
169
/**
169
- * Retrieves a specified Occurrence from the server
170
+ * Retrieves and prints a specified Occurrence from the server
170
171
* @param client The Grafeas client used to perform the API requests.
171
- * @param occurrenceName the name of the occurrence to delete
172
- * format: "projects/{projectId} /occurrences/{occurrence_id} "
172
+ * @param occurrenceName the name of the Occurrence to delete
173
+ * format: "projects/[PROJECT_ID] /occurrences/[OCCURRENCE_ID] "
173
174
* @return the requested Occurrence object
174
175
*/
175
176
public static Occurrence getOccurrence (GrafeasV1Beta1Client client , String occurrenceName ) {
176
- return client .getOccurrence (occurrenceName );
177
+ Occurrence occ = client .getOccurrence (occurrenceName );
178
+ System .out .println (occ );
179
+ return occ ;
177
180
}
178
181
// [END get_occurrence]
179
182
180
183
// [START get_note]
181
184
/**
182
- * Retrieves a specified Note from the server
185
+ * Retrieves and prints a specified Note from the server
183
186
* @param client The Grafeas client used to perform the API requests.
184
- * @param noteId the note 's unique identifier
187
+ * @param noteId the Note 's unique identifier
185
188
* @param projectId the GCP project the Note belongs to
186
189
* @return the requested Note object
187
190
*/
188
191
public static Note getNote (GrafeasV1Beta1Client client , String noteId , String projectId ) {
189
192
final String noteName = client .formatNoteName (projectId , noteId );
190
193
191
- return client .getNote (noteName );
194
+ Note n = client .getNote (noteName );
195
+ System .out .println (n );
196
+ return n ;
192
197
}
193
198
// [END get_note]
194
199
@@ -197,13 +202,13 @@ public static Note getNote(GrafeasV1Beta1Client client, String noteId, String pr
197
202
* Retrieves and prints the Discovery Occurrence created for a specified image
198
203
* The Discovery Occurrence contains information about the initial scan on the image
199
204
* @param client The Grafeas client used to perform the API requests.
200
- * @param imageUri the Container Registry URL associated with the image
205
+ * @param imageUrl the Container Registry URL associated with the image
201
206
* example: "https://gcr.io/project/image@sha256:foo"
202
207
* @param projectId the GCP project the image belongs to
203
208
*/
204
- public static void getDiscoveryInfo (GrafeasV1Beta1Client client , String imageUri ,
209
+ public static void getDiscoveryInfo (GrafeasV1Beta1Client client , String imageUrl ,
205
210
String projectId ) {
206
- String filterStr = "kind=\" DISCOVERY\" AND resourceUrl=\" " + imageUri + "\" " ;
211
+ String filterStr = "kind=\" DISCOVERY\" AND resourceUrl=\" " + imageUrl + "\" " ;
207
212
final String projectName = client .formatProjectName (projectId );
208
213
209
214
for (Occurrence o : client .listOccurrences (projectName , filterStr ).iterateAll ()) {
@@ -217,17 +222,17 @@ public static void getDiscoveryInfo(GrafeasV1Beta1Client client, String imageUri
217
222
* Retrieves all the Occurrences associated with a specified Note
218
223
* Here, all Occurrences are printed and counted
219
224
* @param client The Grafeas client used to perform the API requests.
220
- * @param noteId the note 's unique identifier
225
+ * @param noteId the Note 's unique identifier
221
226
* @param projectId the GCP project the Note belongs to
222
- * @return number of occurrences found
227
+ * @return number of Occurrences found
223
228
*/
224
229
public static int getOccurrencesForNote (GrafeasV1Beta1Client client , String noteId ,
225
230
String projectId ) {
226
- final String parentNoteName = client .formatNoteName (projectId , noteId );
231
+ final String noteName = client .formatNoteName (projectId , noteId );
227
232
int i = 0 ;
228
233
229
234
ListNoteOccurrencesRequest request = ListNoteOccurrencesRequest .newBuilder ()
230
- .setName (parentNoteName )
235
+ .setName (noteName )
231
236
.build ();
232
237
for (Occurrence o : client .listNoteOccurrences (request ).iterateAll ()) {
233
238
// Write custom code to process each Occurrence here
@@ -244,14 +249,14 @@ public static int getOccurrencesForNote(GrafeasV1Beta1Client client, String note
244
249
* Retrieves all the Occurrences associated with a specified image
245
250
* Here, all Occurrences are simply printed and counted
246
251
* @param client The Grafeas client used to perform the API requests.
247
- * @param imageUri the Container Registry URL associated with the image
252
+ * @param imageUrl the Container Registry URL associated with the image
248
253
* example: "https://gcr.io/project/image@sha256:foo"
249
254
* @param projectId the GCP project to search for Occurrences in
250
- * @return number of occurrences found
255
+ * @return number of Occurrences found
251
256
*/
252
- public static int getOccurrencesForImage (GrafeasV1Beta1Client client , String imageUri ,
257
+ public static int getOccurrencesForImage (GrafeasV1Beta1Client client , String imageUrl ,
253
258
String projectId ) {
254
- final String filterStr = "resourceUrl=\" " + imageUri + "\" " ;
259
+ final String filterStr = "resourceUrl=\" " + imageUrl + "\" " ;
255
260
final String projectName = client .formatProjectName (projectId );
256
261
int i = 0 ;
257
262
@@ -270,7 +275,7 @@ public static int getOccurrencesForImage(GrafeasV1Beta1Client client, String ima
270
275
* @param subId the user-specified identifier for the Pub/Sub subscription
271
276
* @param timeout the amount of time to listen for Pub/Sub messages (in seconds)
272
277
* @param projectId the GCP project the Pub/Sub subscription belongs to
273
- * @return number of occurrence Pub/Sub messages received before exiting
278
+ * @return number of Occurrence Pub/Sub messages received before exiting
274
279
* @throws InterruptedException on errors with the subscription client
275
280
*/
276
281
public static int pubSub (String subId , int timeout , String projectId )
@@ -327,7 +332,7 @@ public synchronized void receiveMessage(PubsubMessage message, AckReplyConsumer
327
332
public static Subscription createOccurrenceSubscription (String subId , String projectId )
328
333
throws IOException , StatusRuntimeException {
329
334
// This topic id will automatically receive messages when Occurrences are added or modified
330
- String topicId = "resource-notes -occurrences-v1alpha1 " ;
335
+ String topicId = "container-analysis -occurrences-v1beta1 " ;
331
336
SubscriptionAdminClient client = SubscriptionAdminClient .create ();
332
337
PushConfig config = PushConfig .getDefaultInstance ();
333
338
ProjectTopicName topicName = ProjectTopicName .of (projectId , topicId );
0 commit comments