@kyverno/backstage-plugin-policy-reporter-common 2.0.6 → 2.1.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,26 @@
1
1
  # @kyverno/backstage-plugin-policy-reporter-common
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 44376bd: Add support for the `backstage.io/kubernetes-namespace` annotation as an alternative for the `kyverno.io/namespace`. This is useful for anyone already using the Kubernetes plugin. The kyverno namespaced annotation will always be the first priority.
8
+
9
+ Add `isPolicyReporterAvailable` helper function to validate if PolicyReporter is configured for an entity.
10
+
11
+ - ee217ed: Update to Backstage versions 1.43.0
12
+ - e713e1f: Migrate to OpenAPI-generated ApiClient, typed Express router, and common types instead of manual definitions.
13
+
14
+ **BREAKING:** The backend endpoint now accepts environment entity as a query parameter instead of a path parameter.
15
+
16
+ Frontend and backend must be updated simultaneously to maintain compatibility.
17
+
18
+ ## 2.0.7
19
+
20
+ ### Patch Changes
21
+
22
+ - 00159f4: New release to validate updated publishing workflow
23
+
3
24
  ## 2.0.6
4
25
 
5
26
  ### Patch Changes
@@ -3,8 +3,10 @@
3
3
  const KYVERNO_RESOURCE_NAME_ANNOTATION = "kyverno.io/resource-name";
4
4
  const KYVERNO_KIND_ANNOTATION = "kyverno.io/kind";
5
5
  const KYVERNO_NAMESPACE_ANNOTATION = "kyverno.io/namespace";
6
+ const KUBERNETES_NAMESPACE_ANNOTATION = "backstage.io/kubernetes-namespace";
6
7
  const KYVERNO_ENDPOINT_ANNOTATION = "kyverno.io/endpoint";
7
8
 
9
+ exports.KUBERNETES_NAMESPACE_ANNOTATION = KUBERNETES_NAMESPACE_ANNOTATION;
8
10
  exports.KYVERNO_ENDPOINT_ANNOTATION = KYVERNO_ENDPOINT_ANNOTATION;
9
11
  exports.KYVERNO_KIND_ANNOTATION = KYVERNO_KIND_ANNOTATION;
10
12
  exports.KYVERNO_NAMESPACE_ANNOTATION = KYVERNO_NAMESPACE_ANNOTATION;
@@ -1 +1 @@
1
- {"version":3,"file":"annotations.cjs.js","sources":["../src/annotations.ts"],"sourcesContent":["// The resource to display policies\nexport const KYVERNO_RESOURCE_NAME_ANNOTATION = 'kyverno.io/resource-name';\n\n// The kind of the resource to display policies\nexport const KYVERNO_KIND_ANNOTATION = 'kyverno.io/kind';\n\n// The namespace of the resource to display policies\nexport const KYVERNO_NAMESPACE_ANNOTATION = 'kyverno.io/namespace';\n\n// The endpoint for the Policy Reporter API\n// EXAMPLE: https://kyverno.io/policy-reporter/api/\nexport const KYVERNO_ENDPOINT_ANNOTATION = 'kyverno.io/endpoint';\n"],"names":[],"mappings":";;AACO,MAAM,gCAAmC,GAAA;AAGzC,MAAM,uBAA0B,GAAA;AAGhC,MAAM,4BAA+B,GAAA;AAIrC,MAAM,2BAA8B,GAAA;;;;;;;"}
1
+ {"version":3,"file":"annotations.cjs.js","sources":["../src/annotations.ts"],"sourcesContent":["// The resource to display policies\nexport const KYVERNO_RESOURCE_NAME_ANNOTATION = 'kyverno.io/resource-name';\n\n// The kind of the resource to display policies\nexport const KYVERNO_KIND_ANNOTATION = 'kyverno.io/kind';\n\n// The namespace of the resource to display policies\nexport const KYVERNO_NAMESPACE_ANNOTATION = 'kyverno.io/namespace';\n\n// The namespace of the resource to display policies\nexport const KUBERNETES_NAMESPACE_ANNOTATION =\n 'backstage.io/kubernetes-namespace';\n\n// The endpoint for the Policy Reporter API\n// EXAMPLE: https://kyverno.io/policy-reporter/api/\nexport const KYVERNO_ENDPOINT_ANNOTATION = 'kyverno.io/endpoint';\n"],"names":[],"mappings":";;AACO,MAAM,gCAAmC,GAAA;AAGzC,MAAM,uBAA0B,GAAA;AAGhC,MAAM,4BAA+B,GAAA;AAGrC,MAAM,+BACX,GAAA;AAIK,MAAM,2BAA8B,GAAA;;;;;;;;"}
@@ -1,7 +1,8 @@
1
1
  const KYVERNO_RESOURCE_NAME_ANNOTATION = "kyverno.io/resource-name";
2
2
  const KYVERNO_KIND_ANNOTATION = "kyverno.io/kind";
3
3
  const KYVERNO_NAMESPACE_ANNOTATION = "kyverno.io/namespace";
4
+ const KUBERNETES_NAMESPACE_ANNOTATION = "backstage.io/kubernetes-namespace";
4
5
  const KYVERNO_ENDPOINT_ANNOTATION = "kyverno.io/endpoint";
5
6
 
6
- export { KYVERNO_ENDPOINT_ANNOTATION, KYVERNO_KIND_ANNOTATION, KYVERNO_NAMESPACE_ANNOTATION, KYVERNO_RESOURCE_NAME_ANNOTATION };
7
+ export { KUBERNETES_NAMESPACE_ANNOTATION, KYVERNO_ENDPOINT_ANNOTATION, KYVERNO_KIND_ANNOTATION, KYVERNO_NAMESPACE_ANNOTATION, KYVERNO_RESOURCE_NAME_ANNOTATION };
7
8
  //# sourceMappingURL=annotations.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"annotations.esm.js","sources":["../src/annotations.ts"],"sourcesContent":["// The resource to display policies\nexport const KYVERNO_RESOURCE_NAME_ANNOTATION = 'kyverno.io/resource-name';\n\n// The kind of the resource to display policies\nexport const KYVERNO_KIND_ANNOTATION = 'kyverno.io/kind';\n\n// The namespace of the resource to display policies\nexport const KYVERNO_NAMESPACE_ANNOTATION = 'kyverno.io/namespace';\n\n// The endpoint for the Policy Reporter API\n// EXAMPLE: https://kyverno.io/policy-reporter/api/\nexport const KYVERNO_ENDPOINT_ANNOTATION = 'kyverno.io/endpoint';\n"],"names":[],"mappings":"AACO,MAAM,gCAAmC,GAAA;AAGzC,MAAM,uBAA0B,GAAA;AAGhC,MAAM,4BAA+B,GAAA;AAIrC,MAAM,2BAA8B,GAAA;;;;"}
1
+ {"version":3,"file":"annotations.esm.js","sources":["../src/annotations.ts"],"sourcesContent":["// The resource to display policies\nexport const KYVERNO_RESOURCE_NAME_ANNOTATION = 'kyverno.io/resource-name';\n\n// The kind of the resource to display policies\nexport const KYVERNO_KIND_ANNOTATION = 'kyverno.io/kind';\n\n// The namespace of the resource to display policies\nexport const KYVERNO_NAMESPACE_ANNOTATION = 'kyverno.io/namespace';\n\n// The namespace of the resource to display policies\nexport const KUBERNETES_NAMESPACE_ANNOTATION =\n 'backstage.io/kubernetes-namespace';\n\n// The endpoint for the Policy Reporter API\n// EXAMPLE: https://kyverno.io/policy-reporter/api/\nexport const KYVERNO_ENDPOINT_ANNOTATION = 'kyverno.io/endpoint';\n"],"names":[],"mappings":"AACO,MAAM,gCAAmC,GAAA;AAGzC,MAAM,uBAA0B,GAAA;AAGhC,MAAM,4BAA+B,GAAA;AAGrC,MAAM,+BACX,GAAA;AAIK,MAAM,2BAA8B,GAAA;;;;"}
package/dist/index.cjs.js CHANGED
@@ -1,13 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var types = require('./types.cjs.js');
4
3
  var annotations = require('./annotations.cjs.js');
4
+ var Api_client = require('./schema/openapi/generated/apis/Api.client.cjs.js');
5
5
 
6
6
 
7
7
 
8
- exports.Direction = types.Direction;
8
+ exports.KUBERNETES_NAMESPACE_ANNOTATION = annotations.KUBERNETES_NAMESPACE_ANNOTATION;
9
9
  exports.KYVERNO_ENDPOINT_ANNOTATION = annotations.KYVERNO_ENDPOINT_ANNOTATION;
10
10
  exports.KYVERNO_KIND_ANNOTATION = annotations.KYVERNO_KIND_ANNOTATION;
11
11
  exports.KYVERNO_NAMESPACE_ANNOTATION = annotations.KYVERNO_NAMESPACE_ANNOTATION;
12
12
  exports.KYVERNO_RESOURCE_NAME_ANNOTATION = annotations.KYVERNO_RESOURCE_NAME_ANNOTATION;
13
+ exports.DefaultApiClient = Api_client.DefaultApiClient;
13
14
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,59 +1,238 @@
1
- type Status = 'fail' | 'skip' | 'pass' | 'warn' | 'error' | 'summary';
2
- type Severity = 'unknown' | 'info' | 'low' | 'medium' | 'high' | 'critical';
3
- type ResultList = {
4
- items: ListResult[];
5
- count: number;
1
+ type Environment = {
2
+ id: number;
3
+ entityRef: string;
4
+ name: string;
6
5
  };
7
- type ListResult = {
6
+
7
+ declare const KYVERNO_RESOURCE_NAME_ANNOTATION = "kyverno.io/resource-name";
8
+ declare const KYVERNO_KIND_ANNOTATION = "kyverno.io/kind";
9
+ declare const KYVERNO_NAMESPACE_ANNOTATION = "kyverno.io/namespace";
10
+ declare const KUBERNETES_NAMESPACE_ANNOTATION = "backstage.io/kubernetes-namespace";
11
+ declare const KYVERNO_ENDPOINT_ANNOTATION = "kyverno.io/endpoint";
12
+
13
+ /**
14
+ * @public
15
+ */
16
+ type Direction = 'asc' | 'desc';
17
+
18
+ /**
19
+ * @public
20
+ */
21
+ type Severity = 'unknown' | 'info' | 'low' | 'medium' | 'high' | 'critical';
22
+
23
+ /**
24
+ * @public
25
+ */
26
+ type Status = 'fail' | 'skip' | 'pass' | 'warn' | 'error' | 'summary';
27
+
28
+ /**
29
+ * @public
30
+ */
31
+ interface ListResult {
32
+ /**
33
+ * Unique identifier for the result
34
+ */
8
35
  id: string;
36
+ /**
37
+ * Kubernetes namespace
38
+ */
9
39
  namespace: string;
40
+ /**
41
+ * Kubernetes resource kind
42
+ */
10
43
  kind: string;
44
+ /**
45
+ * Resource name
46
+ */
11
47
  name: string;
48
+ /**
49
+ * Unique resource identifier
50
+ */
12
51
  resourceId: string;
52
+ /**
53
+ * Policy result message
54
+ */
13
55
  message: string;
56
+ /**
57
+ * Policy name
58
+ */
14
59
  policy: string;
60
+ /**
61
+ * Policy rule name
62
+ */
15
63
  rule: string;
16
64
  status: Status;
17
65
  severity: Severity;
66
+ /**
67
+ * Unix timestamp of the result
68
+ */
18
69
  timestamp: number;
70
+ /**
71
+ * Additional key-value properties
72
+ */
19
73
  properties: {
20
74
  [key: string]: string;
21
75
  };
76
+ }
77
+
78
+ /**
79
+ * @public
80
+ */
81
+ interface ResultList {
82
+ items: Array<ListResult>;
83
+ /**
84
+ * Total number of results
85
+ */
86
+ count: number;
87
+ }
88
+
89
+ /**
90
+ * Wraps the Response type to convey a type on the json call.
91
+ *
92
+ * @public
93
+ */
94
+ type TypedResponse<T> = Omit<Response, 'json'> & {
95
+ json: () => Promise<T>;
96
+ };
97
+ /**
98
+ * Options you can pass into a request for additional information.
99
+ *
100
+ * @public
101
+ */
102
+ interface RequestOptions {
103
+ token?: string;
104
+ }
105
+ /**
106
+ * @public
107
+ */
108
+ type GetNamespacedResults = {
109
+ query: {
110
+ environment: string;
111
+ sources?: Array<string>;
112
+ namespaces?: Array<string>;
113
+ kinds?: Array<string>;
114
+ resources?: Array<string>;
115
+ categories?: Array<string>;
116
+ policies?: Array<string>;
117
+ status?: Array<Status>;
118
+ severities?: Array<Severity>;
119
+ search?: string;
120
+ labels?: Array<string>;
121
+ page?: number;
122
+ offset?: number;
123
+ direction?: Direction;
124
+ };
22
125
  };
23
- type Filter = {
24
- kinds?: string[];
25
- clusterKinds?: string[];
26
- categories?: string[];
27
- namespaces?: string[];
28
- severities?: Severity[];
29
- policies?: string[];
30
- sources?: string[];
31
- exclude?: string[];
32
- labels?: string[];
33
- status?: Status[];
126
+ /**
127
+ * @public
128
+ */
129
+ declare class DefaultApiClient {
130
+ private readonly discoveryApi;
131
+ private readonly fetchApi;
132
+ constructor(options: {
133
+ discoveryApi: {
134
+ getBaseUrl(pluginId: string): Promise<string>;
135
+ };
136
+ fetchApi?: {
137
+ fetch: typeof fetch;
138
+ };
139
+ });
140
+ /**
141
+ * Retrieves policy results for a specific environment with optional filtering and pagination
142
+ * Get namespaced policy results
143
+ * @param environment - The environment entity reference (URL encoded)
144
+ * @param sources - Filter by a list of sources
145
+ * @param namespaces - Filter by a list of namespaces
146
+ * @param kinds - Filter by a list of Kubernetes resource kinds
147
+ * @param resources - Filter by a list of resources
148
+ * @param categories - Filter by a list of categories
149
+ * @param policies - Filter by a list of policies
150
+ * @param status - Filter by policy result status
151
+ * @param severities - Filter by severity levels
152
+ * @param search - Search string to filter results
153
+ * @param labels - Filter by label-value pairs
154
+ * @param page - Requested list page number
155
+ * @param offset - Number of results per page
156
+ * @param direction - Sort direction for results
157
+ */
158
+ getNamespacedResults(request: GetNamespacedResults, options?: RequestOptions): Promise<TypedResponse<ResultList>>;
159
+ }
160
+
161
+ /**
162
+ * Filter options for policy results
163
+ * @public
164
+ */
165
+ interface Filter {
166
+ /**
167
+ * Filter by a list of sources
168
+ */
169
+ sources?: Array<string>;
170
+ /**
171
+ * Filter by a list of namespaces
172
+ */
173
+ namespaces?: Array<string>;
174
+ /**
175
+ * Filter by a list of kinds
176
+ */
177
+ kinds?: Array<string>;
178
+ /**
179
+ * Filter by a list of resources
180
+ */
181
+ resources?: Array<string>;
182
+ /**
183
+ * Filter by a list of categories
184
+ */
185
+ categories?: Array<string>;
186
+ /**
187
+ * Filter by a list of policies
188
+ */
189
+ policies?: Array<string>;
190
+ /**
191
+ * Filter by a list of status
192
+ */
193
+ status?: Array<Status>;
194
+ /**
195
+ * Filter by a list of severities
196
+ */
197
+ severities?: Array<Severity>;
198
+ /**
199
+ * Filter by search string
200
+ */
34
201
  search?: string;
35
- resource_id?: string;
36
- namespaced?: boolean;
37
- };
38
- type Pagination = {
39
- page: number;
40
- offset: number;
41
- sortBy?: string[];
202
+ /**
203
+ * Filter by label-value pairs
204
+ */
205
+ labels?: Array<string>;
206
+ }
207
+
208
+ /**
209
+ * Pagination options for results
210
+ * @public
211
+ */
212
+ interface Pagination {
213
+ /**
214
+ * Requested list page number
215
+ */
216
+ page?: number;
217
+ /**
218
+ * Number of results per page
219
+ */
220
+ offset?: number;
221
+ /**
222
+ * Fields to sort by
223
+ */
224
+ sortBy?: Array<string>;
42
225
  direction?: Direction;
43
- };
44
- declare enum Direction {
45
- ASC = "asc",
46
- DESC = "desc"
47
226
  }
48
- type Environment = {
49
- id: number;
50
- entityRef: string;
51
- name: string;
52
- };
53
227
 
54
- declare const KYVERNO_RESOURCE_NAME_ANNOTATION = "kyverno.io/resource-name";
55
- declare const KYVERNO_KIND_ANNOTATION = "kyverno.io/kind";
56
- declare const KYVERNO_NAMESPACE_ANNOTATION = "kyverno.io/namespace";
57
- declare const KYVERNO_ENDPOINT_ANNOTATION = "kyverno.io/endpoint";
228
+ /**
229
+ * @public
230
+ */
231
+ interface RequestError {
232
+ /**
233
+ * Error message
234
+ */
235
+ error: string;
236
+ }
58
237
 
59
- export { Direction, type Environment, type Filter, KYVERNO_ENDPOINT_ANNOTATION, KYVERNO_KIND_ANNOTATION, KYVERNO_NAMESPACE_ANNOTATION, KYVERNO_RESOURCE_NAME_ANNOTATION, type ListResult, type Pagination, type ResultList, type Severity, type Status };
238
+ export { DefaultApiClient, type Direction, type Environment, type Filter, type GetNamespacedResults, KUBERNETES_NAMESPACE_ANNOTATION, KYVERNO_ENDPOINT_ANNOTATION, KYVERNO_KIND_ANNOTATION, KYVERNO_NAMESPACE_ANNOTATION, KYVERNO_RESOURCE_NAME_ANNOTATION, type ListResult, type Pagination, type RequestError, type RequestOptions, type ResultList, type Severity, type Status, type TypedResponse };
package/dist/index.esm.js CHANGED
@@ -1,3 +1,3 @@
1
- export { Direction } from './types.esm.js';
2
- export { KYVERNO_ENDPOINT_ANNOTATION, KYVERNO_KIND_ANNOTATION, KYVERNO_NAMESPACE_ANNOTATION, KYVERNO_RESOURCE_NAME_ANNOTATION } from './annotations.esm.js';
1
+ export { KUBERNETES_NAMESPACE_ANNOTATION, KYVERNO_ENDPOINT_ANNOTATION, KYVERNO_KIND_ANNOTATION, KYVERNO_NAMESPACE_ANNOTATION, KYVERNO_RESOURCE_NAME_ANNOTATION } from './annotations.esm.js';
2
+ export { DefaultApiClient } from './schema/openapi/generated/apis/Api.client.esm.js';
3
3
  //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ var crossFetch = require('cross-fetch');
4
+ var pluginId = require('../pluginId.cjs.js');
5
+ var parser = require('uri-template');
6
+
7
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
8
+
9
+ function _interopNamespaceCompat(e) {
10
+ if (e && typeof e === 'object' && 'default' in e) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var crossFetch__default = /*#__PURE__*/_interopDefaultCompat(crossFetch);
28
+ var parser__namespace = /*#__PURE__*/_interopNamespaceCompat(parser);
29
+
30
+ class DefaultApiClient {
31
+ discoveryApi;
32
+ fetchApi;
33
+ constructor(options) {
34
+ this.discoveryApi = options.discoveryApi;
35
+ this.fetchApi = options.fetchApi || { fetch: crossFetch__default.default };
36
+ }
37
+ /**
38
+ * Retrieves policy results for a specific environment with optional filtering and pagination
39
+ * Get namespaced policy results
40
+ * @param environment - The environment entity reference (URL encoded)
41
+ * @param sources - Filter by a list of sources
42
+ * @param namespaces - Filter by a list of namespaces
43
+ * @param kinds - Filter by a list of Kubernetes resource kinds
44
+ * @param resources - Filter by a list of resources
45
+ * @param categories - Filter by a list of categories
46
+ * @param policies - Filter by a list of policies
47
+ * @param status - Filter by policy result status
48
+ * @param severities - Filter by severity levels
49
+ * @param search - Search string to filter results
50
+ * @param labels - Filter by label-value pairs
51
+ * @param page - Requested list page number
52
+ * @param offset - Number of results per page
53
+ * @param direction - Sort direction for results
54
+ */
55
+ async getNamespacedResults(request, options) {
56
+ const baseUrl = await this.discoveryApi.getBaseUrl(pluginId.pluginId);
57
+ const uriTemplate = `/namespaced-resources/results{?environment,sources*,namespaces*,kinds*,resources*,categories*,policies*,status*,severities*,search,labels*,page,offset,direction}`;
58
+ const uri = parser__namespace.parse(uriTemplate).expand({
59
+ ...request.query
60
+ });
61
+ return await this.fetchApi.fetch(`${baseUrl}${uri}`, {
62
+ headers: {
63
+ "Content-Type": "application/json",
64
+ ...options?.token && { Authorization: `Bearer ${options?.token}` }
65
+ },
66
+ method: "GET"
67
+ });
68
+ }
69
+ }
70
+
71
+ exports.DefaultApiClient = DefaultApiClient;
72
+ //# sourceMappingURL=Api.client.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Api.client.cjs.js","sources":["../../../../../src/schema/openapi/generated/apis/Api.client.ts"],"sourcesContent":["//\n\n// ******************************************************************\n// * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. *\n// ******************************************************************\nimport { DiscoveryApi } from '../types/discovery';\nimport { FetchApi } from '../types/fetch';\nimport crossFetch from 'cross-fetch';\nimport { pluginId } from '../pluginId';\nimport * as parser from 'uri-template';\nimport { Direction } from '../models/Direction.model';\nimport { ResultList } from '../models/ResultList.model';\nimport { Severity } from '../models/Severity.model';\nimport { Status } from '../models/Status.model';\n\n/**\n * Wraps the Response type to convey a type on the json call.\n *\n * @public\n */\nexport type TypedResponse<T> = Omit<Response, 'json'> & {\n json: () => Promise<T>;\n};\n\n/**\n * Options you can pass into a request for additional information.\n *\n * @public\n */\nexport interface RequestOptions {\n token?: string;\n}\n/**\n * @public\n */\nexport type GetNamespacedResults = {\n query: {\n environment: string;\n sources?: Array<string>;\n namespaces?: Array<string>;\n kinds?: Array<string>;\n resources?: Array<string>;\n categories?: Array<string>;\n policies?: Array<string>;\n status?: Array<Status>;\n severities?: Array<Severity>;\n search?: string;\n labels?: Array<string>;\n page?: number;\n offset?: number;\n direction?: Direction;\n };\n};\n\n/**\n * @public\n */\nexport class DefaultApiClient {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n\n constructor(options: {\n discoveryApi: { getBaseUrl(pluginId: string): Promise<string> };\n fetchApi?: { fetch: typeof fetch };\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi || { fetch: crossFetch };\n }\n\n /**\n * Retrieves policy results for a specific environment with optional filtering and pagination\n * Get namespaced policy results\n * @param environment - The environment entity reference (URL encoded)\n * @param sources - Filter by a list of sources\n * @param namespaces - Filter by a list of namespaces\n * @param kinds - Filter by a list of Kubernetes resource kinds\n * @param resources - Filter by a list of resources\n * @param categories - Filter by a list of categories\n * @param policies - Filter by a list of policies\n * @param status - Filter by policy result status\n * @param severities - Filter by severity levels\n * @param search - Search string to filter results\n * @param labels - Filter by label-value pairs\n * @param page - Requested list page number\n * @param offset - Number of results per page\n * @param direction - Sort direction for results\n */\n public async getNamespacedResults(\n // @ts-ignore\n request: GetNamespacedResults,\n options?: RequestOptions,\n ): Promise<TypedResponse<ResultList>> {\n const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);\n\n const uriTemplate = `/namespaced-resources/results{?environment,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 return await this.fetchApi.fetch(`${baseUrl}${uri}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(options?.token && { Authorization: `Bearer ${options?.token}` }),\n },\n method: 'GET',\n });\n }\n}\n"],"names":["crossFetch","pluginId","parser"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,MAAM,gBAAiB,CAAA;AAAA,EACX,YAAA;AAAA,EACA,QAAA;AAAA,EAEjB,YAAY,OAGT,EAAA;AACD,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA;AAC5B,IAAA,IAAA,CAAK,QAAW,GAAA,OAAA,CAAQ,QAAY,IAAA,EAAE,OAAOA,2BAAW,EAAA;AAAA;AAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA,MAAa,oBAEX,CAAA,OAAA,EACA,OACoC,EAAA;AACpC,IAAA,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,YAAA,CAAa,WAAWC,iBAAQ,CAAA;AAE3D,IAAA,MAAM,WAAc,GAAA,CAAA,iKAAA,CAAA;AAEpB,IAAA,MAAM,GAAM,GAAAC,iBAAA,CAAO,KAAM,CAAA,WAAW,EAAE,MAAO,CAAA;AAAA,MAC3C,GAAG,OAAQ,CAAA;AAAA,KACZ,CAAA;AAED,IAAO,OAAA,MAAM,KAAK,QAAS,CAAA,KAAA,CAAM,GAAG,OAAO,CAAA,EAAG,GAAG,CAAI,CAAA,EAAA;AAAA,MACnD,OAAS,EAAA;AAAA,QACP,cAAgB,EAAA,kBAAA;AAAA,QAChB,GAAI,SAAS,KAAS,IAAA,EAAE,eAAe,CAAU,OAAA,EAAA,OAAA,EAAS,KAAK,CAAG,CAAA;AAAA,OACpE;AAAA,MACA,MAAQ,EAAA;AAAA,KACT,CAAA;AAAA;AAEL;;;;"}
@@ -0,0 +1,47 @@
1
+ import crossFetch from 'cross-fetch';
2
+ import { pluginId } from '../pluginId.esm.js';
3
+ import * as parser from 'uri-template';
4
+
5
+ class DefaultApiClient {
6
+ discoveryApi;
7
+ fetchApi;
8
+ constructor(options) {
9
+ this.discoveryApi = options.discoveryApi;
10
+ this.fetchApi = options.fetchApi || { fetch: crossFetch };
11
+ }
12
+ /**
13
+ * Retrieves policy results for a specific environment with optional filtering and pagination
14
+ * Get namespaced policy results
15
+ * @param environment - The environment entity reference (URL encoded)
16
+ * @param sources - Filter by a list of sources
17
+ * @param namespaces - Filter by a list of namespaces
18
+ * @param kinds - Filter by a list of Kubernetes resource kinds
19
+ * @param resources - Filter by a list of resources
20
+ * @param categories - Filter by a list of categories
21
+ * @param policies - Filter by a list of policies
22
+ * @param status - Filter by policy result status
23
+ * @param severities - Filter by severity levels
24
+ * @param search - Search string to filter results
25
+ * @param labels - Filter by label-value pairs
26
+ * @param page - Requested list page number
27
+ * @param offset - Number of results per page
28
+ * @param direction - Sort direction for results
29
+ */
30
+ async getNamespacedResults(request, options) {
31
+ const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);
32
+ const uriTemplate = `/namespaced-resources/results{?environment,sources*,namespaces*,kinds*,resources*,categories*,policies*,status*,severities*,search,labels*,page,offset,direction}`;
33
+ const uri = parser.parse(uriTemplate).expand({
34
+ ...request.query
35
+ });
36
+ return await this.fetchApi.fetch(`${baseUrl}${uri}`, {
37
+ headers: {
38
+ "Content-Type": "application/json",
39
+ ...options?.token && { Authorization: `Bearer ${options?.token}` }
40
+ },
41
+ method: "GET"
42
+ });
43
+ }
44
+ }
45
+
46
+ export { DefaultApiClient };
47
+ //# sourceMappingURL=Api.client.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Api.client.esm.js","sources":["../../../../../src/schema/openapi/generated/apis/Api.client.ts"],"sourcesContent":["//\n\n// ******************************************************************\n// * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. *\n// ******************************************************************\nimport { DiscoveryApi } from '../types/discovery';\nimport { FetchApi } from '../types/fetch';\nimport crossFetch from 'cross-fetch';\nimport { pluginId } from '../pluginId';\nimport * as parser from 'uri-template';\nimport { Direction } from '../models/Direction.model';\nimport { ResultList } from '../models/ResultList.model';\nimport { Severity } from '../models/Severity.model';\nimport { Status } from '../models/Status.model';\n\n/**\n * Wraps the Response type to convey a type on the json call.\n *\n * @public\n */\nexport type TypedResponse<T> = Omit<Response, 'json'> & {\n json: () => Promise<T>;\n};\n\n/**\n * Options you can pass into a request for additional information.\n *\n * @public\n */\nexport interface RequestOptions {\n token?: string;\n}\n/**\n * @public\n */\nexport type GetNamespacedResults = {\n query: {\n environment: string;\n sources?: Array<string>;\n namespaces?: Array<string>;\n kinds?: Array<string>;\n resources?: Array<string>;\n categories?: Array<string>;\n policies?: Array<string>;\n status?: Array<Status>;\n severities?: Array<Severity>;\n search?: string;\n labels?: Array<string>;\n page?: number;\n offset?: number;\n direction?: Direction;\n };\n};\n\n/**\n * @public\n */\nexport class DefaultApiClient {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n\n constructor(options: {\n discoveryApi: { getBaseUrl(pluginId: string): Promise<string> };\n fetchApi?: { fetch: typeof fetch };\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi || { fetch: crossFetch };\n }\n\n /**\n * Retrieves policy results for a specific environment with optional filtering and pagination\n * Get namespaced policy results\n * @param environment - The environment entity reference (URL encoded)\n * @param sources - Filter by a list of sources\n * @param namespaces - Filter by a list of namespaces\n * @param kinds - Filter by a list of Kubernetes resource kinds\n * @param resources - Filter by a list of resources\n * @param categories - Filter by a list of categories\n * @param policies - Filter by a list of policies\n * @param status - Filter by policy result status\n * @param severities - Filter by severity levels\n * @param search - Search string to filter results\n * @param labels - Filter by label-value pairs\n * @param page - Requested list page number\n * @param offset - Number of results per page\n * @param direction - Sort direction for results\n */\n public async getNamespacedResults(\n // @ts-ignore\n request: GetNamespacedResults,\n options?: RequestOptions,\n ): Promise<TypedResponse<ResultList>> {\n const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);\n\n const uriTemplate = `/namespaced-resources/results{?environment,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 return await this.fetchApi.fetch(`${baseUrl}${uri}`, {\n headers: {\n 'Content-Type': 'application/json',\n ...(options?.token && { Authorization: `Bearer ${options?.token}` }),\n },\n method: 'GET',\n });\n }\n}\n"],"names":[],"mappings":";;;;AAyDO,MAAM,gBAAiB,CAAA;AAAA,EACX,YAAA;AAAA,EACA,QAAA;AAAA,EAEjB,YAAY,OAGT,EAAA;AACD,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA;AAC5B,IAAA,IAAA,CAAK,QAAW,GAAA,OAAA,CAAQ,QAAY,IAAA,EAAE,OAAO,UAAW,EAAA;AAAA;AAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBA,MAAa,oBAEX,CAAA,OAAA,EACA,OACoC,EAAA;AACpC,IAAA,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,YAAA,CAAa,WAAW,QAAQ,CAAA;AAE3D,IAAA,MAAM,WAAc,GAAA,CAAA,iKAAA,CAAA;AAEpB,IAAA,MAAM,GAAM,GAAA,MAAA,CAAO,KAAM,CAAA,WAAW,EAAE,MAAO,CAAA;AAAA,MAC3C,GAAG,OAAQ,CAAA;AAAA,KACZ,CAAA;AAED,IAAO,OAAA,MAAM,KAAK,QAAS,CAAA,KAAA,CAAM,GAAG,OAAO,CAAA,EAAG,GAAG,CAAI,CAAA,EAAA;AAAA,MACnD,OAAS,EAAA;AAAA,QACP,cAAgB,EAAA,kBAAA;AAAA,QAChB,GAAI,SAAS,KAAS,IAAA,EAAE,eAAe,CAAU,OAAA,EAAA,OAAA,EAAS,KAAK,CAAG,CAAA;AAAA,OACpE;AAAA,MACA,MAAQ,EAAA;AAAA,KACT,CAAA;AAAA;AAEL;;;;"}
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ const pluginId = "policy-reporter";
4
+
5
+ exports.pluginId = pluginId;
6
+ //# sourceMappingURL=pluginId.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluginId.cjs.js","sources":["../../../../src/schema/openapi/generated/pluginId.ts"],"sourcesContent":["export const pluginId = 'policy-reporter';\n"],"names":[],"mappings":";;AAAO,MAAM,QAAW,GAAA;;;;"}
@@ -0,0 +1,4 @@
1
+ const pluginId = "policy-reporter";
2
+
3
+ export { pluginId };
4
+ //# sourceMappingURL=pluginId.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluginId.esm.js","sources":["../../../../src/schema/openapi/generated/pluginId.ts"],"sourcesContent":["export const pluginId = 'policy-reporter';\n"],"names":[],"mappings":"AAAO,MAAM,QAAW,GAAA;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kyverno/backstage-plugin-policy-reporter-common",
3
3
  "description": "Common functionalities for the policy-reporter plugin",
4
- "version": "2.0.6",
4
+ "version": "2.1.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -40,11 +40,15 @@
40
40
  "postpack": "backstage-cli package postpack"
41
41
  },
42
42
  "devDependencies": {
43
- "@backstage/cli": "^0.32.0"
43
+ "@backstage/cli": "^0.34.3"
44
44
  },
45
45
  "files": [
46
46
  "dist"
47
47
  ],
48
+ "dependencies": {
49
+ "cross-fetch": "^4.1.0",
50
+ "uri-template": "^2.0.0"
51
+ },
48
52
  "typesVersions": {
49
53
  "*": {
50
54
  "package.json": [
package/dist/types.cjs.js DELETED
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- var Direction = /* @__PURE__ */ ((Direction2) => {
4
- Direction2["ASC"] = "asc";
5
- Direction2["DESC"] = "desc";
6
- return Direction2;
7
- })(Direction || {});
8
-
9
- exports.Direction = Direction;
10
- //# sourceMappingURL=types.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.cjs.js","sources":["../src/types.ts"],"sourcesContent":["export type Status = 'fail' | 'skip' | 'pass' | 'warn' | 'error' | 'summary';\n\nexport type Severity =\n | 'unknown'\n | 'info'\n | 'low'\n | 'medium'\n | 'high'\n | 'critical';\n\nexport type ResultList = { items: ListResult[]; count: number };\n\nexport type ListResult = {\n id: string;\n namespace: string;\n kind: string;\n name: string;\n resourceId: string;\n message: string;\n policy: string;\n rule: string;\n status: Status;\n severity: Severity;\n timestamp: number;\n properties: { [key: string]: string };\n};\n\nexport type Filter = {\n kinds?: string[];\n clusterKinds?: string[];\n categories?: string[];\n namespaces?: string[];\n severities?: Severity[];\n policies?: string[];\n sources?: string[];\n exclude?: string[];\n labels?: string[];\n status?: Status[];\n search?: string;\n resource_id?: string;\n namespaced?: boolean;\n};\n\nexport type Pagination = {\n page: number;\n offset: number;\n sortBy?: string[];\n direction?: Direction;\n};\n\nexport enum Direction {\n ASC = 'asc',\n DESC = 'desc',\n}\n\nexport type Environment = {\n id: number;\n entityRef: string;\n name: string;\n};\n"],"names":["Direction"],"mappings":";;AAkDY,IAAA,SAAA,qBAAAA,UAAL,KAAA;AACL,EAAAA,WAAA,KAAM,CAAA,GAAA,KAAA;AACN,EAAAA,WAAA,MAAO,CAAA,GAAA,MAAA;AAFG,EAAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA;;;;"}
package/dist/types.esm.js DELETED
@@ -1,8 +0,0 @@
1
- var Direction = /* @__PURE__ */ ((Direction2) => {
2
- Direction2["ASC"] = "asc";
3
- Direction2["DESC"] = "desc";
4
- return Direction2;
5
- })(Direction || {});
6
-
7
- export { Direction };
8
- //# sourceMappingURL=types.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.esm.js","sources":["../src/types.ts"],"sourcesContent":["export type Status = 'fail' | 'skip' | 'pass' | 'warn' | 'error' | 'summary';\n\nexport type Severity =\n | 'unknown'\n | 'info'\n | 'low'\n | 'medium'\n | 'high'\n | 'critical';\n\nexport type ResultList = { items: ListResult[]; count: number };\n\nexport type ListResult = {\n id: string;\n namespace: string;\n kind: string;\n name: string;\n resourceId: string;\n message: string;\n policy: string;\n rule: string;\n status: Status;\n severity: Severity;\n timestamp: number;\n properties: { [key: string]: string };\n};\n\nexport type Filter = {\n kinds?: string[];\n clusterKinds?: string[];\n categories?: string[];\n namespaces?: string[];\n severities?: Severity[];\n policies?: string[];\n sources?: string[];\n exclude?: string[];\n labels?: string[];\n status?: Status[];\n search?: string;\n resource_id?: string;\n namespaced?: boolean;\n};\n\nexport type Pagination = {\n page: number;\n offset: number;\n sortBy?: string[];\n direction?: Direction;\n};\n\nexport enum Direction {\n ASC = 'asc',\n DESC = 'desc',\n}\n\nexport type Environment = {\n id: number;\n entityRef: string;\n name: string;\n};\n"],"names":["Direction"],"mappings":"AAkDY,IAAA,SAAA,qBAAAA,UAAL,KAAA;AACL,EAAAA,WAAA,KAAM,CAAA,GAAA,KAAA;AACN,EAAAA,WAAA,MAAO,CAAA,GAAA,MAAA;AAFG,EAAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA;;;;"}