-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathopenapi.jq
More file actions
501 lines (497 loc) · 15.6 KB
/
Copy pathopenapi.jq
File metadata and controls
501 lines (497 loc) · 15.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# vim: set expandtab ts=2 sw=2:
include "oapi";
# Some helper functions:
def example_ref($id): ref("examples/\($id).json"); # Files are local at build time.
def responses($r):
{
"200": {
description: "Success",
headers: {
"Clair-Error": header_ref("Clair-Error"),
},
},
"400": response_ref("bad_request"),
"415": response_ref("unsupported_media_type"),
default: response_ref("oops"),
} * $r
;
# Some variables:
"/notifier/api/v1" as $path_notif |
"/matcher/api/v1" as $path_match |
"/indexer/api/v1" as $path_index |
# The OpenAPI object:
{
openapi: "3.1.0",
info: {
title: "Clair Container Analyzer",
description: ([
"Clair is a set of cooperating microservices which can index and match a container image's content with known vulnerabilities.",
"",
"**Note:** Any endpoints tagged \"internal\" are documented for completeness but are considered exempt from versioning.",
""] | join("\n") | sub("[[:space:]]*$"; "")),
version: "1.2.0",
contact: {
name: "Clair Team",
url: "http://github.com/quay/clair",
email: "clair-devel@googlegroups.com",
},
license: {
name: "Apache License 2.0",
url: "http://www.apache.org/licenses/",
}
},
externalDocs: { url: "https://quay.github.io/clair/" },
tags: ({
indexer: "Indexer service endpoints.\n\nThese are responsible for determining the contents of containers.",
matcher: "Matcher service endpoints.\n\nThese are responsible for generating reports against current vulnerability data.",
notifier: "Matcher service endpoints.\n\nThese are responsible for serving notifications.",
internal: "These are internal endpoints, documented for completeness.\n\nThey are exempted from API stability guarentees.",
} | to_entries | map({name: .key, description: .value}) ),
paths: {
"\($path_notif)/notification/{id}": {
parameters: [ {
in: "path",
name: "id",
required: true,
schema: schema_ref("token"),
description: "A notification ID returned by a callback"
} ],
delete: {
operationId: "DeleteNotification",
responses: responses({
"200": { description: "Delete the notification referenced by the \"id\" parameter." },
}),
},
get: {
operationId: "GetNotification",
parameters: [
{
in: "query",
name: "page_size",
schema: {
type: "integer",
default: 500,
},
description: "The maximum number of notifications to deliver in a single page."
},
{
in: "query",
name: "next",
schema: schema_ref("token"),
description: "The next page to fetch via id. Typically this number is provided on initial response in the \"page.next\" field. The first request should omit this field."
}
],
responses: responses({
"200": {
description: "A paginated list of notifications",
content: contenttype("notification_page"),
},
"304": {
description: "Not Modified",
},
})
}
},
"\($path_index)/index_report": {
post: {
operationId: "Index",
requestBody: {
description: "Manifest to index.",
required: true,
content: contenttype("manifest"),
},
responses: (responses({
"201": {
description: "IndexReport created.\n\nClients may want to avoid reading the body if simply submitting the manifest for later vulnerability reporting.",
content: contenttype("index_report"),
headers: {
Location: header_ref("Location"),
Link: header_ref("Link"),
},
links: {
retrieve: {
operationId: "GetIndexReport",
parameters: {
digest: "$request.body#/hash"
},
},
delete: {
operationId: "DeleteManifest",
parameters: {
digest: "$request.body#/hash"
},
},
report: {
operationId: "GetVulnerabilityReport",
parameters: {
digest: "$request.body#/hash"
},
},
},
},
"412": {
description: "Precondition Failed",
},
}) | del(.["200"])),
},
delete: {
operationId: "DeleteManifests",
requestBody: {
description: "Array of manifest digests to delete.",
required: true,
content: contenttype("bulk_delete"),
},
responses: responses({
"200": {
description: "Successfully deleted manifests.",
content: contenttype("bulk_delete"),
},
}),
}
},
"\($path_index)/index_report/{digest}": {
delete: {
operationId: "DeleteManifest",
responses: (responses({"204": {
description: "Success",
}}) |
del(.["200"])),
},
get: {
operationId: "GetIndexReport",
responses: responses({
"200": {
description: "IndexReport retrieved",
content: contenttype("index_report"),
},
"404": response_ref("not_found"),
}),
},
parameters: [ param_ref("digest") ],
},
"\($path_index)/internal/affected_manifest": {
post: {
operationId: "AffectedManifests",
requestBody: {
description: "Array of vulnerability summaries to report on.",
required: true,
content: contenttype("vulnerability_summaries"),
},
responses: responses({
"200": {
description: "The list of manifests and the corresponding vulnerabilities.",
content: contenttype("affected_manifests"),
},
}),
},
},
"\($path_index)/index_state": {
get: {
operationId: "IndexState",
responses: {
"200": {
description: "Indexer State",
headers: {
Etag: header_ref("Etag"),
},
content: contenttype("index_state"),
},
"304": {
description: "Not Modified",
},
}
}
},
"\($path_match)/vulnerability_report/{digest}": {
get: {
operationId: "GetVulnerabilityReport",
responses: (responses({
"201": {
description: "Vulnerability Report Created",
content: contenttype("vulnerability_report"),
}
,
"404": response_ref("not_found"),
}) | del(.["200"])),
},
parameters: [ param_ref("digest") ],
},
"\($path_match)/internal/update_operation": {
get: {
operationId: "GetUpdateOperation",
responses: responses({
"200": {
description: "Update Operations, keyed by updater.",
content: contenttype("update_operations"),
},
}),
parameters: [
{
in: "query",
name: "kind",
schema: {
enum:["vulnerability", "enrichment"],
default:"vulnerability",
},
description: "The \"kind\" of updaters to query."
},
{
in: "query",
name: "latest",
schema: {
type:"boolean",
default: false
},
description: "Return only the latest Update Operations instead of all known Update Operations."
}
],
},
},
"\($path_match)/internal/update_operation/{id}": {
delete: {
operationId: "DeleteUpdateOperation",
responses: (responses({
"204": {
description: "Success",
},
}) | del(.["200"])),
},
parameters: [ param_ref("update_operation_id") ],
},
"\($path_match)/internal/update_diff": {
get: {
operationId: "GetUpdateDiff",
responses: responses({
"200": {
description: "Changes between two Update Operations.",
content: contenttype("update_diff"),
},
}),
parameters: [
{
in: "query",
name: "cur",
schema: schema_ref("token"),
description: "\"Current\" Update Operation ref."
},
{
in: "query",
name: "prev",
required: true,
schema: schema_ref("token"),
description: "\"Previous\" Update Operation ref."
}
],
},
},
},
security: [
{},
{ PSK: [] }
],
webhooks: {
notification: {
post: {
tags: ["notifier"],
description: "If configured, Clair will issue webhooks when notifications are available for retrieval.",
requestBody: {
content: contenttype("notification_webhook"),
},
responses: {
"200": {
description: "OK",
},
},
},
},
},
components: {
schemas: {
# Anything here will get overwritten by standalone JSON Schema objects
# if the keys are duplicated.
#
# Generally, anything that goes in a response/request body should have a
# schema over in the types directory.
token: {
type: "string",
description: "An opaque token previously obtained from the service.",
},
},
responses: {
bad_request: {
description: "Bad Request",
content: contenttype("error"),
},
oops: {
description: "Internal Server Error",
content: contenttype("error"),
},
not_found: {
description: "Not Found",
content: contenttype("error"),
},
# Not expressible in OpenAPI:
#method_not_allowed: {
# description: "Method Not Allowed",
# headers: {
# Allow: header_ref("Allow"),
# },
# content: contenttype("error"),
#},
unsupported_media_type: {
description: "Unsupported Media Type",
content: contenttype("error"),
},
},
parameters: {
digest: {
description: "OCI-compatible digest of a referred object.",
name: "digest",
in: "path",
schema: schema_ref("digest"),
required: true,
},
update_operation_id: {
description: "UUID of the update operation to delete.",
name: "id",
in: "path",
schema: {
type: "string",
format: "uuid",
},
required: true,
}
},
headers: {
# Only used for 415 Method Not Allowed responses, which aren't expressible in OpenAPI.
#Allow: {
# description: "TKTK",
# style: "simple",
# schema: { type: "string" },
# required: true,
#},
"Clair-Error": {
description: "This is a trailer containing any errors encountered while writing the response.",
style: "simple",
schema: { type: "string" },
},
Etag: {
description: "HTTP [ETag header](https://httpwg.org/specs/rfc9110.html#field.etag)",
style: "simple",
schema: { type: "string" }
},
Link: {
description: "Web Linking [Link header](https://httpwg.org/specs/rfc8288.html#header)",
style: "simple",
schema: { type: "string" },
},
Location: {
description: "HTTP [Location header](https://httpwg.org/specs/rfc9110.html#field.location)",
style: "simple",
required: true,
schema: { type: "string" },
},
},
securitySchemes: {
PSK: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT with preshared key and allow-listed issuers",
description: "Clair's authentication scheme.\n\nThis is a [JWT](https://datatracker.ietf.org/doc/html/rfc7519) signed with a configured pre-shared key containing an allowlisted `iss` claim.",
},
},
},
}
|
# And now, a bunch of fixups:
def add_tags: # Match the path prefixes and add default tags.
.paths |= with_entries(
(
if (.key|contains("internal")) then
"internal"
elif (.key|startswith($path_index)) then
"indexer"
elif (.key|startswith($path_match)) then
"matcher"
elif (.key|startswith($path_notif)) then
"notifier"
else
""
end
) as $k |
if ($k=="") then
.
else
(.value[]|select(objects)) |= . + {
tags: ((.tags//[]) + [$k]),
}
end
)
;
def operation_metadata: # Slipstream some metadata into response objects.
{
AffectedManifests: {
summary: "Retrieve Manifests Affected by a Vulnerability",
description: "The provided vulnerability summaries are attempted to be run \"backwards\" through the indexer to produce a set of manifests.",
},
DeleteManifest: {
summary: "Delete an Indexed Manifest",
description: "Given a Manifest's content addressable hash, any data related to it will be removed it it exists.",
},
DeleteManifests: {
summary: "Delete Indexed Manifests",
description: "Given a Manifest's content addressable hash, any data related to it will be removed if it exists.",
},
DeleteNotification: {
summary: "Delete a Notification Set",
description: "Issues a delete of the provided notification ID and all associated notifications.\nAfter this delete clients will no longer be able to retrieve notifications.",
},
DeleteUpdateOperation: {
summary: "Delete an Update Operation",
description: "Issues a delete of the provided Update Operation ID and all associated data.\nAfter this delete clients will no longer be able to generate a diff against this Update Operation.",
},
GetIndexReport: {
summary: "Retrieve the IndexReport for a Manifest",
description: "Given a Manifest's content addressable hash, an IndexReport will be retrieved if it exists.",
},
GetNotification: {
summary: "Retrieve Pages of a Notification Set",
description: "By performing a GET with an id as a path parameter, the client will retrieve a paginated response of notification objects.",
},
GetUpdateDiff: {
summary: "Retrieve Vulnerability Changes Between Two Update Operations",
description: "Given IDs for two Update Operations, this will return the difference between them. This is used in the notification flow.",
},
GetUpdateOperation: {
summary: "Retrieve Update Operations",
description: "Retrive all known or just the latest Update Operations.",
},
GetVulnerabilityReport: {
summary: "Retrieve a VulnerabilityReport for a Manifest",
description: "Given a Manifest's content addressable hash a VulnerabilityReport will be created. The Manifest **must** have been Indexed first via the Index endpoint.",
},
Index: {
summary: "Index a Manifest",
description: "By submitting a Manifest object to this endpoint Clair will fetch the layers, scan each layer's contents, and provide an index of discovered packages, repository and distribution information.",
},
IndexState: {
summary: "Report the Indexer's State",
description: "The index state endpoint returns a json structure indicating the indexer's internal configuration state.\nA client may be interested in this as a signal that manifests may need to be re-indexed.",
},
} as $m |
( .paths[][] | select(objects) ) |= (
.operationId as $id |
($m[$id]?) as $m |
if ($m) then
. + $m
else
.
end
)
;
sort_paths |
content_defaults |
add_tags |
operation_metadata |
cli_hints |
.