pepr 0.1.27 → 0.1.28

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.
Files changed (59) hide show
  1. package/dist/index.d.ts +5 -0
  2. package/dist/index.js +5 -0
  3. package/dist/package.json +76 -0
  4. package/dist/src/cli/banner.d.ts +1 -0
  5. package/dist/{pepr-cli.js → src/cli/banner.js} +1 -1251
  6. package/dist/src/cli/build.d.ts +7 -0
  7. package/dist/src/cli/build.js +95 -0
  8. package/dist/src/cli/capability.d.ts +2 -0
  9. package/dist/src/cli/capability.js +12 -0
  10. package/dist/src/cli/deploy.d.ts +2 -0
  11. package/dist/src/cli/deploy.js +49 -0
  12. package/dist/src/cli/dev.d.ts +2 -0
  13. package/dist/src/cli/dev.js +90 -0
  14. package/dist/src/cli/index.d.ts +1 -0
  15. package/dist/src/cli/index.js +28 -0
  16. package/dist/src/cli/init/index.d.ts +2 -0
  17. package/dist/src/cli/init/index.js +48 -0
  18. package/dist/src/cli/init/templates.d.ts +82 -0
  19. package/dist/src/cli/init/templates.js +224 -0
  20. package/dist/src/cli/init/utils.d.ts +20 -0
  21. package/dist/src/cli/init/utils.js +50 -0
  22. package/dist/src/cli/init/walkthrough.d.ts +7 -0
  23. package/dist/src/cli/init/walkthrough.js +76 -0
  24. package/dist/src/cli/root.d.ts +4 -0
  25. package/dist/src/cli/root.js +14 -0
  26. package/dist/src/cli/test.d.ts +2 -0
  27. package/dist/src/cli/test.js +45 -0
  28. package/dist/src/lib/capability.d.ts +26 -0
  29. package/dist/src/lib/capability.js +112 -0
  30. package/dist/src/lib/controller.d.ts +13 -0
  31. package/dist/src/lib/controller.js +77 -0
  32. package/dist/src/lib/filter.d.ts +10 -0
  33. package/dist/src/lib/filter.js +41 -0
  34. package/dist/src/lib/k8s/index.d.ts +4 -0
  35. package/dist/src/lib/k8s/index.js +7 -0
  36. package/dist/src/lib/k8s/kinds.d.ts +3 -0
  37. package/dist/src/lib/k8s/kinds.js +427 -0
  38. package/dist/src/lib/k8s/tls.d.ts +17 -0
  39. package/dist/src/lib/k8s/tls.js +67 -0
  40. package/dist/src/lib/k8s/types.d.ts +136 -0
  41. package/dist/src/lib/k8s/types.js +9 -0
  42. package/dist/src/lib/k8s/upstream.d.ts +1 -0
  43. package/dist/src/lib/k8s/upstream.js +3 -0
  44. package/dist/src/lib/k8s/webhook.d.ts +33 -0
  45. package/dist/src/lib/k8s/webhook.js +490 -0
  46. package/dist/src/lib/logger.d.ts +54 -0
  47. package/dist/{types-1709b44f.js → src/lib/logger.js} +3 -40
  48. package/dist/src/lib/module.d.ts +22 -0
  49. package/dist/src/lib/module.js +32 -0
  50. package/dist/src/lib/processor.d.ts +4 -0
  51. package/dist/src/lib/processor.js +66 -0
  52. package/dist/src/lib/request.d.ts +77 -0
  53. package/dist/src/lib/request.js +117 -0
  54. package/dist/src/lib/types.d.ts +187 -0
  55. package/dist/src/lib/types.js +31 -0
  56. package/package.json +8 -11
  57. package/tsconfig.build.json +4 -0
  58. package/dist/pepr-core.js +0 -949
  59. package/tsconfig.json +0 -17
@@ -0,0 +1,33 @@
1
+ import { V1ClusterRole, V1ClusterRoleBinding, V1Deployment, V1MutatingWebhookConfiguration, V1Namespace, V1NetworkPolicy, V1Secret, V1Service, V1ServiceAccount } from "@kubernetes/client-node";
2
+ import { ModuleConfig } from "../types";
3
+ import { TLSOut } from "./tls";
4
+ export declare class Webhook {
5
+ private readonly config;
6
+ private readonly host?;
7
+ private name;
8
+ private _tls;
9
+ image: string;
10
+ get tls(): TLSOut;
11
+ constructor(config: ModuleConfig, host?: string);
12
+ /** Generate the pepr-system namespace */
13
+ namespace(): V1Namespace;
14
+ /**
15
+ * Grants the controller access to cluster resources beyond the mutating webhook.
16
+ *
17
+ * @todo: should dynamically generate this based on resources used by the module. will also need to explore how this should work for multiple modules.
18
+ * @returns
19
+ */
20
+ clusterRole(): V1ClusterRole;
21
+ clusterRoleBinding(): V1ClusterRoleBinding;
22
+ serviceAccount(): V1ServiceAccount;
23
+ tlsSecret(): V1Secret;
24
+ mutatingWebhook(): V1MutatingWebhookConfiguration;
25
+ deployment(): V1Deployment;
26
+ /** Only permit the */
27
+ networkPolicy(): V1NetworkPolicy;
28
+ service(): V1Service;
29
+ moduleSecret(data: string): V1Secret;
30
+ zarfYaml(path: string): string;
31
+ allYaml(code: string): string;
32
+ deploy(code: string): Promise<void>;
33
+ }
@@ -0,0 +1,490 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
+ import { AdmissionregistrationV1Api, AppsV1Api, CoreV1Api, KubeConfig, NetworkingV1Api, RbacAuthorizationV1Api, dumpYaml, } from "@kubernetes/client-node";
4
+ import { gzipSync } from "zlib";
5
+ import Log from "../logger";
6
+ import { genTLS } from "./tls";
7
+ const peprIgnore = {
8
+ key: "pepr.dev",
9
+ operator: "NotIn",
10
+ values: ["ignore"],
11
+ };
12
+ export class Webhook {
13
+ get tls() {
14
+ return this._tls;
15
+ }
16
+ constructor(config, host) {
17
+ this.config = config;
18
+ this.host = host;
19
+ this.name = `pepr-${config.uuid}`;
20
+ this.image = `ghcr.io/defenseunicorns/pepr/controller:${config.version}`;
21
+ // Generate the ephemeral tls things
22
+ this._tls = genTLS(this.host || `${this.name}.pepr-system.svc`);
23
+ }
24
+ /** Generate the pepr-system namespace */
25
+ namespace() {
26
+ return {
27
+ apiVersion: "v1",
28
+ kind: "Namespace",
29
+ metadata: { name: "pepr-system" },
30
+ };
31
+ }
32
+ /**
33
+ * Grants the controller access to cluster resources beyond the mutating webhook.
34
+ *
35
+ * @todo: should dynamically generate this based on resources used by the module. will also need to explore how this should work for multiple modules.
36
+ * @returns
37
+ */
38
+ clusterRole() {
39
+ return {
40
+ apiVersion: "rbac.authorization.k8s.io/v1",
41
+ kind: "ClusterRole",
42
+ metadata: { name: this.name },
43
+ rules: [
44
+ {
45
+ // @todo: make this configurable
46
+ apiGroups: ["*"],
47
+ resources: ["*"],
48
+ verbs: ["create", "delete", "get", "list", "patch", "update", "watch"],
49
+ },
50
+ ],
51
+ };
52
+ }
53
+ clusterRoleBinding() {
54
+ const name = this.name;
55
+ return {
56
+ apiVersion: "rbac.authorization.k8s.io/v1",
57
+ kind: "ClusterRoleBinding",
58
+ metadata: { name },
59
+ roleRef: {
60
+ apiGroup: "rbac.authorization.k8s.io",
61
+ kind: "ClusterRole",
62
+ name,
63
+ },
64
+ subjects: [
65
+ {
66
+ kind: "ServiceAccount",
67
+ name,
68
+ namespace: "pepr-system",
69
+ },
70
+ ],
71
+ };
72
+ }
73
+ serviceAccount() {
74
+ return {
75
+ apiVersion: "v1",
76
+ kind: "ServiceAccount",
77
+ metadata: {
78
+ name: this.name,
79
+ namespace: "pepr-system",
80
+ },
81
+ };
82
+ }
83
+ tlsSecret() {
84
+ return {
85
+ apiVersion: "v1",
86
+ kind: "Secret",
87
+ metadata: {
88
+ name: `${this.name}-tls`,
89
+ namespace: "pepr-system",
90
+ },
91
+ type: "kubernetes.io/tls",
92
+ data: {
93
+ "tls.crt": this._tls.crt,
94
+ "tls.key": this._tls.key,
95
+ },
96
+ };
97
+ }
98
+ mutatingWebhook() {
99
+ const { name } = this;
100
+ const ignore = [peprIgnore];
101
+ // Add any namespaces to ignore
102
+ if (this.config.alwaysIgnore.namespaces.length > 0) {
103
+ ignore.push({
104
+ key: "kubernetes.io/metadata.name",
105
+ operator: "NotIn",
106
+ values: this.config.alwaysIgnore.namespaces,
107
+ });
108
+ }
109
+ const clientConfig = {
110
+ caBundle: this._tls.ca,
111
+ };
112
+ // If a host is specified, use that with a port of 3000
113
+ if (this.host) {
114
+ clientConfig.url = `https://${this.host}:3000/mutate`;
115
+ }
116
+ else {
117
+ // Otherwise, use the service
118
+ clientConfig.service = {
119
+ name: this.name,
120
+ namespace: "pepr-system",
121
+ path: "/mutate",
122
+ };
123
+ }
124
+ return {
125
+ apiVersion: "admissionregistration.k8s.io/v1",
126
+ kind: "MutatingWebhookConfiguration",
127
+ metadata: { name },
128
+ webhooks: [
129
+ {
130
+ name: `${name}.pepr.dev`,
131
+ admissionReviewVersions: ["v1", "v1beta1"],
132
+ clientConfig,
133
+ failurePolicy: "Ignore",
134
+ matchPolicy: "Equivalent",
135
+ timeoutSeconds: 15,
136
+ namespaceSelector: {
137
+ matchExpressions: ignore,
138
+ },
139
+ objectSelector: {
140
+ matchExpressions: ignore,
141
+ },
142
+ // @todo: make this configurable
143
+ rules: [
144
+ {
145
+ apiGroups: ["*"],
146
+ apiVersions: ["*"],
147
+ operations: ["CREATE", "UPDATE", "DELETE"],
148
+ resources: ["*/*"],
149
+ },
150
+ ],
151
+ // @todo: track side effects state
152
+ sideEffects: "None",
153
+ },
154
+ ],
155
+ };
156
+ }
157
+ deployment() {
158
+ return {
159
+ apiVersion: "apps/v1",
160
+ kind: "Deployment",
161
+ metadata: {
162
+ name: this.name,
163
+ namespace: "pepr-system",
164
+ labels: {
165
+ app: this.name,
166
+ },
167
+ },
168
+ spec: {
169
+ replicas: 2,
170
+ selector: {
171
+ matchLabels: {
172
+ app: this.name,
173
+ },
174
+ },
175
+ template: {
176
+ metadata: {
177
+ labels: {
178
+ app: this.name,
179
+ },
180
+ },
181
+ spec: {
182
+ priorityClassName: "system-node-critical",
183
+ serviceAccountName: this.name,
184
+ containers: [
185
+ {
186
+ name: "server",
187
+ image: this.image,
188
+ imagePullPolicy: "IfNotPresent",
189
+ livenessProbe: {
190
+ httpGet: {
191
+ path: "/healthz",
192
+ port: 3000,
193
+ scheme: "HTTPS",
194
+ },
195
+ },
196
+ ports: [
197
+ {
198
+ containerPort: 3000,
199
+ },
200
+ ],
201
+ resources: {
202
+ requests: {
203
+ memory: "64Mi",
204
+ cpu: "100m",
205
+ },
206
+ limits: {
207
+ memory: "256Mi",
208
+ cpu: "500m",
209
+ },
210
+ },
211
+ volumeMounts: [
212
+ {
213
+ name: "tls-certs",
214
+ mountPath: "/etc/certs",
215
+ readOnly: true,
216
+ },
217
+ {
218
+ name: "module",
219
+ mountPath: "/app/module.js.gz",
220
+ readOnly: true,
221
+ },
222
+ ],
223
+ },
224
+ ],
225
+ volumes: [
226
+ {
227
+ name: "tls-certs",
228
+ secret: {
229
+ secretName: `${this.name}-tls`,
230
+ },
231
+ },
232
+ {
233
+ name: "module",
234
+ secret: {
235
+ secretName: `${this.name}-module`,
236
+ },
237
+ },
238
+ ],
239
+ },
240
+ },
241
+ },
242
+ };
243
+ }
244
+ /** Only permit the */
245
+ networkPolicy() {
246
+ return {
247
+ apiVersion: "networking.k8s.io/v1",
248
+ kind: "NetworkPolicy",
249
+ metadata: {
250
+ name: this.name,
251
+ namespace: "pepr-system",
252
+ },
253
+ spec: {
254
+ podSelector: {
255
+ matchLabels: {
256
+ app: this.name,
257
+ },
258
+ },
259
+ policyTypes: ["Ingress"],
260
+ ingress: [
261
+ {
262
+ from: [
263
+ {
264
+ namespaceSelector: {
265
+ matchLabels: {
266
+ "kubernetes.io/metadata.name": "kube-system",
267
+ },
268
+ },
269
+ },
270
+ ],
271
+ ports: [
272
+ {
273
+ protocol: "TCP",
274
+ port: 443,
275
+ },
276
+ ],
277
+ },
278
+ ],
279
+ },
280
+ };
281
+ }
282
+ service() {
283
+ return {
284
+ apiVersion: "v1",
285
+ kind: "Service",
286
+ metadata: {
287
+ name: this.name,
288
+ namespace: "pepr-system",
289
+ },
290
+ spec: {
291
+ selector: {
292
+ app: this.name,
293
+ },
294
+ ports: [
295
+ {
296
+ port: 443,
297
+ targetPort: 3000,
298
+ },
299
+ ],
300
+ },
301
+ };
302
+ }
303
+ moduleSecret(data) {
304
+ // Compress the data
305
+ const compressed = gzipSync(data);
306
+ return {
307
+ apiVersion: "v1",
308
+ kind: "Secret",
309
+ metadata: {
310
+ name: `${this.name}-module`,
311
+ namespace: "pepr-system",
312
+ },
313
+ type: "Opaque",
314
+ data: {
315
+ module: compressed.toString("base64"),
316
+ },
317
+ };
318
+ }
319
+ zarfYaml(path) {
320
+ const zarfCfg = {
321
+ kind: "ZarfPackageConfig",
322
+ metadata: {
323
+ name: this.name,
324
+ description: `Pepr Module: ${this.config.description}`,
325
+ url: "https://github.com/defenseunicorns/pepr",
326
+ version: this.config.version,
327
+ },
328
+ components: [
329
+ {
330
+ name: "module",
331
+ required: true,
332
+ manifests: [
333
+ {
334
+ name: "module",
335
+ namespace: "pepr-system",
336
+ files: [path],
337
+ },
338
+ ],
339
+ images: [this.image],
340
+ },
341
+ ],
342
+ };
343
+ return dumpYaml(zarfCfg, { noRefs: true });
344
+ }
345
+ allYaml(code) {
346
+ const resources = [
347
+ this.namespace(),
348
+ this.networkPolicy(),
349
+ this.clusterRole(),
350
+ this.clusterRoleBinding(),
351
+ this.serviceAccount(),
352
+ this.tlsSecret(),
353
+ this.mutatingWebhook(),
354
+ this.deployment(),
355
+ this.service(),
356
+ this.moduleSecret(code),
357
+ ];
358
+ // Convert the resources to a single YAML string
359
+ return resources.map(r => dumpYaml(r, { noRefs: true })).join("---\n");
360
+ }
361
+ async deploy(code) {
362
+ Log.info("Establishing connection to Kubernetes");
363
+ const namespace = "pepr-system";
364
+ // Deploy the resources using the k8s API
365
+ const kubeConfig = new KubeConfig();
366
+ kubeConfig.loadFromDefault();
367
+ const coreV1Api = kubeConfig.makeApiClient(CoreV1Api);
368
+ const rbacApi = kubeConfig.makeApiClient(RbacAuthorizationV1Api);
369
+ const appsApi = kubeConfig.makeApiClient(AppsV1Api);
370
+ const admissionApi = kubeConfig.makeApiClient(AdmissionregistrationV1Api);
371
+ const networkApi = kubeConfig.makeApiClient(NetworkingV1Api);
372
+ const ns = this.namespace();
373
+ try {
374
+ Log.info("Checking for namespace");
375
+ await coreV1Api.readNamespace(namespace);
376
+ }
377
+ catch (e) {
378
+ Log.debug(e.body);
379
+ Log.info("Creating namespace");
380
+ await coreV1Api.createNamespace(ns);
381
+ }
382
+ const netpol = this.networkPolicy();
383
+ try {
384
+ Log.info("Checking for network policy");
385
+ await networkApi.readNamespacedNetworkPolicy(netpol.metadata.name, namespace);
386
+ }
387
+ catch (e) {
388
+ Log.debug(e.body);
389
+ Log.info("Creating network policy");
390
+ await networkApi.createNamespacedNetworkPolicy(namespace, netpol);
391
+ }
392
+ const wh = this.mutatingWebhook();
393
+ try {
394
+ Log.info("Creating mutating webhook");
395
+ await admissionApi.createMutatingWebhookConfiguration(wh);
396
+ }
397
+ catch (e) {
398
+ Log.debug(e.body);
399
+ Log.info("Removing and re-creating mutating webhook");
400
+ await admissionApi.deleteMutatingWebhookConfiguration(wh.metadata.name);
401
+ await admissionApi.createMutatingWebhookConfiguration(wh);
402
+ }
403
+ const crb = this.clusterRoleBinding();
404
+ try {
405
+ Log.info("Creating cluster role binding");
406
+ await rbacApi.createClusterRoleBinding(crb);
407
+ }
408
+ catch (e) {
409
+ Log.debug(e.body);
410
+ Log.info("Removing and re-creating cluster role binding");
411
+ await rbacApi.deleteClusterRoleBinding(crb.metadata.name);
412
+ await rbacApi.createClusterRoleBinding(crb);
413
+ }
414
+ const cr = this.clusterRole();
415
+ try {
416
+ Log.info("Creating cluster role");
417
+ await rbacApi.createClusterRole(cr);
418
+ }
419
+ catch (e) {
420
+ Log.debug(e.body);
421
+ Log.info("Removing and re-creating the cluster role");
422
+ try {
423
+ await rbacApi.deleteClusterRole(cr.metadata.name);
424
+ await rbacApi.createClusterRole(cr);
425
+ }
426
+ catch (e) {
427
+ Log.debug(e.body);
428
+ }
429
+ }
430
+ const sa = this.serviceAccount();
431
+ try {
432
+ Log.info("Creating service account");
433
+ await coreV1Api.createNamespacedServiceAccount(namespace, sa);
434
+ }
435
+ catch (e) {
436
+ Log.debug(e.body);
437
+ Log.info("Removing and re-creating service account");
438
+ await coreV1Api.deleteNamespacedServiceAccount(sa.metadata.name, namespace);
439
+ await coreV1Api.createNamespacedServiceAccount(namespace, sa);
440
+ }
441
+ // If a host is specified, we don't need to deploy the rest of the resources
442
+ if (this.host) {
443
+ return;
444
+ }
445
+ const mod = this.moduleSecret(code);
446
+ try {
447
+ Log.info("Creating module secret");
448
+ await coreV1Api.createNamespacedSecret(namespace, mod);
449
+ }
450
+ catch (e) {
451
+ Log.debug(e.body);
452
+ Log.info("Removing and re-creating module secret");
453
+ await coreV1Api.deleteNamespacedSecret(mod.metadata.name, namespace);
454
+ await coreV1Api.createNamespacedSecret(namespace, mod);
455
+ }
456
+ const svc = this.service();
457
+ try {
458
+ Log.info("Creating service");
459
+ await coreV1Api.createNamespacedService(namespace, svc);
460
+ }
461
+ catch (e) {
462
+ Log.debug(e.body);
463
+ Log.info("Removing and re-creating service");
464
+ await coreV1Api.deleteNamespacedService(svc.metadata.name, namespace);
465
+ await coreV1Api.createNamespacedService(namespace, svc);
466
+ }
467
+ const tls = this.tlsSecret();
468
+ try {
469
+ Log.info("Creating TLS secret");
470
+ await coreV1Api.createNamespacedSecret(namespace, tls);
471
+ }
472
+ catch (e) {
473
+ Log.debug(e.body);
474
+ Log.info("Removing and re-creating TLS secret");
475
+ await coreV1Api.deleteNamespacedSecret(tls.metadata.name, namespace);
476
+ await coreV1Api.createNamespacedSecret(namespace, tls);
477
+ }
478
+ const dep = this.deployment();
479
+ try {
480
+ Log.info("Creating deployment");
481
+ await appsApi.createNamespacedDeployment(namespace, dep);
482
+ }
483
+ catch (e) {
484
+ Log.debug(e.body);
485
+ Log.info("Removing and re-creating deployment");
486
+ await appsApi.deleteNamespacedDeployment(dep.metadata.name, namespace);
487
+ await appsApi.createNamespacedDeployment(namespace, dep);
488
+ }
489
+ }
490
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Enumeration representing different logging levels.
3
+ */
4
+ export declare enum LogLevel {
5
+ debug = 0,
6
+ info = 1,
7
+ warn = 2,
8
+ error = 3
9
+ }
10
+ /**
11
+ * Simple logger class that logs messages at different log levels.
12
+ */
13
+ export declare class Logger {
14
+ private _logLevel;
15
+ /**
16
+ * Create a new logger instance.
17
+ * @param logLevel - The minimum log level to log messages for.
18
+ */
19
+ constructor(logLevel: LogLevel);
20
+ /**
21
+ * Change the log level of the logger.
22
+ * @param logLevel - The log level to log the message at.
23
+ */
24
+ SetLogLevel(logLevel: string): void;
25
+ /**
26
+ * Log a debug message.
27
+ * @param message - The message to log.
28
+ */
29
+ debug<T>(message: T, prefix?: string): void;
30
+ /**
31
+ * Log an info message.
32
+ * @param message - The message to log.
33
+ */
34
+ info<T>(message: T, prefix?: string): void;
35
+ /**
36
+ * Log a warning message.
37
+ * @param message - The message to log.
38
+ */
39
+ warn<T>(message: T, prefix?: string): void;
40
+ /**
41
+ * Log an error message.
42
+ * @param message - The message to log.
43
+ */
44
+ error<T>(message: T, prefix?: string): void;
45
+ /**
46
+ * Log a message at the specified log level.
47
+ * @param logLevel - The log level of the message.
48
+ * @param message - The message to log.
49
+ */
50
+ private log;
51
+ private colorize;
52
+ }
53
+ declare const _default: Logger;
54
+ export default _default;
@@ -1,12 +1,9 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
1
  // SPDX-License-Identifier: Apache-2.0
5
2
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
6
3
  /**
7
4
  * Enumeration representing different logging levels.
8
5
  */
9
- var LogLevel;
6
+ export var LogLevel;
10
7
  (function (LogLevel) {
11
8
  LogLevel[LogLevel["debug"] = 0] = "debug";
12
9
  LogLevel[LogLevel["info"] = 1] = "info";
@@ -42,7 +39,7 @@ var ConsoleColors;
42
39
  /**
43
40
  * Simple logger class that logs messages at different log levels.
44
41
  */
45
- class Logger {
42
+ export class Logger {
46
43
  /**
47
44
  * Create a new logger instance.
48
45
  * @param logLevel - The minimum log level to log messages for.
@@ -116,38 +113,4 @@ class Logger {
116
113
  return color + text + ConsoleColors.Reset;
117
114
  }
118
115
  }
119
- var logger = new Logger(LogLevel.info);
120
-
121
- // SPDX-License-Identifier: Apache-2.0
122
- // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
123
- /**
124
- * The behavior of this module when an error occurs.
125
- */
126
- exports.ErrorBehavior = void 0;
127
- (function (ErrorBehavior) {
128
- ErrorBehavior["ignore"] = "ignore";
129
- ErrorBehavior["audit"] = "audit";
130
- ErrorBehavior["reject"] = "reject";
131
- })(exports.ErrorBehavior || (exports.ErrorBehavior = {}));
132
- /**
133
- * The phase of the Kubernetes admission webhook that the capability is registered for.
134
- *
135
- * Currently only `mutate` is supported.
136
- */
137
- exports.HookPhase = void 0;
138
- (function (HookPhase) {
139
- HookPhase["mutate"] = "mutate";
140
- HookPhase["valdiate"] = "validate";
141
- })(exports.HookPhase || (exports.HookPhase = {}));
142
- /**
143
- * The type of Kubernetes mutating webhook event ethat the capability action is registered for.
144
- */
145
- exports.Event = void 0;
146
- (function (Event) {
147
- Event["Create"] = "create";
148
- Event["Update"] = "update";
149
- Event["Delete"] = "delete";
150
- Event["CreateOrUpdate"] = "createOrUpdate";
151
- })(exports.Event || (exports.Event = {}));
152
-
153
- exports.logger = logger;
116
+ export default new Logger(LogLevel.info);
@@ -0,0 +1,22 @@
1
+ import { Capability } from "./capability";
2
+ import { ModuleConfig } from "./types";
3
+ export type PackageJSON = {
4
+ description: string;
5
+ pepr: ModuleConfig;
6
+ };
7
+ export declare class PeprModule {
8
+ private _controller;
9
+ /**
10
+ * Create a new Pepr runtime
11
+ *
12
+ * @param config The configuration for the Pepr runtime
13
+ */
14
+ constructor({ description, pepr }: PackageJSON, capabilities?: Capability[], deferStart?: boolean);
15
+ /**
16
+ * Start the Pepr runtime manually.
17
+ * Normally this is called automatically when the Pepr module is instantiated, but can be called manually if `deferStart` is set to `true` in the constructor.
18
+ *
19
+ * @param port
20
+ */
21
+ start(port?: number): void;
22
+ }
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
+ import R from "ramda";
4
+ import { Controller } from "./controller";
5
+ const alwaysIgnore = {
6
+ namespaces: ["kube-system", "pepr-system"],
7
+ labels: [{ "pepr.dev": "ignore" }],
8
+ };
9
+ export class PeprModule {
10
+ /**
11
+ * Create a new Pepr runtime
12
+ *
13
+ * @param config The configuration for the Pepr runtime
14
+ */
15
+ constructor({ description, pepr }, capabilities = [], deferStart = false) {
16
+ const config = R.mergeDeepWith(R.concat, pepr, alwaysIgnore);
17
+ config.description = description;
18
+ this._controller = new Controller(config, capabilities);
19
+ if (!deferStart) {
20
+ this.start();
21
+ }
22
+ }
23
+ /**
24
+ * Start the Pepr runtime manually.
25
+ * Normally this is called automatically when the Pepr module is instantiated, but can be called manually if `deferStart` is set to `true` in the constructor.
26
+ *
27
+ * @param port
28
+ */
29
+ start(port = 3000) {
30
+ this._controller.startServer(port);
31
+ }
32
+ }
@@ -0,0 +1,4 @@
1
+ import { Capability } from "./capability";
2
+ import { Request, Response } from "./k8s/types";
3
+ import { ModuleConfig } from "./types";
4
+ export declare function processor(config: ModuleConfig, capabilities: Capability[], req: Request): Response;