pepr 0.1.27 → 0.1.29

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