@kyverno/backstage-plugin-policy-reporter-backend 2.1.4 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @kyverno/backstage-plugin-policy-reporter-backend
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ee217ed: Update to Backstage versions 1.43.0
|
|
8
|
+
- e713e1f: Migrate to OpenAPI-generated ApiClient, typed Express router, and common types instead of manual definitions.
|
|
9
|
+
|
|
10
|
+
**BREAKING:** The backend endpoint now accepts environment entity as a query parameter instead of a path parameter.
|
|
11
|
+
|
|
12
|
+
Frontend and backend must be updated simultaneously to maintain compatibility.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [44376bd]
|
|
17
|
+
- Updated dependencies [ee217ed]
|
|
18
|
+
- Updated dependencies [e713e1f]
|
|
19
|
+
- @kyverno/backstage-plugin-policy-reporter-common@2.1.0
|
|
20
|
+
|
|
3
21
|
## 2.1.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendOpenapiUtils = require('@backstage/backend-openapi-utils');
|
|
4
|
+
|
|
5
|
+
const spec = {
|
|
6
|
+
openapi: "3.0.3",
|
|
7
|
+
info: {
|
|
8
|
+
title: "policy-reporter",
|
|
9
|
+
description: "Backend API for the Backstage Policy Reporter plugin",
|
|
10
|
+
version: "1.0.0"
|
|
11
|
+
},
|
|
12
|
+
paths: {
|
|
13
|
+
"/namespaced-resources/results": {
|
|
14
|
+
get: {
|
|
15
|
+
summary: "Get namespaced policy results",
|
|
16
|
+
description: "Retrieves policy results for a specific environment with optional filtering and pagination",
|
|
17
|
+
operationId: "getNamespacedResults",
|
|
18
|
+
parameters: [
|
|
19
|
+
{
|
|
20
|
+
name: "environment",
|
|
21
|
+
in: "query",
|
|
22
|
+
required: true,
|
|
23
|
+
description: "The environment entity reference (URL encoded)",
|
|
24
|
+
schema: {
|
|
25
|
+
type: "string",
|
|
26
|
+
example: "default/component/my-service"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "sources",
|
|
31
|
+
in: "query",
|
|
32
|
+
description: "Filter by a list of sources",
|
|
33
|
+
schema: {
|
|
34
|
+
type: "array",
|
|
35
|
+
items: {
|
|
36
|
+
type: "string"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
style: "form",
|
|
40
|
+
explode: true
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "namespaces",
|
|
44
|
+
in: "query",
|
|
45
|
+
description: "Filter by a list of namespaces",
|
|
46
|
+
schema: {
|
|
47
|
+
type: "array",
|
|
48
|
+
items: {
|
|
49
|
+
type: "string"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
style: "form",
|
|
53
|
+
explode: true
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "kinds",
|
|
57
|
+
in: "query",
|
|
58
|
+
description: "Filter by a list of Kubernetes resource kinds",
|
|
59
|
+
schema: {
|
|
60
|
+
type: "array",
|
|
61
|
+
items: {
|
|
62
|
+
type: "string"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
style: "form",
|
|
66
|
+
explode: true
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "resources",
|
|
70
|
+
in: "query",
|
|
71
|
+
description: "Filter by a list of resources",
|
|
72
|
+
schema: {
|
|
73
|
+
type: "array",
|
|
74
|
+
items: {
|
|
75
|
+
type: "string"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
style: "form",
|
|
79
|
+
explode: true
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "categories",
|
|
83
|
+
in: "query",
|
|
84
|
+
description: "Filter by a list of categories",
|
|
85
|
+
schema: {
|
|
86
|
+
type: "array",
|
|
87
|
+
items: {
|
|
88
|
+
type: "string"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
style: "form",
|
|
92
|
+
explode: true
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "policies",
|
|
96
|
+
in: "query",
|
|
97
|
+
description: "Filter by a list of policies",
|
|
98
|
+
schema: {
|
|
99
|
+
type: "array",
|
|
100
|
+
items: {
|
|
101
|
+
type: "string"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
style: "form",
|
|
105
|
+
explode: true
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "status",
|
|
109
|
+
in: "query",
|
|
110
|
+
description: "Filter by policy result status",
|
|
111
|
+
schema: {
|
|
112
|
+
type: "array",
|
|
113
|
+
items: {
|
|
114
|
+
$ref: "#/components/schemas/Status"
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
style: "form",
|
|
118
|
+
explode: true
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "severities",
|
|
122
|
+
in: "query",
|
|
123
|
+
description: "Filter by severity levels",
|
|
124
|
+
schema: {
|
|
125
|
+
type: "array",
|
|
126
|
+
items: {
|
|
127
|
+
$ref: "#/components/schemas/Severity"
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
style: "form",
|
|
131
|
+
explode: true
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "search",
|
|
135
|
+
in: "query",
|
|
136
|
+
description: "Search string to filter results",
|
|
137
|
+
schema: {
|
|
138
|
+
type: "string"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "labels",
|
|
143
|
+
in: "query",
|
|
144
|
+
description: "Filter by label-value pairs",
|
|
145
|
+
schema: {
|
|
146
|
+
type: "array",
|
|
147
|
+
items: {
|
|
148
|
+
type: "string"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
style: "form",
|
|
152
|
+
explode: true
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "page",
|
|
156
|
+
in: "query",
|
|
157
|
+
description: "Requested list page number",
|
|
158
|
+
schema: {
|
|
159
|
+
type: "integer",
|
|
160
|
+
minimum: 1,
|
|
161
|
+
default: 1
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: "offset",
|
|
166
|
+
in: "query",
|
|
167
|
+
description: "Number of results per page",
|
|
168
|
+
schema: {
|
|
169
|
+
type: "integer",
|
|
170
|
+
minimum: 1,
|
|
171
|
+
maximum: 100,
|
|
172
|
+
default: 20
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "direction",
|
|
177
|
+
in: "query",
|
|
178
|
+
description: "Sort direction for results",
|
|
179
|
+
schema: {
|
|
180
|
+
$ref: "#/components/schemas/Direction"
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
responses: {
|
|
185
|
+
"200": {
|
|
186
|
+
description: "Policy results retrieved successfully",
|
|
187
|
+
content: {
|
|
188
|
+
"application/json": {
|
|
189
|
+
schema: {
|
|
190
|
+
$ref: "#/components/schemas/ResultList"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"400": {
|
|
196
|
+
description: "Bad request - invalid entityRef or missing annotation",
|
|
197
|
+
content: {
|
|
198
|
+
"application/json": {
|
|
199
|
+
schema: {
|
|
200
|
+
$ref: "#/components/schemas/RequestError"
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
"500": {
|
|
206
|
+
description: "Internal server error - failed to fetch policies",
|
|
207
|
+
content: {
|
|
208
|
+
"application/json": {
|
|
209
|
+
schema: {
|
|
210
|
+
$ref: "#/components/schemas/RequestError"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
components: {
|
|
220
|
+
schemas: {
|
|
221
|
+
Status: {
|
|
222
|
+
type: "string",
|
|
223
|
+
enum: ["fail", "skip", "pass", "warn", "error", "summary"],
|
|
224
|
+
description: "Policy result status"
|
|
225
|
+
},
|
|
226
|
+
Severity: {
|
|
227
|
+
type: "string",
|
|
228
|
+
enum: ["unknown", "info", "low", "medium", "high", "critical"],
|
|
229
|
+
description: "Policy result severity level"
|
|
230
|
+
},
|
|
231
|
+
Direction: {
|
|
232
|
+
type: "string",
|
|
233
|
+
enum: ["asc", "desc"],
|
|
234
|
+
description: "Sort direction"
|
|
235
|
+
},
|
|
236
|
+
Filter: {
|
|
237
|
+
type: "object",
|
|
238
|
+
description: "Filter options for policy results",
|
|
239
|
+
properties: {
|
|
240
|
+
sources: {
|
|
241
|
+
type: "array",
|
|
242
|
+
items: {
|
|
243
|
+
type: "string"
|
|
244
|
+
},
|
|
245
|
+
description: "Filter by a list of sources"
|
|
246
|
+
},
|
|
247
|
+
namespaces: {
|
|
248
|
+
type: "array",
|
|
249
|
+
items: {
|
|
250
|
+
type: "string"
|
|
251
|
+
},
|
|
252
|
+
description: "Filter by a list of namespaces"
|
|
253
|
+
},
|
|
254
|
+
kinds: {
|
|
255
|
+
type: "array",
|
|
256
|
+
items: {
|
|
257
|
+
type: "string"
|
|
258
|
+
},
|
|
259
|
+
description: "Filter by a list of kinds"
|
|
260
|
+
},
|
|
261
|
+
resources: {
|
|
262
|
+
type: "array",
|
|
263
|
+
items: {
|
|
264
|
+
type: "string"
|
|
265
|
+
},
|
|
266
|
+
description: "Filter by a list of resources"
|
|
267
|
+
},
|
|
268
|
+
categories: {
|
|
269
|
+
type: "array",
|
|
270
|
+
items: {
|
|
271
|
+
type: "string"
|
|
272
|
+
},
|
|
273
|
+
description: "Filter by a list of categories"
|
|
274
|
+
},
|
|
275
|
+
policies: {
|
|
276
|
+
type: "array",
|
|
277
|
+
items: {
|
|
278
|
+
type: "string"
|
|
279
|
+
},
|
|
280
|
+
description: "Filter by a list of policies"
|
|
281
|
+
},
|
|
282
|
+
status: {
|
|
283
|
+
type: "array",
|
|
284
|
+
items: {
|
|
285
|
+
$ref: "#/components/schemas/Status"
|
|
286
|
+
},
|
|
287
|
+
description: "Filter by a list of status"
|
|
288
|
+
},
|
|
289
|
+
severities: {
|
|
290
|
+
type: "array",
|
|
291
|
+
items: {
|
|
292
|
+
$ref: "#/components/schemas/Severity"
|
|
293
|
+
},
|
|
294
|
+
description: "Filter by a list of severities"
|
|
295
|
+
},
|
|
296
|
+
search: {
|
|
297
|
+
type: "string",
|
|
298
|
+
description: "Filter by search string"
|
|
299
|
+
},
|
|
300
|
+
labels: {
|
|
301
|
+
type: "array",
|
|
302
|
+
items: {
|
|
303
|
+
type: "string"
|
|
304
|
+
},
|
|
305
|
+
description: "Filter by label-value pairs"
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
Pagination: {
|
|
310
|
+
type: "object",
|
|
311
|
+
description: "Pagination options for results",
|
|
312
|
+
properties: {
|
|
313
|
+
page: {
|
|
314
|
+
type: "integer",
|
|
315
|
+
minimum: 1,
|
|
316
|
+
default: 1,
|
|
317
|
+
description: "Requested list page number"
|
|
318
|
+
},
|
|
319
|
+
offset: {
|
|
320
|
+
type: "integer",
|
|
321
|
+
minimum: 1,
|
|
322
|
+
maximum: 100,
|
|
323
|
+
default: 20,
|
|
324
|
+
description: "Number of results per page"
|
|
325
|
+
},
|
|
326
|
+
sortBy: {
|
|
327
|
+
type: "array",
|
|
328
|
+
items: {
|
|
329
|
+
type: "string"
|
|
330
|
+
},
|
|
331
|
+
description: "Fields to sort by"
|
|
332
|
+
},
|
|
333
|
+
direction: {
|
|
334
|
+
$ref: "#/components/schemas/Direction",
|
|
335
|
+
description: "Sort direction for results"
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
ResultList: {
|
|
340
|
+
type: "object",
|
|
341
|
+
required: ["items", "count"],
|
|
342
|
+
properties: {
|
|
343
|
+
items: {
|
|
344
|
+
type: "array",
|
|
345
|
+
items: {
|
|
346
|
+
$ref: "#/components/schemas/ListResult"
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
count: {
|
|
350
|
+
type: "integer",
|
|
351
|
+
description: "Total number of results"
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
ListResult: {
|
|
356
|
+
type: "object",
|
|
357
|
+
required: [
|
|
358
|
+
"id",
|
|
359
|
+
"namespace",
|
|
360
|
+
"kind",
|
|
361
|
+
"name",
|
|
362
|
+
"resourceId",
|
|
363
|
+
"message",
|
|
364
|
+
"policy",
|
|
365
|
+
"rule",
|
|
366
|
+
"status",
|
|
367
|
+
"severity",
|
|
368
|
+
"timestamp",
|
|
369
|
+
"properties"
|
|
370
|
+
],
|
|
371
|
+
properties: {
|
|
372
|
+
id: {
|
|
373
|
+
type: "string",
|
|
374
|
+
description: "Unique identifier for the result"
|
|
375
|
+
},
|
|
376
|
+
namespace: {
|
|
377
|
+
type: "string",
|
|
378
|
+
description: "Kubernetes namespace"
|
|
379
|
+
},
|
|
380
|
+
kind: {
|
|
381
|
+
type: "string",
|
|
382
|
+
description: "Kubernetes resource kind"
|
|
383
|
+
},
|
|
384
|
+
name: {
|
|
385
|
+
type: "string",
|
|
386
|
+
description: "Resource name"
|
|
387
|
+
},
|
|
388
|
+
resourceId: {
|
|
389
|
+
type: "string",
|
|
390
|
+
description: "Unique resource identifier"
|
|
391
|
+
},
|
|
392
|
+
message: {
|
|
393
|
+
type: "string",
|
|
394
|
+
description: "Policy result message"
|
|
395
|
+
},
|
|
396
|
+
policy: {
|
|
397
|
+
type: "string",
|
|
398
|
+
description: "Policy name"
|
|
399
|
+
},
|
|
400
|
+
rule: {
|
|
401
|
+
type: "string",
|
|
402
|
+
description: "Policy rule name"
|
|
403
|
+
},
|
|
404
|
+
status: {
|
|
405
|
+
$ref: "#/components/schemas/Status"
|
|
406
|
+
},
|
|
407
|
+
severity: {
|
|
408
|
+
$ref: "#/components/schemas/Severity"
|
|
409
|
+
},
|
|
410
|
+
timestamp: {
|
|
411
|
+
type: "integer",
|
|
412
|
+
format: "int64",
|
|
413
|
+
description: "Unix timestamp of the result"
|
|
414
|
+
},
|
|
415
|
+
properties: {
|
|
416
|
+
type: "object",
|
|
417
|
+
additionalProperties: {
|
|
418
|
+
type: "string"
|
|
419
|
+
},
|
|
420
|
+
description: "Additional key-value properties"
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
RequestError: {
|
|
425
|
+
type: "object",
|
|
426
|
+
required: ["error"],
|
|
427
|
+
properties: {
|
|
428
|
+
error: {
|
|
429
|
+
type: "string",
|
|
430
|
+
description: "Error message"
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
const createOpenApiRouter = async (options) => backendOpenapiUtils.createValidatedOpenApiRouterFromGeneratedEndpointMap(
|
|
438
|
+
spec,
|
|
439
|
+
options
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
exports.createOpenApiRouter = createOpenApiRouter;
|
|
443
|
+
exports.spec = spec;
|
|
444
|
+
//# sourceMappingURL=router.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.cjs.js","sources":["../../../../src/schema/openapi/generated/router.ts"],"sourcesContent":["//\n\n// ******************************************************************\n// * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. *\n// ******************************************************************\nimport { createValidatedOpenApiRouterFromGeneratedEndpointMap } from '@backstage/backend-openapi-utils';\nimport { EndpointMap } from './apis';\n\nexport const spec = {\n openapi: '3.0.3',\n info: {\n title: 'policy-reporter',\n description: 'Backend API for the Backstage Policy Reporter plugin',\n version: '1.0.0',\n },\n paths: {\n '/namespaced-resources/results': {\n get: {\n summary: 'Get namespaced policy results',\n description:\n 'Retrieves policy results for a specific environment with optional filtering and pagination',\n operationId: 'getNamespacedResults',\n parameters: [\n {\n name: 'environment',\n in: 'query',\n required: true,\n description: 'The environment entity reference (URL encoded)',\n schema: {\n type: 'string',\n example: 'default/component/my-service',\n },\n },\n {\n name: 'sources',\n in: 'query',\n description: 'Filter by a list of sources',\n schema: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n style: 'form',\n explode: true,\n },\n {\n name: 'namespaces',\n in: 'query',\n description: 'Filter by a list of namespaces',\n schema: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n style: 'form',\n explode: true,\n },\n {\n name: 'kinds',\n in: 'query',\n description: 'Filter by a list of Kubernetes resource kinds',\n schema: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n style: 'form',\n explode: true,\n },\n {\n name: 'resources',\n in: 'query',\n description: 'Filter by a list of resources',\n schema: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n style: 'form',\n explode: true,\n },\n {\n name: 'categories',\n in: 'query',\n description: 'Filter by a list of categories',\n schema: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n style: 'form',\n explode: true,\n },\n {\n name: 'policies',\n in: 'query',\n description: 'Filter by a list of policies',\n schema: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n style: 'form',\n explode: true,\n },\n {\n name: 'status',\n in: 'query',\n description: 'Filter by policy result status',\n schema: {\n type: 'array',\n items: {\n $ref: '#/components/schemas/Status',\n },\n },\n style: 'form',\n explode: true,\n },\n {\n name: 'severities',\n in: 'query',\n description: 'Filter by severity levels',\n schema: {\n type: 'array',\n items: {\n $ref: '#/components/schemas/Severity',\n },\n },\n style: 'form',\n explode: true,\n },\n {\n name: 'search',\n in: 'query',\n description: 'Search string to filter results',\n schema: {\n type: 'string',\n },\n },\n {\n name: 'labels',\n in: 'query',\n description: 'Filter by label-value pairs',\n schema: {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n style: 'form',\n explode: true,\n },\n {\n name: 'page',\n in: 'query',\n description: 'Requested list page number',\n schema: {\n type: 'integer',\n minimum: 1,\n default: 1,\n },\n },\n {\n name: 'offset',\n in: 'query',\n description: 'Number of results per page',\n schema: {\n type: 'integer',\n minimum: 1,\n maximum: 100,\n default: 20,\n },\n },\n {\n name: 'direction',\n in: 'query',\n description: 'Sort direction for results',\n schema: {\n $ref: '#/components/schemas/Direction',\n },\n },\n ],\n responses: {\n '200': {\n description: 'Policy results retrieved successfully',\n content: {\n 'application/json': {\n schema: {\n $ref: '#/components/schemas/ResultList',\n },\n },\n },\n },\n '400': {\n description:\n 'Bad request - invalid entityRef or missing annotation',\n content: {\n 'application/json': {\n schema: {\n $ref: '#/components/schemas/RequestError',\n },\n },\n },\n },\n '500': {\n description: 'Internal server error - failed to fetch policies',\n content: {\n 'application/json': {\n schema: {\n $ref: '#/components/schemas/RequestError',\n },\n },\n },\n },\n },\n },\n },\n },\n components: {\n schemas: {\n Status: {\n type: 'string',\n enum: ['fail', 'skip', 'pass', 'warn', 'error', 'summary'],\n description: 'Policy result status',\n },\n Severity: {\n type: 'string',\n enum: ['unknown', 'info', 'low', 'medium', 'high', 'critical'],\n description: 'Policy result severity level',\n },\n Direction: {\n type: 'string',\n enum: ['asc', 'desc'],\n description: 'Sort direction',\n },\n Filter: {\n type: 'object',\n description: 'Filter options for policy results',\n properties: {\n sources: {\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Filter by a list of sources',\n },\n namespaces: {\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Filter by a list of namespaces',\n },\n kinds: {\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Filter by a list of kinds',\n },\n resources: {\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Filter by a list of resources',\n },\n categories: {\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Filter by a list of categories',\n },\n policies: {\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Filter by a list of policies',\n },\n status: {\n type: 'array',\n items: {\n $ref: '#/components/schemas/Status',\n },\n description: 'Filter by a list of status',\n },\n severities: {\n type: 'array',\n items: {\n $ref: '#/components/schemas/Severity',\n },\n description: 'Filter by a list of severities',\n },\n search: {\n type: 'string',\n description: 'Filter by search string',\n },\n labels: {\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Filter by label-value pairs',\n },\n },\n },\n Pagination: {\n type: 'object',\n description: 'Pagination options for results',\n properties: {\n page: {\n type: 'integer',\n minimum: 1,\n default: 1,\n description: 'Requested list page number',\n },\n offset: {\n type: 'integer',\n minimum: 1,\n maximum: 100,\n default: 20,\n description: 'Number of results per page',\n },\n sortBy: {\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Fields to sort by',\n },\n direction: {\n $ref: '#/components/schemas/Direction',\n description: 'Sort direction for results',\n },\n },\n },\n ResultList: {\n type: 'object',\n required: ['items', 'count'],\n properties: {\n items: {\n type: 'array',\n items: {\n $ref: '#/components/schemas/ListResult',\n },\n },\n count: {\n type: 'integer',\n description: 'Total number of results',\n },\n },\n },\n ListResult: {\n type: 'object',\n required: [\n 'id',\n 'namespace',\n 'kind',\n 'name',\n 'resourceId',\n 'message',\n 'policy',\n 'rule',\n 'status',\n 'severity',\n 'timestamp',\n 'properties',\n ],\n properties: {\n id: {\n type: 'string',\n description: 'Unique identifier for the result',\n },\n namespace: {\n type: 'string',\n description: 'Kubernetes namespace',\n },\n kind: {\n type: 'string',\n description: 'Kubernetes resource kind',\n },\n name: {\n type: 'string',\n description: 'Resource name',\n },\n resourceId: {\n type: 'string',\n description: 'Unique resource identifier',\n },\n message: {\n type: 'string',\n description: 'Policy result message',\n },\n policy: {\n type: 'string',\n description: 'Policy name',\n },\n rule: {\n type: 'string',\n description: 'Policy rule name',\n },\n status: {\n $ref: '#/components/schemas/Status',\n },\n severity: {\n $ref: '#/components/schemas/Severity',\n },\n timestamp: {\n type: 'integer',\n format: 'int64',\n description: 'Unix timestamp of the result',\n },\n properties: {\n type: 'object',\n additionalProperties: {\n type: 'string',\n },\n description: 'Additional key-value properties',\n },\n },\n },\n RequestError: {\n type: 'object',\n required: ['error'],\n properties: {\n error: {\n type: 'string',\n description: 'Error message',\n },\n },\n },\n },\n },\n} as const;\nexport const createOpenApiRouter = async (\n options?: Parameters<\n typeof createValidatedOpenApiRouterFromGeneratedEndpointMap\n >['1'],\n) =>\n createValidatedOpenApiRouterFromGeneratedEndpointMap<EndpointMap>(\n spec,\n options,\n );\n"],"names":["createValidatedOpenApiRouterFromGeneratedEndpointMap"],"mappings":";;;;AAQO,MAAM,IAAO,GAAA;AAAA,EAClB,OAAS,EAAA,OAAA;AAAA,EACT,IAAM,EAAA;AAAA,IACJ,KAAO,EAAA,iBAAA;AAAA,IACP,WAAa,EAAA,sDAAA;AAAA,IACb,OAAS,EAAA;AAAA,GACX;AAAA,EACA,KAAO,EAAA;AAAA,IACL,+BAAiC,EAAA;AAAA,MAC/B,GAAK,EAAA;AAAA,QACH,OAAS,EAAA,+BAAA;AAAA,QACT,WACE,EAAA,4FAAA;AAAA,QACF,WAAa,EAAA,sBAAA;AAAA,QACb,UAAY,EAAA;AAAA,UACV;AAAA,YACE,IAAM,EAAA,aAAA;AAAA,YACN,EAAI,EAAA,OAAA;AAAA,YACJ,QAAU,EAAA,IAAA;AAAA,YACV,WAAa,EAAA,gDAAA;AAAA,YACb,MAAQ,EAAA;AAAA,cACN,IAAM,EAAA,QAAA;AAAA,cACN,OAAS,EAAA;AAAA;AACX,WACF;AAAA,UACA;AAAA,YACE,IAAM,EAAA,SAAA;AAAA,YACN,EAAI,EAAA,OAAA;AAAA,YACJ,WAAa,EAAA,6BAAA;AAAA,YACb,MAAQ,EAAA;AAAA,cACN,IAAM,EAAA,OAAA;AAAA,cACN,KAAO,EAAA;AAAA,gBACL,IAAM,EAAA;AAAA;AACR,aACF;AAAA,YACA,KAAO,EAAA,MAAA;AAAA,YACP,OAAS,EAAA;AAAA,WACX;AAAA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AAA,YACN,WAAa,EAAA;AAAA,WACf;AAAA,UACA,MAAQ,EAAA;AAAA,YACN,IAAM,EAAA,QAAA;AAAA,YACN,WAAa,EAAA;AAAA,WACf;AAAA,UACA,IAAM,EAAA;AAAA,YACJ,IAAM,EAAA,QAAA;AAAA,YACN,WAAa,EAAA;AAAA,WACf;AAAA,UACA,MAAQ,EAAA;AAAA,YACN,IAAM,EAAA;AAAA,WACR;AAAA,UACA,QAAU,EAAA;AAAA,YACR,IAAM,EAAA;AAAA,WACR;AAAA,UACA,SAAW,EAAA;AAAA,YACT,IAAM,EAAA,SAAA;AAAA,YACN,MAAQ,EAAA,OAAA;AAAA,YACR,WAAa,EAAA;AAAA,WACf;AAAA,UACA,UAAY,EAAA;AAAA,YACV,IAAM,EAAA,QAAA;AAAA,YACN,oBAAsB,EAAA;AAAA,cACpB,IAAM,EAAA;AAAA,aACR;AAAA,YACA,WAAa,EAAA;AAAA;AACf;AACF,OACF;AAAA,MACA,YAAc,EAAA;AAAA,QACZ,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,OAAO,CAAA;AAAA,QAClB,UAAY,EAAA;AAAA,UACV,KAAO,EAAA;AAAA,YACL,IAAM,EAAA,QAAA;AAAA,YACN,WAAa,EAAA;AAAA;AACf;AACF;AACF;AACF;AAEJ;AACa,MAAA,mBAAA,GAAsB,OACjC,OAIA,KAAAA,wEAAA;AAAA,EACE,IAAA;AAAA,EACA;AACF;;;;;"}
|
|
@@ -1,59 +1,74 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var express = require('express');
|
|
4
|
-
var Router = require('express-promise-router');
|
|
5
4
|
var backstagePluginPolicyReporterCommon = require('@kyverno/backstage-plugin-policy-reporter-common');
|
|
6
5
|
var rootHttpRouter = require('@backstage/backend-defaults/rootHttpRouter');
|
|
6
|
+
var router = require('../schema/openapi/generated/router.cjs.js');
|
|
7
|
+
var parser = require('uri-template');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
10
|
|
|
11
|
+
function _interopNamespaceCompat(e) {
|
|
12
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
13
|
+
var n = Object.create(null);
|
|
14
|
+
if (e) {
|
|
15
|
+
Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
10
29
|
var express__default = /*#__PURE__*/_interopDefaultCompat(express);
|
|
11
|
-
var
|
|
30
|
+
var parser__namespace = /*#__PURE__*/_interopNamespaceCompat(parser);
|
|
12
31
|
|
|
13
32
|
const ensureTrailingSlash = (url) => url.endsWith("/") ? url : `${url}/`;
|
|
14
33
|
async function createRouter(options) {
|
|
15
34
|
const { logger, config, catalogService, authService } = options;
|
|
16
|
-
const router =
|
|
17
|
-
router.use(express__default.default.json());
|
|
18
|
-
router.get(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
const router$1 = await router.createOpenApiRouter();
|
|
36
|
+
router$1.use(express__default.default.json());
|
|
37
|
+
router$1.get("/namespaced-resources/results", async (request, response) => {
|
|
38
|
+
const entityRef = decodeURIComponent(request.query.environment);
|
|
39
|
+
const credentials = await authService.getOwnServiceCredentials();
|
|
40
|
+
const entity = await catalogService.getEntityByRef(entityRef, {
|
|
41
|
+
credentials
|
|
42
|
+
});
|
|
43
|
+
if (!entity)
|
|
44
|
+
return response.status(400).json({ error: "Invalid entityRef" });
|
|
45
|
+
const kyvernoEndpoint = entity?.metadata.annotations?.[backstagePluginPolicyReporterCommon.KYVERNO_ENDPOINT_ANNOTATION];
|
|
46
|
+
if (!kyvernoEndpoint)
|
|
47
|
+
return response.status(400).json({ error: `Entity missing 'kyverno.io/endpoint' annotation` });
|
|
48
|
+
const uriTemplate = `v1/namespaced-resources/results{?sources*,namespaces*,kinds*,resources*,categories*,policies*,status*,severities*,search,labels*,page,offset,direction}`;
|
|
49
|
+
const uri = parser__namespace.parse(uriTemplate).expand({
|
|
50
|
+
...request.query
|
|
51
|
+
});
|
|
52
|
+
const policyResponse = await fetch(
|
|
53
|
+
`${ensureTrailingSlash(kyvernoEndpoint)}${uri}`,
|
|
54
|
+
{
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json"
|
|
57
|
+
},
|
|
58
|
+
method: "GET"
|
|
29
59
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
60
|
+
);
|
|
61
|
+
if (!policyResponse.ok) {
|
|
62
|
+
return response.status(500).json({
|
|
63
|
+
error: `Failed to fetch policies ${policyResponse.status} ${policyResponse.statusText}`
|
|
34
64
|
});
|
|
35
|
-
if (!entity)
|
|
36
|
-
return response.status(400).json({ error: "Invalid entityRef" });
|
|
37
|
-
const kyvernoEndpoint = entity?.metadata.annotations?.[backstagePluginPolicyReporterCommon.KYVERNO_ENDPOINT_ANNOTATION];
|
|
38
|
-
if (!kyvernoEndpoint)
|
|
39
|
-
return response.status(400).json({ error: `Entity missing 'kyverno.io/endpoint' annotation` });
|
|
40
|
-
const policyResponse = await fetch(
|
|
41
|
-
`${ensureTrailingSlash(
|
|
42
|
-
kyvernoEndpoint
|
|
43
|
-
)}v1/namespaced-resources/results?${urlParams.toString()}`
|
|
44
|
-
);
|
|
45
|
-
if (!policyResponse.ok) {
|
|
46
|
-
return response.status(500).json({
|
|
47
|
-
error: `Failed to fetch policies: ${policyResponse.statusText}`
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
const result = await policyResponse.json();
|
|
51
|
-
return response.status(200).json(result);
|
|
52
65
|
}
|
|
53
|
-
|
|
66
|
+
const result = await policyResponse.json();
|
|
67
|
+
return response.status(200).json(result);
|
|
68
|
+
});
|
|
54
69
|
const middleware = rootHttpRouter.MiddlewareFactory.create({ logger, config });
|
|
55
|
-
router.use(middleware.error());
|
|
56
|
-
return router;
|
|
70
|
+
router$1.use(middleware.error());
|
|
71
|
+
return router$1;
|
|
57
72
|
}
|
|
58
73
|
|
|
59
74
|
exports.createRouter = createRouter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.cjs.js","sources":["../../src/service/router.ts"],"sourcesContent":["import { AuthService, RootConfigService } from '@backstage/backend-plugin-api';\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport express from 'express';\nimport
|
|
1
|
+
{"version":3,"file":"router.cjs.js","sources":["../../src/service/router.ts"],"sourcesContent":["import { AuthService, RootConfigService } from '@backstage/backend-plugin-api';\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport express from 'express';\nimport { KYVERNO_ENDPOINT_ANNOTATION } from '@kyverno/backstage-plugin-policy-reporter-common';\nimport { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\nimport { createOpenApiRouter } from '../schema/openapi';\n\nimport * as parser from 'uri-template';\n\nexport interface RouterOptions {\n logger: LoggerService;\n config: RootConfigService;\n catalogService: CatalogService;\n authService: AuthService;\n}\n\nconst ensureTrailingSlash = (url: string) =>\n url.endsWith('/') ? url : `${url}/`;\n\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { logger, config, catalogService, authService } = options;\n\n const router = await createOpenApiRouter();\n router.use(express.json());\n\n router.get('/namespaced-resources/results', async (request, response) => {\n // Get entityRef from query.\n const entityRef = decodeURIComponent(request.query.environment);\n\n const credentials = await authService.getOwnServiceCredentials();\n\n const entity = await catalogService.getEntityByRef(entityRef, {\n credentials,\n });\n\n if (!entity)\n return response.status(400).json({ error: 'Invalid entityRef' });\n\n const kyvernoEndpoint =\n entity?.metadata.annotations?.[KYVERNO_ENDPOINT_ANNOTATION];\n\n if (!kyvernoEndpoint)\n return response\n .status(400)\n .json({ error: `Entity missing 'kyverno.io/endpoint' annotation` });\n\n const uriTemplate = `v1/namespaced-resources/results{?sources*,namespaces*,kinds*,resources*,categories*,policies*,status*,severities*,search,labels*,page,offset,direction}`;\n\n const uri = parser.parse(uriTemplate).expand({\n ...request.query,\n });\n\n const policyResponse = await fetch(\n `${ensureTrailingSlash(kyvernoEndpoint)}${uri}`,\n {\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'GET',\n },\n );\n\n if (!policyResponse.ok) {\n return response.status(500).json({\n error: `Failed to fetch policies ${policyResponse.status} ${policyResponse.statusText}`,\n });\n }\n\n const result = await policyResponse.json();\n\n return response.status(200).json(result);\n });\n\n const middleware = MiddlewareFactory.create({ logger, config });\n\n router.use(middleware.error());\n return router;\n}\n"],"names":["router","createOpenApiRouter","express","KYVERNO_ENDPOINT_ANNOTATION","parser","MiddlewareFactory"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,mBAAA,GAAsB,CAAC,GAC3B,KAAA,GAAA,CAAI,SAAS,GAAG,CAAA,GAAI,GAAM,GAAA,CAAA,EAAG,GAAG,CAAA,CAAA,CAAA;AAElC,eAAsB,aACpB,OACyB,EAAA;AACzB,EAAA,MAAM,EAAE,MAAA,EAAQ,MAAQ,EAAA,cAAA,EAAgB,aAAgB,GAAA,OAAA;AAExD,EAAM,MAAAA,QAAA,GAAS,MAAMC,0BAAoB,EAAA;AACzC,EAAOD,QAAA,CAAA,GAAA,CAAIE,wBAAQ,CAAA,IAAA,EAAM,CAAA;AAEzB,EAAAF,QAAA,CAAO,GAAI,CAAA,+BAAA,EAAiC,OAAO,OAAA,EAAS,QAAa,KAAA;AAEvE,IAAA,MAAM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M,cAAA,CAAe,IAAK,EAAA;AAEzC,IAAA,OAAO,QAAS,CAAA,MAAA,CAAO,GAAG,CAAA,CAAE,KAAK,MAAM,CAAA;AAAA,GACxC,CAAA;AAED,EAAA,MAAM,aAAaC,gCAAkB,CAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,QAAQ,CAAA;AAE9D,EAAOL,QAAA,CAAA,GAAA,CAAI,UAAW,CAAA,KAAA,EAAO,CAAA;AAC7B,EAAO,OAAAA,QAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyverno/backstage-plugin-policy-reporter-backend",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,27 +38,31 @@
|
|
|
38
38
|
"test": "backstage-cli package test",
|
|
39
39
|
"clean": "backstage-cli package clean",
|
|
40
40
|
"prepack": "backstage-cli package prepack",
|
|
41
|
-
"postpack": "backstage-cli package postpack"
|
|
41
|
+
"postpack": "backstage-cli package postpack",
|
|
42
|
+
"generate": "backstage-repo-tools package schema openapi generate --server --client-package plugins/policy-reporter-common"
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
|
-
"@backstage/backend-defaults": "^0.
|
|
45
|
-
"@backstage/backend-
|
|
46
|
-
"@backstage/
|
|
47
|
-
"@backstage/
|
|
48
|
-
"@
|
|
45
|
+
"@backstage/backend-defaults": "^0.12.1",
|
|
46
|
+
"@backstage/backend-openapi-utils": "^0.6.1",
|
|
47
|
+
"@backstage/backend-plugin-api": "^1.4.3",
|
|
48
|
+
"@backstage/config": "^1.3.4",
|
|
49
|
+
"@backstage/plugin-catalog-node": "^1.19.0",
|
|
50
|
+
"@backstage/repo-tools": "^0.15.2",
|
|
51
|
+
"@kyverno/backstage-plugin-policy-reporter-common": "^2.1.0",
|
|
49
52
|
"@types/express": "*",
|
|
50
53
|
"express": "^4.17.1",
|
|
51
54
|
"express-promise-router": "^4.1.0",
|
|
55
|
+
"uri-template": "^2.0.0",
|
|
52
56
|
"winston": "^3.2.1",
|
|
53
57
|
"yn": "^4.0.0"
|
|
54
58
|
},
|
|
55
59
|
"devDependencies": {
|
|
56
|
-
"@backstage/backend-test-utils": "^1.
|
|
57
|
-
"@backstage/catalog-model": "^1.7.
|
|
58
|
-
"@backstage/cli": "^0.
|
|
59
|
-
"@backstage/plugin-auth-backend": "^0.
|
|
60
|
-
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.
|
|
61
|
-
"@backstage/plugin-catalog-backend": "^1.
|
|
60
|
+
"@backstage/backend-test-utils": "^1.9.0",
|
|
61
|
+
"@backstage/catalog-model": "^1.7.5",
|
|
62
|
+
"@backstage/cli": "^0.34.3",
|
|
63
|
+
"@backstage/plugin-auth-backend": "^0.25.4",
|
|
64
|
+
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.12",
|
|
65
|
+
"@backstage/plugin-catalog-backend": "^3.1.1",
|
|
62
66
|
"@types/supertest": "^2.0.12",
|
|
63
67
|
"better-sqlite3": "^9.0.0",
|
|
64
68
|
"msw": "^1.0.0",
|