pepr 0.42.0 → 0.42.2
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/dist/cli/build.d.ts +1 -0
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.helpers.d.ts +66 -0
- package/dist/cli/build.helpers.d.ts.map +1 -1
- package/dist/cli/deploy.d.ts +15 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.helpers.d.ts +3 -0
- package/dist/cli/format.helpers.d.ts.map +1 -0
- package/dist/cli/init/enums.d.ts +10 -0
- package/dist/cli/init/enums.d.ts.map +1 -0
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +15 -11
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/init/utils.d.ts.map +1 -1
- package/dist/cli/init/walkthrough.d.ts +3 -2
- package/dist/cli/init/walkthrough.d.ts.map +1 -1
- package/dist/cli/kfc.d.ts.map +1 -1
- package/dist/cli/monitor.d.ts +23 -0
- package/dist/cli/monitor.d.ts.map +1 -1
- package/dist/cli/root.d.ts.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/uuid.d.ts.map +1 -1
- package/dist/cli.js +483 -586
- package/dist/controller.js +1 -195
- package/dist/fixtures/loader.d.ts.map +1 -1
- package/dist/lib/assets/deploy.d.ts.map +1 -1
- package/dist/lib/assets/destroy.d.ts.map +1 -1
- package/dist/lib/assets/helm.d.ts +1 -1
- package/dist/lib/assets/helm.d.ts.map +1 -1
- package/dist/lib/assets/index.d.ts +1 -1
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/pods.d.ts +6 -22
- package/dist/lib/assets/pods.d.ts.map +1 -1
- package/dist/lib/assets/rbac.d.ts.map +1 -1
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts +2 -2
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts +1 -2
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/controller/storeCache.d.ts +2 -1
- package/dist/lib/controller/storeCache.d.ts.map +1 -1
- package/dist/lib/{capability.d.ts → core/capability.d.ts} +1 -1
- package/dist/lib/core/capability.d.ts.map +1 -0
- package/dist/lib/{module.d.ts → core/module.d.ts} +2 -2
- package/dist/lib/core/module.d.ts.map +1 -0
- package/dist/lib/core/queue.d.ts.map +1 -0
- package/dist/lib/{schedule.d.ts → core/schedule.d.ts} +0 -1
- package/dist/lib/core/schedule.d.ts.map +1 -0
- package/dist/lib/{storage.d.ts → core/storage.d.ts} +4 -4
- package/dist/lib/core/storage.d.ts.map +1 -0
- package/dist/lib/deploymentChecks.d.ts.map +1 -1
- package/dist/lib/errors.d.ts +0 -5
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/filesystemService.d.ts.map +1 -1
- package/dist/lib/filter/adjudicators/adjudicators.d.ts +5 -4
- package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -1
- package/dist/lib/filter/filter.d.ts +33 -1
- package/dist/lib/filter/filter.d.ts.map +1 -1
- package/dist/lib/finalizer.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +4 -9
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/included-files.d.ts.map +1 -1
- package/dist/lib/mutate-request.d.ts +2 -2
- package/dist/lib/mutate-request.d.ts.map +1 -1
- package/dist/lib/processors/mutate-processor.d.ts +28 -0
- package/dist/lib/processors/mutate-processor.d.ts.map +1 -0
- package/dist/lib/processors/validate-processor.d.ts +9 -0
- package/dist/lib/processors/validate-processor.d.ts.map +1 -0
- package/dist/lib/{watch-processor.d.ts → processors/watch-processor.d.ts} +2 -2
- package/dist/lib/processors/watch-processor.d.ts.map +1 -0
- package/dist/lib/telemetry/logger.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/validate-request.d.ts +2 -2
- package/dist/lib/validate-request.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +508 -341
- package/dist/lib.js.map +4 -4
- package/dist/sdk/heredoc.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/cli/build.helpers.ts +180 -0
- package/src/cli/build.ts +85 -133
- package/src/cli/deploy.ts +113 -74
- package/src/cli/dev.ts +2 -2
- package/src/cli/format.helpers.ts +27 -0
- package/src/cli/format.ts +4 -18
- package/src/cli/init/enums.ts +9 -0
- package/src/cli/init/index.ts +4 -3
- package/src/cli/init/templates.ts +30 -2
- package/src/cli/init/utils.ts +3 -3
- package/src/cli/init/walkthrough.ts +7 -8
- package/src/cli/kfc.ts +1 -1
- package/src/cli/monitor.ts +108 -65
- package/src/cli/root.ts +1 -1
- package/src/cli/update.ts +1 -1
- package/src/cli/uuid.ts +1 -1
- package/src/fixtures/loader.ts +2 -2
- package/src/lib/assets/deploy.ts +11 -11
- package/src/lib/assets/destroy.ts +1 -1
- package/src/lib/assets/helm.ts +6 -6
- package/src/lib/assets/index.ts +23 -23
- package/src/lib/assets/pods.ts +11 -6
- package/src/lib/assets/webhooks.ts +31 -46
- package/src/lib/assets/yaml.ts +12 -9
- package/src/lib/controller/index.ts +13 -11
- package/src/lib/controller/store.ts +25 -12
- package/src/lib/controller/storeCache.ts +16 -3
- package/src/lib/{capability.ts → core/capability.ts} +25 -14
- package/src/lib/{module.ts → core/module.ts} +10 -10
- package/src/lib/{queue.ts → core/queue.ts} +13 -5
- package/src/lib/{storage.ts → core/storage.ts} +33 -24
- package/src/lib/deploymentChecks.ts +2 -2
- package/src/lib/errors.ts +3 -8
- package/src/lib/filesystemService.ts +1 -1
- package/src/lib/filter/adjudicators/adjudicators.ts +40 -9
- package/src/lib/filter/filter.ts +204 -111
- package/src/lib/finalizer.ts +2 -2
- package/src/lib/helpers.ts +20 -133
- package/src/lib/included-files.ts +1 -1
- package/src/lib/mutate-request.ts +11 -11
- package/src/lib/processors/mutate-processor.ts +225 -0
- package/src/lib/processors/validate-processor.ts +93 -0
- package/src/lib/{watch-processor.ts → processors/watch-processor.ts} +19 -15
- package/src/lib/telemetry/logger.ts +3 -1
- package/src/lib/tls.ts +5 -1
- package/src/lib/utils.ts +5 -5
- package/src/lib/validate-request.ts +4 -4
- package/src/lib.ts +2 -2
- package/src/runtime/controller.ts +2 -2
- package/src/sdk/cosign.ts +4 -4
- package/src/sdk/heredoc.ts +1 -1
- package/dist/lib/capability.d.ts.map +0 -1
- package/dist/lib/module.d.ts.map +0 -1
- package/dist/lib/mutate-processor.d.ts +0 -6
- package/dist/lib/mutate-processor.d.ts.map +0 -1
- package/dist/lib/queue.d.ts.map +0 -1
- package/dist/lib/schedule.d.ts.map +0 -1
- package/dist/lib/storage.d.ts.map +0 -1
- package/dist/lib/validate-processor.d.ts +0 -6
- package/dist/lib/validate-processor.d.ts.map +0 -1
- package/dist/lib/watch-processor.d.ts.map +0 -1
- package/src/lib/mutate-processor.ts +0 -165
- package/src/lib/validate-processor.ts +0 -85
- /package/dist/lib/{queue.d.ts → core/queue.d.ts} +0 -0
- /package/src/lib/{schedule.ts → core/schedule.ts} +0 -0
package/dist/cli.js
CHANGED
|
@@ -86,26 +86,10 @@ var banner = `\x1B[107;40m\x1B[38;5;m \x1B[38;5;m \x1B[38;5;m \x1B[38;5;m \x1B[3
|
|
|
86
86
|
`;
|
|
87
87
|
|
|
88
88
|
// src/cli/build.ts
|
|
89
|
-
var
|
|
90
|
-
var
|
|
91
|
-
var
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
// src/lib/included-files.ts
|
|
95
|
-
var import_fs = require("fs");
|
|
96
|
-
async function createDockerfile(version3, description, includedFiles) {
|
|
97
|
-
const file = `
|
|
98
|
-
# Use an official Node.js runtime as the base image
|
|
99
|
-
FROM ghcr.io/defenseunicorns/pepr/controller:v${version3}
|
|
100
|
-
|
|
101
|
-
LABEL description="${description}"
|
|
102
|
-
|
|
103
|
-
# Add the included files to the image
|
|
104
|
-
${includedFiles.map((f) => `ADD ${f} ${f}`).join("\n")}
|
|
105
|
-
|
|
106
|
-
`;
|
|
107
|
-
await import_fs.promises.writeFile("Dockerfile.controller", file, { encoding: "utf-8" });
|
|
108
|
-
}
|
|
89
|
+
var import_child_process3 = require("child_process");
|
|
90
|
+
var import_esbuild2 = require("esbuild");
|
|
91
|
+
var import_fs9 = require("fs");
|
|
92
|
+
var import_path3 = require("path");
|
|
109
93
|
|
|
110
94
|
// src/lib/assets/index.ts
|
|
111
95
|
var import_crypto3 = __toESM(require("crypto"));
|
|
@@ -170,7 +154,7 @@ function genCert(key, name2, issuer) {
|
|
|
170
154
|
|
|
171
155
|
// src/lib/assets/deploy.ts
|
|
172
156
|
var import_crypto = __toESM(require("crypto"));
|
|
173
|
-
var
|
|
157
|
+
var import_fs = require("fs");
|
|
174
158
|
var import_kubernetes_fluent_client3 = require("kubernetes-fluent-client");
|
|
175
159
|
|
|
176
160
|
// src/lib/telemetry/logger.ts
|
|
@@ -283,200 +267,6 @@ function sanitizeResourceName(name2) {
|
|
|
283
267
|
return name2.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 250).replace(/^[^a-z]+|[^a-z]+$/g, "");
|
|
284
268
|
}
|
|
285
269
|
|
|
286
|
-
// src/lib/filter/adjudicators/adjudicators.ts
|
|
287
|
-
var import_ramda = require("ramda");
|
|
288
|
-
var declaredOperation = (0, import_ramda.pipe)(
|
|
289
|
-
(request) => request?.operation,
|
|
290
|
-
(0, import_ramda.defaultTo)("")
|
|
291
|
-
);
|
|
292
|
-
var declaredGroup = (0, import_ramda.pipe)(
|
|
293
|
-
(request) => request?.kind?.group,
|
|
294
|
-
(0, import_ramda.defaultTo)("")
|
|
295
|
-
);
|
|
296
|
-
var declaredVersion = (0, import_ramda.pipe)(
|
|
297
|
-
(request) => request?.kind?.version,
|
|
298
|
-
(0, import_ramda.defaultTo)("")
|
|
299
|
-
);
|
|
300
|
-
var declaredKind = (0, import_ramda.pipe)(
|
|
301
|
-
(request) => request?.kind?.kind,
|
|
302
|
-
(0, import_ramda.defaultTo)("")
|
|
303
|
-
);
|
|
304
|
-
var declaredUid = (0, import_ramda.pipe)((request) => request?.uid, (0, import_ramda.defaultTo)(""));
|
|
305
|
-
var carriesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
306
|
-
(kubernetesObject) => !!kubernetesObject.metadata?.deletionTimestamp,
|
|
307
|
-
(0, import_ramda.defaultTo)(false)
|
|
308
|
-
);
|
|
309
|
-
var missingDeletionTimestamp = (0, import_ramda.complement)(carriesDeletionTimestamp);
|
|
310
|
-
var carriedKind = (0, import_ramda.pipe)(
|
|
311
|
-
(kubernetesObject) => kubernetesObject?.kind,
|
|
312
|
-
(0, import_ramda.defaultTo)("not set")
|
|
313
|
-
);
|
|
314
|
-
var carriedVersion = (0, import_ramda.pipe)(
|
|
315
|
-
(kubernetesObject) => kubernetesObject?.metadata?.resourceVersion,
|
|
316
|
-
(0, import_ramda.defaultTo)("not set")
|
|
317
|
-
);
|
|
318
|
-
var carriedName = (0, import_ramda.pipe)(
|
|
319
|
-
(kubernetesObject) => kubernetesObject?.metadata?.name,
|
|
320
|
-
(0, import_ramda.defaultTo)("")
|
|
321
|
-
);
|
|
322
|
-
var carriesName = (0, import_ramda.pipe)(carriedName, (0, import_ramda.equals)(""), import_ramda.not);
|
|
323
|
-
var missingName = (0, import_ramda.complement)(carriesName);
|
|
324
|
-
var carriedNamespace = (0, import_ramda.pipe)(
|
|
325
|
-
(kubernetesObject) => kubernetesObject?.metadata?.namespace,
|
|
326
|
-
(0, import_ramda.defaultTo)("")
|
|
327
|
-
);
|
|
328
|
-
var carriesNamespace = (0, import_ramda.pipe)(carriedNamespace, (0, import_ramda.equals)(""), import_ramda.not);
|
|
329
|
-
var carriedAnnotations = (0, import_ramda.pipe)(
|
|
330
|
-
(kubernetesObject) => kubernetesObject?.metadata?.annotations,
|
|
331
|
-
(0, import_ramda.defaultTo)({})
|
|
332
|
-
);
|
|
333
|
-
var carriesAnnotations = (0, import_ramda.pipe)(carriedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
|
|
334
|
-
var carriedLabels = (0, import_ramda.pipe)(
|
|
335
|
-
(kubernetesObject) => kubernetesObject?.metadata?.labels,
|
|
336
|
-
(0, import_ramda.defaultTo)({})
|
|
337
|
-
);
|
|
338
|
-
var carriesLabels = (0, import_ramda.pipe)(carriedLabels, (0, import_ramda.equals)({}), import_ramda.not);
|
|
339
|
-
var definesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
340
|
-
(binding) => binding?.filters?.deletionTimestamp ?? false,
|
|
341
|
-
(0, import_ramda.defaultTo)(false)
|
|
342
|
-
);
|
|
343
|
-
var ignoresDeletionTimestamp = (0, import_ramda.complement)(definesDeletionTimestamp);
|
|
344
|
-
var definedName = (0, import_ramda.pipe)((binding) => {
|
|
345
|
-
return binding.filters.name;
|
|
346
|
-
}, (0, import_ramda.defaultTo)(""));
|
|
347
|
-
var definesName = (0, import_ramda.pipe)(definedName, (0, import_ramda.equals)(""), import_ramda.not);
|
|
348
|
-
var ignoresName = (0, import_ramda.complement)(definesName);
|
|
349
|
-
var definedNameRegex = (0, import_ramda.pipe)(
|
|
350
|
-
(binding) => binding.filters?.regexName,
|
|
351
|
-
(0, import_ramda.defaultTo)("")
|
|
352
|
-
);
|
|
353
|
-
var definesNameRegex = (0, import_ramda.pipe)(definedNameRegex, (0, import_ramda.equals)(""), import_ramda.not);
|
|
354
|
-
var definedNamespaces = (0, import_ramda.pipe)((binding) => binding?.filters?.namespaces, (0, import_ramda.defaultTo)([]));
|
|
355
|
-
var definesNamespaces = (0, import_ramda.pipe)(definedNamespaces, (0, import_ramda.equals)([]), import_ramda.not);
|
|
356
|
-
var definedNamespaceRegexes = (0, import_ramda.pipe)((binding) => binding?.filters?.regexNamespaces, (0, import_ramda.defaultTo)([]));
|
|
357
|
-
var definesNamespaceRegexes = (0, import_ramda.pipe)(definedNamespaceRegexes, (0, import_ramda.equals)([]), import_ramda.not);
|
|
358
|
-
var definedAnnotations = (0, import_ramda.pipe)((binding) => binding?.filters?.annotations, (0, import_ramda.defaultTo)({}));
|
|
359
|
-
var definesAnnotations = (0, import_ramda.pipe)(definedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
|
|
360
|
-
var definedLabels = (0, import_ramda.pipe)((binding) => binding?.filters?.labels, (0, import_ramda.defaultTo)({}));
|
|
361
|
-
var definesLabels = (0, import_ramda.pipe)(definedLabels, (0, import_ramda.equals)({}), import_ramda.not);
|
|
362
|
-
var definedEvent = (binding) => {
|
|
363
|
-
return binding.event;
|
|
364
|
-
};
|
|
365
|
-
var definesDelete = (0, import_ramda.pipe)(definedEvent, (0, import_ramda.equals)("DELETE" /* DELETE */));
|
|
366
|
-
var definedGroup = (0, import_ramda.pipe)((binding) => binding?.kind?.group, (0, import_ramda.defaultTo)(""));
|
|
367
|
-
var definesGroup = (0, import_ramda.pipe)(definedGroup, (0, import_ramda.equals)(""), import_ramda.not);
|
|
368
|
-
var definedVersion = (0, import_ramda.pipe)(
|
|
369
|
-
(binding) => binding?.kind?.version,
|
|
370
|
-
(0, import_ramda.defaultTo)("")
|
|
371
|
-
);
|
|
372
|
-
var definesVersion = (0, import_ramda.pipe)(definedVersion, (0, import_ramda.equals)(""), import_ramda.not);
|
|
373
|
-
var definedKind = (0, import_ramda.pipe)((binding) => binding?.kind?.kind, (0, import_ramda.defaultTo)(""));
|
|
374
|
-
var definesKind = (0, import_ramda.pipe)(definedKind, (0, import_ramda.equals)(""), import_ramda.not);
|
|
375
|
-
var definedCallback = (binding) => {
|
|
376
|
-
return binding.isFinalize ? binding.finalizeCallback : binding.isWatch ? binding.watchCallback : binding.isMutate ? binding.mutateCallback : binding.isValidate ? binding.validateCallback : null;
|
|
377
|
-
};
|
|
378
|
-
var definedCallbackName = (0, import_ramda.pipe)(definedCallback, (0, import_ramda.defaultTo)({ name: "" }), (callback) => callback.name);
|
|
379
|
-
var mismatchedDeletionTimestamp = (0, import_ramda.allPass)([
|
|
380
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesDeletionTimestamp),
|
|
381
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), missingDeletionTimestamp)
|
|
382
|
-
]);
|
|
383
|
-
var mismatchedName = (0, import_ramda.allPass)([
|
|
384
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesName),
|
|
385
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => definedName(binding) !== carriedName(kubernetesObject))
|
|
386
|
-
]);
|
|
387
|
-
var mismatchedNameRegex = (0, import_ramda.allPass)([
|
|
388
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNameRegex),
|
|
389
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => new RegExp(definedNameRegex(binding)).test(carriedName(kubernetesObject)), import_ramda.not)
|
|
390
|
-
]);
|
|
391
|
-
var bindsToKind = (0, import_ramda.curry)(
|
|
392
|
-
(0, import_ramda.allPass)([(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definedKind, (0, import_ramda.equals)(""), import_ramda.not), (0, import_ramda.pipe)((binding, kind8) => definedKind(binding) === kind8)])
|
|
393
|
-
);
|
|
394
|
-
var bindsToNamespace = (0, import_ramda.curry)((0, import_ramda.pipe)(bindsToKind(import_ramda.__, "Namespace")));
|
|
395
|
-
var misboundNamespace = (0, import_ramda.allPass)([bindsToNamespace, definesNamespaces]);
|
|
396
|
-
var mismatchedNamespace = (0, import_ramda.allPass)([
|
|
397
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaces),
|
|
398
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => definedNamespaces(binding).includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
399
|
-
]);
|
|
400
|
-
var mismatchedNamespaceRegex = (0, import_ramda.allPass)([
|
|
401
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaceRegexes),
|
|
402
|
-
(0, import_ramda.pipe)(
|
|
403
|
-
(binding, kubernetesObject) => (0, import_ramda.pipe)(
|
|
404
|
-
(0, import_ramda.any)((regEx) => new RegExp(regEx).test(carriedNamespace(kubernetesObject))),
|
|
405
|
-
import_ramda.not
|
|
406
|
-
)(definedNamespaceRegexes(binding))
|
|
407
|
-
)
|
|
408
|
-
]);
|
|
409
|
-
var metasMismatch = (0, import_ramda.pipe)(
|
|
410
|
-
(defined, carried) => {
|
|
411
|
-
const result = { defined, carried, unalike: {} };
|
|
412
|
-
result.unalike = Object.entries(result.defined).map(([key, value]) => {
|
|
413
|
-
const keyMissing = !Object.hasOwn(result.carried, key);
|
|
414
|
-
const noValue = !value;
|
|
415
|
-
const valMissing = !result.carried[key];
|
|
416
|
-
const valDiffers = result.carried[key] !== result.defined[key];
|
|
417
|
-
return keyMissing ? { [key]: value } : noValue ? {} : valMissing ? { [key]: value } : valDiffers ? { [key]: value } : {};
|
|
418
|
-
}).reduce((acc, cur) => ({ ...acc, ...cur }), {});
|
|
419
|
-
return result.unalike;
|
|
420
|
-
},
|
|
421
|
-
(unalike) => Object.keys(unalike).length > 0
|
|
422
|
-
);
|
|
423
|
-
var mismatchedAnnotations = (0, import_ramda.allPass)([
|
|
424
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesAnnotations),
|
|
425
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedAnnotations(binding), carriedAnnotations(kubernetesObject)))
|
|
426
|
-
]);
|
|
427
|
-
var mismatchedLabels = (0, import_ramda.allPass)([
|
|
428
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesLabels),
|
|
429
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedLabels(binding), carriedLabels(kubernetesObject)))
|
|
430
|
-
]);
|
|
431
|
-
var uncarryableNamespace = (0, import_ramda.allPass)([
|
|
432
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
433
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
434
|
-
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
435
|
-
]);
|
|
436
|
-
var missingCarriableNamespace = (0, import_ramda.allPass)([
|
|
437
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
438
|
-
(0, import_ramda.pipe)(
|
|
439
|
-
(namespaceSelector, kubernetesObject) => kubernetesObject.kind === "Namespace" ? !namespaceSelector.includes(kubernetesObject.metadata.name) : !carriesNamespace(kubernetesObject)
|
|
440
|
-
)
|
|
441
|
-
]);
|
|
442
|
-
var carriesIgnoredNamespace = (0, import_ramda.allPass)([
|
|
443
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
444
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
445
|
-
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)))
|
|
446
|
-
]);
|
|
447
|
-
var unbindableNamespaces = (0, import_ramda.allPass)([
|
|
448
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
449
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), definesNamespaces),
|
|
450
|
-
(0, import_ramda.pipe)(
|
|
451
|
-
(namespaceSelector, binding) => (0, import_ramda.difference)(definedNamespaces(binding), namespaceSelector),
|
|
452
|
-
import_ramda.length,
|
|
453
|
-
(0, import_ramda.equals)(0),
|
|
454
|
-
import_ramda.not
|
|
455
|
-
)
|
|
456
|
-
]);
|
|
457
|
-
var misboundDeleteWithDeletionTimestamp = (0, import_ramda.allPass)([definesDelete, definesDeletionTimestamp]);
|
|
458
|
-
var operationMatchesEvent = (0, import_ramda.anyPass)([
|
|
459
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), (0, import_ramda.equals)("*" /* ANY */)),
|
|
460
|
-
(0, import_ramda.pipe)((operation, event) => operation.valueOf() === event.valueOf()),
|
|
461
|
-
(0, import_ramda.pipe)((operation, event) => operation ? event.includes(operation) : false)
|
|
462
|
-
]);
|
|
463
|
-
var mismatchedEvent = (0, import_ramda.pipe)(
|
|
464
|
-
(binding, request) => operationMatchesEvent(declaredOperation(request), definedEvent(binding)),
|
|
465
|
-
import_ramda.not
|
|
466
|
-
);
|
|
467
|
-
var mismatchedGroup = (0, import_ramda.allPass)([
|
|
468
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesGroup),
|
|
469
|
-
(0, import_ramda.pipe)((binding, request) => definedGroup(binding) !== declaredGroup(request))
|
|
470
|
-
]);
|
|
471
|
-
var mismatchedVersion = (0, import_ramda.allPass)([
|
|
472
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesVersion),
|
|
473
|
-
(0, import_ramda.pipe)((binding, request) => definedVersion(binding) !== declaredVersion(request))
|
|
474
|
-
]);
|
|
475
|
-
var mismatchedKind = (0, import_ramda.allPass)([
|
|
476
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesKind),
|
|
477
|
-
(0, import_ramda.pipe)((binding, request) => definedKind(binding) !== declaredKind(request))
|
|
478
|
-
]);
|
|
479
|
-
|
|
480
270
|
// src/lib/helpers.ts
|
|
481
271
|
function matchesRegex(pattern, testString) {
|
|
482
272
|
return new RegExp(pattern).test(testString);
|
|
@@ -571,7 +361,11 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
571
361
|
`Error in ${name2} capability. A binding violates namespace rules. Please check ignoredNamespaces and capability namespaces: ${namespaceError}`
|
|
572
362
|
);
|
|
573
363
|
}
|
|
574
|
-
|
|
364
|
+
matchRegexToCapababilityNamespace(bindingRegexNamespaces, capabilityNamespaces);
|
|
365
|
+
checkRegexNamespaces(bindingRegexNamespaces, ignoredNamespaces);
|
|
366
|
+
}
|
|
367
|
+
var matchRegexToCapababilityNamespace = (bindingRegexNamespaces, capabilityNamespaces) => {
|
|
368
|
+
if (bindingRegexNamespaces.length > 0 && capabilityNamespaces && capabilityNamespaces.length > 0) {
|
|
575
369
|
for (const regexNamespace of bindingRegexNamespaces) {
|
|
576
370
|
let matches = false;
|
|
577
371
|
matches = regexNamespace !== "" && capabilityNamespaces.some((capabilityNamespace) => matchesRegex(regexNamespace, capabilityNamespace));
|
|
@@ -582,7 +376,9 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
582
376
|
}
|
|
583
377
|
}
|
|
584
378
|
}
|
|
585
|
-
|
|
379
|
+
};
|
|
380
|
+
var checkRegexNamespaces = (bindingRegexNamespaces, ignoredNamespaces) => {
|
|
381
|
+
if (bindingRegexNamespaces.length > 0 && ignoredNamespaces && ignoredNamespaces.length > 0) {
|
|
586
382
|
for (const regexNamespace of bindingRegexNamespaces) {
|
|
587
383
|
const matchedNS = ignoredNamespaces.find((ignoredNS) => matchesRegex(regexNamespace, ignoredNS));
|
|
588
384
|
if (matchedNS) {
|
|
@@ -592,7 +388,7 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
592
388
|
}
|
|
593
389
|
}
|
|
594
390
|
}
|
|
595
|
-
}
|
|
391
|
+
};
|
|
596
392
|
function secretOverLimit(str) {
|
|
597
393
|
const encoder = new TextEncoder();
|
|
598
394
|
const encoded = encoder.encode(str);
|
|
@@ -600,7 +396,7 @@ function secretOverLimit(str) {
|
|
|
600
396
|
const oneMiBInBytes = 1048576;
|
|
601
397
|
return sizeInBytes > oneMiBInBytes;
|
|
602
398
|
}
|
|
603
|
-
var parseTimeout = (value
|
|
399
|
+
var parseTimeout = (value) => {
|
|
604
400
|
const parsedValue = parseInt(value, 10);
|
|
605
401
|
const floatValue = parseFloat(value);
|
|
606
402
|
if (isNaN(parsedValue)) {
|
|
@@ -633,7 +429,7 @@ function replaceString(str, stringA, stringB) {
|
|
|
633
429
|
}
|
|
634
430
|
|
|
635
431
|
// src/lib/assets/pods.ts
|
|
636
|
-
function
|
|
432
|
+
function getNamespace(namespaceLabels) {
|
|
637
433
|
if (namespaceLabels) {
|
|
638
434
|
return {
|
|
639
435
|
apiVersion: "v1",
|
|
@@ -653,7 +449,7 @@ function namespace(namespaceLabels) {
|
|
|
653
449
|
};
|
|
654
450
|
}
|
|
655
451
|
}
|
|
656
|
-
function
|
|
452
|
+
function getWatcher(assets, hash, buildTimestamp, imagePullSecret) {
|
|
657
453
|
const { name: name2, image, capabilities, config } = assets;
|
|
658
454
|
let hasSchedule = false;
|
|
659
455
|
const app = `${name2}-watcher`;
|
|
@@ -797,7 +593,7 @@ function watcher(assets, hash, buildTimestamp, imagePullSecret) {
|
|
|
797
593
|
}
|
|
798
594
|
return deploy2;
|
|
799
595
|
}
|
|
800
|
-
function
|
|
596
|
+
function getDeployment(assets, hash, buildTimestamp, imagePullSecret) {
|
|
801
597
|
const { name: name2, image, config } = assets;
|
|
802
598
|
const app = name2;
|
|
803
599
|
const deploy2 = {
|
|
@@ -938,7 +734,7 @@ function deployment(assets, hash, buildTimestamp, imagePullSecret) {
|
|
|
938
734
|
}
|
|
939
735
|
return deploy2;
|
|
940
736
|
}
|
|
941
|
-
function
|
|
737
|
+
function getModuleSecret(name2, data, hash) {
|
|
942
738
|
const compressed = (0, import_zlib.gzipSync)(data);
|
|
943
739
|
const path = `module-${hash}.js.gz`;
|
|
944
740
|
const compressedData = compressed.toString("base64");
|
|
@@ -1134,51 +930,40 @@ var peprStoreCRD = {
|
|
|
1134
930
|
};
|
|
1135
931
|
|
|
1136
932
|
// src/lib/assets/webhooks.ts
|
|
1137
|
-
var
|
|
933
|
+
var import_ramda = require("ramda");
|
|
1138
934
|
var peprIgnoreLabel = {
|
|
1139
935
|
key: "pepr.dev",
|
|
1140
936
|
operator: "NotIn",
|
|
1141
937
|
values: ["ignore"]
|
|
1142
938
|
};
|
|
1143
939
|
var peprIgnoreNamespaces = ["kube-system", "pepr-system"];
|
|
940
|
+
var validateRule = (binding, isMutateWebhook) => {
|
|
941
|
+
const { event, kind: kind8, isMutate, isValidate } = binding;
|
|
942
|
+
if (isMutateWebhook && !isMutate || !isMutateWebhook && !isValidate) {
|
|
943
|
+
return void 0;
|
|
944
|
+
}
|
|
945
|
+
const operations = event === "CREATEORUPDATE" /* CREATE_OR_UPDATE */ ? ["CREATE" /* CREATE */, "UPDATE" /* UPDATE */] : [event];
|
|
946
|
+
const resource = kind8.plural || `${kind8.kind.toLowerCase()}s`;
|
|
947
|
+
const ruleObject = {
|
|
948
|
+
apiGroups: [kind8.group],
|
|
949
|
+
apiVersions: [kind8.version || "*"],
|
|
950
|
+
operations,
|
|
951
|
+
resources: [resource, ...resource === "pods" ? ["pods/ephemeralcontainers"] : []]
|
|
952
|
+
};
|
|
953
|
+
return ruleObject;
|
|
954
|
+
};
|
|
1144
955
|
async function generateWebhookRules(assets, isMutateWebhook) {
|
|
1145
956
|
const { config, capabilities } = assets;
|
|
1146
|
-
const rules =
|
|
1147
|
-
for (const capability of capabilities) {
|
|
957
|
+
const rules = capabilities.flatMap((capability) => {
|
|
1148
958
|
console.info(`Module ${config.uuid} has capability: ${capability.name}`);
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
continue;
|
|
1153
|
-
}
|
|
1154
|
-
if (!isMutateWebhook && !isValidate) {
|
|
1155
|
-
continue;
|
|
1156
|
-
}
|
|
1157
|
-
const operations = [];
|
|
1158
|
-
if (event === "CREATEORUPDATE" /* CREATE_OR_UPDATE */) {
|
|
1159
|
-
operations.push("CREATE" /* CREATE */, "UPDATE" /* UPDATE */);
|
|
1160
|
-
} else {
|
|
1161
|
-
operations.push(event);
|
|
1162
|
-
}
|
|
1163
|
-
const resource = kind8.plural || `${kind8.kind.toLowerCase()}s`;
|
|
1164
|
-
const ruleObject = {
|
|
1165
|
-
apiGroups: [kind8.group],
|
|
1166
|
-
apiVersions: [kind8.version || "*"],
|
|
1167
|
-
operations,
|
|
1168
|
-
resources: [resource]
|
|
1169
|
-
};
|
|
1170
|
-
if (resource === "pods") {
|
|
1171
|
-
ruleObject.resources.push("pods/ephemeralcontainers");
|
|
1172
|
-
}
|
|
1173
|
-
rules.push(ruleObject);
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
return (0, import_ramda2.uniqWith)(import_ramda2.equals, rules);
|
|
959
|
+
return capability.bindings.map((binding) => validateRule(binding, isMutateWebhook)).filter((rule) => !!rule);
|
|
960
|
+
});
|
|
961
|
+
return (0, import_ramda.uniqWith)(import_ramda.equals, rules);
|
|
1177
962
|
}
|
|
1178
963
|
async function webhookConfig(assets, mutateOrValidate, timeoutSeconds = 10) {
|
|
1179
964
|
const ignore = [peprIgnoreLabel];
|
|
1180
965
|
const { name: name2, tls, config, apiToken, host } = assets;
|
|
1181
|
-
const ignoreNS = (0,
|
|
966
|
+
const ignoreNS = (0, import_ramda.concat)(peprIgnoreNamespaces, config?.alwaysIgnore?.namespaces || []);
|
|
1182
967
|
if (ignoreNS) {
|
|
1183
968
|
ignore.push({
|
|
1184
969
|
key: "kubernetes.io/metadata.name",
|
|
@@ -1235,7 +1020,7 @@ async function deployImagePullSecret(imagePullSecret, name2) {
|
|
|
1235
1020
|
try {
|
|
1236
1021
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Namespace).Get("pepr-system");
|
|
1237
1022
|
} catch {
|
|
1238
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Namespace).Apply(
|
|
1023
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Namespace).Apply(getNamespace());
|
|
1239
1024
|
}
|
|
1240
1025
|
try {
|
|
1241
1026
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(
|
|
@@ -1261,7 +1046,7 @@ async function deploy(assets, force, webhookTimeout) {
|
|
|
1261
1046
|
logger_default.info("Establishing connection to Kubernetes");
|
|
1262
1047
|
const { name: name2, host, path } = assets;
|
|
1263
1048
|
logger_default.info("Applying pepr-system namespace");
|
|
1264
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Namespace).Apply(
|
|
1049
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Namespace).Apply(getNamespace(assets.config.customLabels?.namespace));
|
|
1265
1050
|
const mutateWebhook = await webhookConfig(assets, "mutate", webhookTimeout);
|
|
1266
1051
|
if (mutateWebhook) {
|
|
1267
1052
|
logger_default.info("Applying mutating webhook");
|
|
@@ -1283,7 +1068,7 @@ async function deploy(assets, force, webhookTimeout) {
|
|
|
1283
1068
|
if (host) {
|
|
1284
1069
|
return;
|
|
1285
1070
|
}
|
|
1286
|
-
const code = await
|
|
1071
|
+
const code = await import_fs.promises.readFile(path);
|
|
1287
1072
|
const hash = import_crypto.default.createHash("sha256").update(code).digest("hex");
|
|
1288
1073
|
if (code.length < 1) {
|
|
1289
1074
|
throw new Error("No code provided");
|
|
@@ -1313,7 +1098,7 @@ async function setupRBAC(name2, capabilities, force, config) {
|
|
|
1313
1098
|
async function setupController(assets, code, hash, force) {
|
|
1314
1099
|
const { name: name2 } = assets;
|
|
1315
1100
|
logger_default.info("Applying module secret");
|
|
1316
|
-
const mod =
|
|
1101
|
+
const mod = getModuleSecret(name2, code, hash);
|
|
1317
1102
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(mod, { force });
|
|
1318
1103
|
logger_default.info("Applying controller service");
|
|
1319
1104
|
const svc = service(name2);
|
|
@@ -1325,11 +1110,11 @@ async function setupController(assets, code, hash, force) {
|
|
|
1325
1110
|
const apiToken = apiTokenSecret(name2, assets.apiToken);
|
|
1326
1111
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(apiToken, { force });
|
|
1327
1112
|
logger_default.info("Applying deployment");
|
|
1328
|
-
const dep =
|
|
1113
|
+
const dep = getDeployment(assets, hash, assets.buildTimestamp);
|
|
1329
1114
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(dep, { force });
|
|
1330
1115
|
}
|
|
1331
1116
|
async function setupWatcher(assets, hash, force) {
|
|
1332
|
-
const watchDeployment =
|
|
1117
|
+
const watchDeployment = getWatcher(assets, hash, assets.buildTimestamp);
|
|
1333
1118
|
if (watchDeployment) {
|
|
1334
1119
|
logger_default.info("Applying watcher deployment");
|
|
1335
1120
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(watchDeployment, { force });
|
|
@@ -1342,7 +1127,7 @@ async function setupWatcher(assets, hash, force) {
|
|
|
1342
1127
|
// src/lib/assets/loader.ts
|
|
1343
1128
|
var import_child_process = require("child_process");
|
|
1344
1129
|
function loadCapabilities(path) {
|
|
1345
|
-
return new Promise((
|
|
1130
|
+
return new Promise((resolve6, reject) => {
|
|
1346
1131
|
const program2 = (0, import_child_process.fork)(path, {
|
|
1347
1132
|
env: {
|
|
1348
1133
|
...process.env,
|
|
@@ -1356,7 +1141,7 @@ function loadCapabilities(path) {
|
|
|
1356
1141
|
for (const capability of capabilities) {
|
|
1357
1142
|
console.info(`Registered Pepr Capability "${capability.name}"`);
|
|
1358
1143
|
}
|
|
1359
|
-
|
|
1144
|
+
resolve6(capabilities);
|
|
1360
1145
|
});
|
|
1361
1146
|
program2.on("error", (error) => {
|
|
1362
1147
|
reject(error);
|
|
@@ -1367,7 +1152,7 @@ function loadCapabilities(path) {
|
|
|
1367
1152
|
// src/lib/assets/yaml.ts
|
|
1368
1153
|
var import_client_node = require("@kubernetes/client-node");
|
|
1369
1154
|
var import_crypto2 = __toESM(require("crypto"));
|
|
1370
|
-
var
|
|
1155
|
+
var import_fs2 = require("fs");
|
|
1371
1156
|
async function overridesFile({ hash, name: name2, image, config, apiToken, capabilities }, path) {
|
|
1372
1157
|
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
1373
1158
|
const overrides = {
|
|
@@ -1518,7 +1303,7 @@ async function overridesFile({ hash, name: name2, image, config, apiToken, capab
|
|
|
1518
1303
|
}
|
|
1519
1304
|
}
|
|
1520
1305
|
};
|
|
1521
|
-
await
|
|
1306
|
+
await import_fs2.promises.writeFile(path, (0, import_client_node.dumpYaml)(overrides, { noRefs: true, forceQuotes: true }));
|
|
1522
1307
|
}
|
|
1523
1308
|
function zarfYaml({ name: name2, image, config }, path) {
|
|
1524
1309
|
const zarfCfg = {
|
|
@@ -1575,22 +1360,22 @@ function zarfYamlChart({ name: name2, image, config }, path) {
|
|
|
1575
1360
|
}
|
|
1576
1361
|
async function allYaml(assets, imagePullSecret) {
|
|
1577
1362
|
const { name: name2, tls, apiToken, path, config } = assets;
|
|
1578
|
-
const code = await
|
|
1363
|
+
const code = await import_fs2.promises.readFile(path);
|
|
1579
1364
|
assets.hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
1580
1365
|
const mutateWebhook = await webhookConfig(assets, "mutate", assets.config.webhookTimeout);
|
|
1581
1366
|
const validateWebhook = await webhookConfig(assets, "validate", assets.config.webhookTimeout);
|
|
1582
|
-
const watchDeployment =
|
|
1367
|
+
const watchDeployment = getWatcher(assets, assets.hash, assets.buildTimestamp, imagePullSecret);
|
|
1583
1368
|
const resources = [
|
|
1584
|
-
|
|
1369
|
+
getNamespace(assets.config.customLabels?.namespace),
|
|
1585
1370
|
clusterRole(name2, assets.capabilities, config.rbacMode, config.rbac),
|
|
1586
1371
|
clusterRoleBinding(name2),
|
|
1587
1372
|
serviceAccount(name2),
|
|
1588
1373
|
apiTokenSecret(name2, apiToken),
|
|
1589
1374
|
tlsSecret(name2, tls),
|
|
1590
|
-
|
|
1375
|
+
getDeployment(assets, assets.hash, assets.buildTimestamp, imagePullSecret),
|
|
1591
1376
|
service(name2),
|
|
1592
1377
|
watcherService(name2),
|
|
1593
|
-
|
|
1378
|
+
getModuleSecret(name2, code, assets.hash),
|
|
1594
1379
|
storeRole(name2),
|
|
1595
1380
|
storeRoleBinding(name2)
|
|
1596
1381
|
];
|
|
@@ -1623,7 +1408,7 @@ function clusterRoleTemplate() {
|
|
|
1623
1408
|
{{- end }}
|
|
1624
1409
|
`;
|
|
1625
1410
|
}
|
|
1626
|
-
function
|
|
1411
|
+
function namespaceTemplate() {
|
|
1627
1412
|
return `
|
|
1628
1413
|
apiVersion: v1
|
|
1629
1414
|
kind: Namespace
|
|
@@ -1860,16 +1645,16 @@ function serviceMonitorTemplate(name2) {
|
|
|
1860
1645
|
}
|
|
1861
1646
|
|
|
1862
1647
|
// src/lib/assets/index.ts
|
|
1863
|
-
var
|
|
1648
|
+
var import_fs4 = require("fs");
|
|
1864
1649
|
|
|
1865
1650
|
// src/lib/filesystemService.ts
|
|
1866
|
-
var
|
|
1651
|
+
var import_fs3 = require("fs");
|
|
1867
1652
|
async function createDirectoryIfNotExists(path) {
|
|
1868
1653
|
try {
|
|
1869
|
-
await
|
|
1654
|
+
await import_fs3.promises.access(path);
|
|
1870
1655
|
} catch (error) {
|
|
1871
1656
|
if (error.code === "ENOENT") {
|
|
1872
|
-
await
|
|
1657
|
+
await import_fs3.promises.mkdir(path, { recursive: true });
|
|
1873
1658
|
} else {
|
|
1874
1659
|
throw error;
|
|
1875
1660
|
}
|
|
@@ -1972,10 +1757,10 @@ var Assets = class {
|
|
|
1972
1757
|
await Promise.all(
|
|
1973
1758
|
Object.values(helm.dirs).sort((l, r) => l.split("/").length - r.split("/").length).map(async (dir) => await createDirectoryIfNotExists(dir))
|
|
1974
1759
|
);
|
|
1975
|
-
const code = await
|
|
1760
|
+
const code = await import_fs4.promises.readFile(this.path);
|
|
1976
1761
|
const pairs = [
|
|
1977
1762
|
[helm.files.chartYaml, () => dedent(chartYaml(this.config.uuid, this.config.description || ""))],
|
|
1978
|
-
[helm.files.namespaceYaml, () => dedent(
|
|
1763
|
+
[helm.files.namespaceYaml, () => dedent(namespaceTemplate())],
|
|
1979
1764
|
[helm.files.watcherServiceYaml, () => toYaml(watcherService(this.name))],
|
|
1980
1765
|
[helm.files.admissionServiceYaml, () => toYaml(service(this.name))],
|
|
1981
1766
|
[helm.files.tlsSecretYaml, () => toYaml(tlsSecret(this.name, this.tls))],
|
|
@@ -1985,28 +1770,28 @@ var Assets = class {
|
|
|
1985
1770
|
[helm.files.clusterRoleYaml, () => dedent(clusterRoleTemplate())],
|
|
1986
1771
|
[helm.files.clusterRoleBindingYaml, () => toYaml(clusterRoleBinding(this.name))],
|
|
1987
1772
|
[helm.files.serviceAccountYaml, () => toYaml(serviceAccount(this.name))],
|
|
1988
|
-
[helm.files.moduleSecretYaml, () => toYaml(
|
|
1773
|
+
[helm.files.moduleSecretYaml, () => toYaml(getModuleSecret(this.name, code, this.hash))]
|
|
1989
1774
|
];
|
|
1990
|
-
await Promise.all(pairs.map(async ([file, content]) => await
|
|
1775
|
+
await Promise.all(pairs.map(async ([file, content]) => await import_fs4.promises.writeFile(file, content())));
|
|
1991
1776
|
await overridesFile(this, helm.files.valuesYaml);
|
|
1992
1777
|
const [mutateWebhook, validateWebhook] = await Promise.all([
|
|
1993
1778
|
webhookConfig(this, "mutate", this.config.webhookTimeout),
|
|
1994
1779
|
webhookConfig(this, "validate", this.config.webhookTimeout)
|
|
1995
1780
|
]);
|
|
1996
1781
|
if (validateWebhook || mutateWebhook) {
|
|
1997
|
-
await
|
|
1998
|
-
await
|
|
1782
|
+
await import_fs4.promises.writeFile(helm.files.admissionDeploymentYaml, dedent(admissionDeployTemplate(this.buildTimestamp)));
|
|
1783
|
+
await import_fs4.promises.writeFile(helm.files.admissionServiceMonitorYaml, dedent(serviceMonitorTemplate("admission")));
|
|
1999
1784
|
}
|
|
2000
1785
|
if (mutateWebhook) {
|
|
2001
|
-
await
|
|
1786
|
+
await import_fs4.promises.writeFile(helm.files.mutationWebhookYaml, createWebhookYaml(this, mutateWebhook));
|
|
2002
1787
|
}
|
|
2003
1788
|
if (validateWebhook) {
|
|
2004
|
-
await
|
|
1789
|
+
await import_fs4.promises.writeFile(helm.files.validationWebhookYaml, createWebhookYaml(this, validateWebhook));
|
|
2005
1790
|
}
|
|
2006
|
-
const watchDeployment =
|
|
1791
|
+
const watchDeployment = getWatcher(this, this.hash, this.buildTimestamp);
|
|
2007
1792
|
if (watchDeployment) {
|
|
2008
|
-
await
|
|
2009
|
-
await
|
|
1793
|
+
await import_fs4.promises.writeFile(helm.files.watcherDeploymentYaml, dedent(watcherDeployTemplate(this.buildTimestamp)));
|
|
1794
|
+
await import_fs4.promises.writeFile(helm.files.watcherServiceMonitorYaml, dedent(serviceMonitorTemplate("watcher")));
|
|
2010
1795
|
}
|
|
2011
1796
|
} catch (err) {
|
|
2012
1797
|
console.error(`Error generating helm chart: ${err.message}`);
|
|
@@ -2222,7 +2007,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
2222
2007
|
var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
|
|
2223
2008
|
var peprTS = 'import { PeprModule } from "pepr";\n// cfg loads your pepr configuration from package.json\nimport cfg from "./package.json";\n\n// HelloPepr is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\nimport { HelloPepr } from "./capabilities/hello-pepr";\n\n/**\n * This is the main entrypoint for this Pepr module. It is run when the module is started.\n * This is where you register your Pepr configurations and capabilities.\n */\nnew PeprModule(cfg, [\n // "HelloPepr" is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n';
|
|
2224
2009
|
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\nimport { MockAgent, setGlobalDispatcher } from "undici";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://icanhazdadjoke.com/");\n * const joke = await fetch("https://icanhazdadjoke.com/") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://icanhazdadjoke.com")\n * ```\n */\ninterface TheChuckNorrisJoke {\n id: string;\n joke: string;\n status: number;\n}\n\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("chuck-norris")\n .Mutate(cm => cm.SetLabel("got-jokes", "true"))\n .Watch(async cm => {\n const jokeURL = "https://icanhazdadjoke.com";\n\n const mockAgent: MockAgent = new MockAgent();\n setGlobalDispatcher(mockAgent);\n const mockClient = mockAgent.get(jokeURL);\n mockClient.intercept({ path: "/", method: "GET" }).reply(\n 200,\n {\n id: "R7UfaahVfFd",\n joke: "Funny joke goes here.",\n status: 200,\n },\n {\n headers: {\n "Content-Type": "application/json; charset=utf-8",\n },\n },\n );\n\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(jokeURL, {\n headers: {\n Accept: "application/json",\n },\n });\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n const { joke } = response.data;\n // Add Joke to the Store\n await Store.setItemAndWait(jokeURL, joke);\n // Add the Chuck Norris joke to the configmap\n try {\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: cm.metadata.name,\n namespace: cm.metadata.namespace,\n },\n data: {\n "chuck-says": Store.getItem(jokeURL),\n },\n });\n } catch (error) {\n Log.error(error, "Failed to apply ConfigMap using server-side apply.", {\n cm,\n });\n }\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
|
|
2225
|
-
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!dist/**/*.test.d.ts*"], version: "0.42.
|
|
2010
|
+
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!dist/**/*.test.d.ts*"], version: "0.42.2", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", version: "node scripts/set-version.js", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns='cosign.e2e.test.ts'", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", express: "4.21.2", "fast-json-patch": "3.1.1", "follow-redirects": "1.15.9", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.3.7", pino: "9.6.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.0.0" }, devDependencies: { "@commitlint/cli": "19.6.1", "@commitlint/config-conventional": "19.6.0", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.0", "@types/follow-redirects": "1.14.4", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^3.19.0", husky: "^9.1.6", jest: "29.7.0", "js-yaml": "^4.1.0", "ts-jest": "29.2.5", undici: "^7.0.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/parser": "7.18.0", "@types/prompts": "2.4.9", eslint: "8.57.0", commander: "12.1.0", esbuild: "0.24.0", "node-forge": "1.3.1", prettier: "3.4.2", prompts: "2.4.2", typescript: "^5.3.3", uuid: "11.0.3" } };
|
|
2226
2011
|
|
|
2227
2012
|
// src/templates/pepr.code-snippets.json
|
|
2228
2013
|
var pepr_code_snippets_default = {
|
|
@@ -2281,7 +2066,7 @@ var tsconfig_module_default = {
|
|
|
2281
2066
|
};
|
|
2282
2067
|
|
|
2283
2068
|
// src/cli/init/utils.ts
|
|
2284
|
-
var
|
|
2069
|
+
var import_fs5 = require("fs");
|
|
2285
2070
|
function sanitizeName(name2) {
|
|
2286
2071
|
if (typeof name2 !== "string") {
|
|
2287
2072
|
throw TypeError(
|
|
@@ -2295,7 +2080,7 @@ function sanitizeName(name2) {
|
|
|
2295
2080
|
}
|
|
2296
2081
|
async function createDir(dir) {
|
|
2297
2082
|
try {
|
|
2298
|
-
await
|
|
2083
|
+
await import_fs5.promises.mkdir(dir);
|
|
2299
2084
|
} catch (err) {
|
|
2300
2085
|
if (err && err.code === "EEXIST") {
|
|
2301
2086
|
throw new Error(`Directory ${dir} already exists`);
|
|
@@ -2308,7 +2093,7 @@ function write(path, data) {
|
|
|
2308
2093
|
if (typeof data !== "string") {
|
|
2309
2094
|
data = JSON.stringify(data, null, 2);
|
|
2310
2095
|
}
|
|
2311
|
-
return
|
|
2096
|
+
return import_fs5.promises.writeFile(path, data);
|
|
2312
2097
|
}
|
|
2313
2098
|
|
|
2314
2099
|
// src/cli/init/templates.ts
|
|
@@ -2404,10 +2189,32 @@ var eslint = {
|
|
|
2404
2189
|
data: eslintrc_template_default
|
|
2405
2190
|
};
|
|
2406
2191
|
|
|
2192
|
+
// src/cli/build.ts
|
|
2193
|
+
var import_commander = require("commander");
|
|
2194
|
+
|
|
2407
2195
|
// src/cli/format.ts
|
|
2408
2196
|
var import_eslint = require("eslint");
|
|
2409
|
-
|
|
2197
|
+
|
|
2198
|
+
// src/cli/format.helpers.ts
|
|
2199
|
+
var import_fs6 = require("fs");
|
|
2410
2200
|
var import_prettier = require("prettier");
|
|
2201
|
+
async function formatWithPrettier(results, validateOnly) {
|
|
2202
|
+
let hasFailure = false;
|
|
2203
|
+
for (const { filePath } of results) {
|
|
2204
|
+
const content = await import_fs6.promises.readFile(filePath, "utf8");
|
|
2205
|
+
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
2206
|
+
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
2207
|
+
if (validateOnly && formatted !== content) {
|
|
2208
|
+
hasFailure = true;
|
|
2209
|
+
console.error(`File ${filePath} is not formatted correctly`);
|
|
2210
|
+
} else {
|
|
2211
|
+
await import_fs6.promises.writeFile(filePath, formatted);
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
return hasFailure;
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
// src/cli/format.ts
|
|
2411
2218
|
function format_default(program2) {
|
|
2412
2219
|
program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
|
|
2413
2220
|
const success = await peprFormat(opts.validateOnly);
|
|
@@ -2438,17 +2245,7 @@ async function peprFormat(validateOnly) {
|
|
|
2438
2245
|
if (!validateOnly) {
|
|
2439
2246
|
await import_eslint.ESLint.outputFixes(results);
|
|
2440
2247
|
}
|
|
2441
|
-
|
|
2442
|
-
const content = await import_fs7.promises.readFile(filePath, "utf8");
|
|
2443
|
-
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
2444
|
-
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
2445
|
-
if (validateOnly && formatted !== content) {
|
|
2446
|
-
hasFailure = true;
|
|
2447
|
-
console.error(`File ${filePath} is not formatted correctly`);
|
|
2448
|
-
} else {
|
|
2449
|
-
await import_fs7.promises.writeFile(filePath, formatted);
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2248
|
+
hasFailure = await formatWithPrettier(results, validateOnly);
|
|
2452
2249
|
return !hasFailure;
|
|
2453
2250
|
} catch (e) {
|
|
2454
2251
|
console.error(`Error formatting module:`, e);
|
|
@@ -2457,10 +2254,27 @@ async function peprFormat(validateOnly) {
|
|
|
2457
2254
|
}
|
|
2458
2255
|
}
|
|
2459
2256
|
|
|
2460
|
-
// src/
|
|
2461
|
-
var
|
|
2257
|
+
// src/lib/included-files.ts
|
|
2258
|
+
var import_fs7 = require("fs");
|
|
2259
|
+
async function createDockerfile(version3, description, includedFiles) {
|
|
2260
|
+
const file = `
|
|
2261
|
+
# Use an official Node.js runtime as the base image
|
|
2262
|
+
FROM ghcr.io/defenseunicorns/pepr/controller:v${version3}
|
|
2263
|
+
|
|
2264
|
+
LABEL description="${description}"
|
|
2265
|
+
|
|
2266
|
+
# Add the included files to the image
|
|
2267
|
+
${includedFiles.map((f) => `ADD ${f} ${f}`).join("\n")}
|
|
2268
|
+
|
|
2269
|
+
`;
|
|
2270
|
+
await import_fs7.promises.writeFile("Dockerfile.controller", file, { encoding: "utf-8" });
|
|
2271
|
+
}
|
|
2462
2272
|
|
|
2463
2273
|
// src/cli/build.helpers.ts
|
|
2274
|
+
var import_child_process2 = require("child_process");
|
|
2275
|
+
var import_esbuild = require("esbuild");
|
|
2276
|
+
var import_path2 = require("path");
|
|
2277
|
+
var import_fs8 = require("fs");
|
|
2464
2278
|
function determineRbacMode(opts, cfg) {
|
|
2465
2279
|
if (opts.rbacMode) {
|
|
2466
2280
|
return opts.rbacMode;
|
|
@@ -2470,6 +2284,93 @@ function determineRbacMode(opts, cfg) {
|
|
|
2470
2284
|
}
|
|
2471
2285
|
return cfg.pepr.rbacMode || "admin";
|
|
2472
2286
|
}
|
|
2287
|
+
async function handleCustomOutputDir(outputDir2) {
|
|
2288
|
+
const defaultOutputDir = "dist";
|
|
2289
|
+
if (outputDir2) {
|
|
2290
|
+
try {
|
|
2291
|
+
await createDirectoryIfNotExists(outputDir2);
|
|
2292
|
+
return outputDir2;
|
|
2293
|
+
} catch (error) {
|
|
2294
|
+
console.error(`Error creating output directory: ${error.message}`);
|
|
2295
|
+
process.exit(1);
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
return defaultOutputDir;
|
|
2299
|
+
}
|
|
2300
|
+
function checkIronBankImage(registry, image, peprVersion) {
|
|
2301
|
+
return registry === "Iron Bank" ? `registry1.dso.mil/ironbank/opensource/defenseunicorns/pepr/controller:v${peprVersion}` : image;
|
|
2302
|
+
}
|
|
2303
|
+
function validImagePullSecret(imagePullSecretName) {
|
|
2304
|
+
if (imagePullSecretName) {
|
|
2305
|
+
const error = "Invalid imagePullSecret. Please provide a valid name as defined in RFC 1123.";
|
|
2306
|
+
if (sanitizeResourceName(imagePullSecretName) !== imagePullSecretName) {
|
|
2307
|
+
console.error(error);
|
|
2308
|
+
process.exit(1);
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
function handleCustomImage(customImage, registry) {
|
|
2313
|
+
let defaultImage = "";
|
|
2314
|
+
if (customImage) {
|
|
2315
|
+
if (registry) {
|
|
2316
|
+
console.error(`Custom Image and registry cannot be used together.`);
|
|
2317
|
+
process.exit(1);
|
|
2318
|
+
}
|
|
2319
|
+
defaultImage = customImage;
|
|
2320
|
+
}
|
|
2321
|
+
return defaultImage;
|
|
2322
|
+
}
|
|
2323
|
+
async function handleCustomImageBuild(includedFiles, peprVersion, description, image) {
|
|
2324
|
+
if (includedFiles.length > 0) {
|
|
2325
|
+
await createDockerfile(peprVersion, description, includedFiles);
|
|
2326
|
+
(0, import_child_process2.execSync)(`docker build --tag ${image} -f Dockerfile.controller .`, {
|
|
2327
|
+
stdio: "inherit"
|
|
2328
|
+
});
|
|
2329
|
+
(0, import_child_process2.execSync)(`docker push ${image}`, { stdio: "inherit" });
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
function handleEmbedding(embed, path) {
|
|
2333
|
+
if (!embed) {
|
|
2334
|
+
console.info(`\u2705 Module built successfully at ${path}`);
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
function handleValidCapabilityNames(capabilities) {
|
|
2339
|
+
try {
|
|
2340
|
+
validateCapabilityNames(capabilities);
|
|
2341
|
+
} catch (e) {
|
|
2342
|
+
console.error(`Error loading capability:`, e);
|
|
2343
|
+
process.exit(1);
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
async function watchForChanges(ctxCfg, reloader) {
|
|
2347
|
+
const ctx = await (0, import_esbuild.context)(ctxCfg);
|
|
2348
|
+
if (reloader) {
|
|
2349
|
+
await ctx.watch();
|
|
2350
|
+
} else {
|
|
2351
|
+
await ctx.rebuild();
|
|
2352
|
+
await ctx.dispose();
|
|
2353
|
+
}
|
|
2354
|
+
return ctx;
|
|
2355
|
+
}
|
|
2356
|
+
async function generateYamlAndWriteToDisk(obj) {
|
|
2357
|
+
const { uuid, imagePullSecret, outputDir: outputDir2, assets, zarf } = obj;
|
|
2358
|
+
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
2359
|
+
const chartPath = `${uuid}-chart`;
|
|
2360
|
+
const yamlPath = (0, import_path2.resolve)(outputDir2, yamlFile);
|
|
2361
|
+
const yaml = await assets.allYaml(imagePullSecret);
|
|
2362
|
+
const zarfPath = (0, import_path2.resolve)(outputDir2, "zarf.yaml");
|
|
2363
|
+
let localZarf = "";
|
|
2364
|
+
if (zarf === "chart") {
|
|
2365
|
+
localZarf = assets.zarfYamlChart(chartPath);
|
|
2366
|
+
} else {
|
|
2367
|
+
localZarf = assets.zarfYaml(yamlFile);
|
|
2368
|
+
}
|
|
2369
|
+
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2370
|
+
await import_fs8.promises.writeFile(zarfPath, localZarf);
|
|
2371
|
+
await assets.generateHelmChart(outputDir2);
|
|
2372
|
+
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
2373
|
+
}
|
|
2473
2374
|
|
|
2474
2375
|
// src/cli/build.ts
|
|
2475
2376
|
var peprTS2 = "pepr.ts";
|
|
@@ -2509,46 +2410,22 @@ function build_default(program2) {
|
|
|
2509
2410
|
["admin", "scoped"]
|
|
2510
2411
|
)
|
|
2511
2412
|
).action(async (opts) => {
|
|
2512
|
-
|
|
2513
|
-
outputDir = opts.outputDir;
|
|
2514
|
-
createDirectoryIfNotExists(outputDir).catch((error) => {
|
|
2515
|
-
console.error(`Error creating output directory: ${error.message}`);
|
|
2516
|
-
process.exit(1);
|
|
2517
|
-
});
|
|
2518
|
-
}
|
|
2413
|
+
outputDir = await handleCustomOutputDir(opts.outputDir);
|
|
2519
2414
|
const buildModuleResult = await buildModule(void 0, opts.entryPoint, opts.embed);
|
|
2520
2415
|
if (buildModuleResult?.cfg && buildModuleResult.path && buildModuleResult.uuid) {
|
|
2521
2416
|
const { cfg, path, uuid } = buildModuleResult;
|
|
2522
2417
|
const { includedFiles } = cfg.pepr;
|
|
2523
|
-
let image =
|
|
2524
|
-
if (opts.customImage) {
|
|
2525
|
-
if (opts.registry) {
|
|
2526
|
-
console.error(`Custom Image and registry cannot be used together.`);
|
|
2527
|
-
process.exit(1);
|
|
2528
|
-
}
|
|
2529
|
-
image = opts.customImage;
|
|
2530
|
-
}
|
|
2418
|
+
let image = handleCustomImage(opts.customImage, opts.registry);
|
|
2531
2419
|
if (opts.timeout !== void 0) {
|
|
2532
2420
|
cfg.pepr.webhookTimeout = opts.timeout;
|
|
2533
2421
|
}
|
|
2534
2422
|
if (opts.registryInfo !== void 0) {
|
|
2535
2423
|
console.info(`Including ${includedFiles.length} files in controller image.`);
|
|
2536
2424
|
image = `${opts.registryInfo}/custom-pepr-controller:${cfg.pepr.peprVersion}`;
|
|
2537
|
-
|
|
2538
|
-
await createDockerfile(cfg.pepr.peprVersion, cfg.description, includedFiles);
|
|
2539
|
-
(0, import_child_process2.execSync)(`docker build --tag ${image} -f Dockerfile.controller .`, {
|
|
2540
|
-
stdio: "inherit"
|
|
2541
|
-
});
|
|
2542
|
-
(0, import_child_process2.execSync)(`docker push ${image}`, { stdio: "inherit" });
|
|
2543
|
-
}
|
|
2544
|
-
}
|
|
2545
|
-
if (!opts.embed) {
|
|
2546
|
-
console.info(`\u2705 Module built successfully at ${path}`);
|
|
2547
|
-
return;
|
|
2548
|
-
}
|
|
2549
|
-
if (opts.version) {
|
|
2550
|
-
cfg.pepr.peprVersion = opts.version;
|
|
2425
|
+
await handleCustomImageBuild(includedFiles, cfg.pepr.peprVersion, cfg.description, image);
|
|
2551
2426
|
}
|
|
2427
|
+
handleEmbedding(opts.embed, path);
|
|
2428
|
+
opts.version ? cfg.pepr.peprVersion = opts.version : null;
|
|
2552
2429
|
const assets = new Assets(
|
|
2553
2430
|
{
|
|
2554
2431
|
...cfg.pepr,
|
|
@@ -2559,46 +2436,17 @@ function build_default(program2) {
|
|
|
2559
2436
|
},
|
|
2560
2437
|
path
|
|
2561
2438
|
);
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
assets
|
|
2572
|
-
}
|
|
2573
|
-
if (opts.withPullSecret) {
|
|
2574
|
-
if (sanitizeResourceName(opts.withPullSecret) !== opts.withPullSecret) {
|
|
2575
|
-
console.error(
|
|
2576
|
-
"Invalid imagePullSecret. Please provide a valid name as defined in RFC 1123."
|
|
2577
|
-
);
|
|
2578
|
-
process.exit(1);
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
2582
|
-
const chartPath = `${uuid}-chart`;
|
|
2583
|
-
const yamlPath = (0, import_path2.resolve)(outputDir, yamlFile);
|
|
2584
|
-
const yaml = await assets.allYaml(opts.withPullSecret);
|
|
2585
|
-
try {
|
|
2586
|
-
validateCapabilityNames(assets.capabilities);
|
|
2587
|
-
} catch (e) {
|
|
2588
|
-
console.error(`Error loading capability:`, e);
|
|
2589
|
-
process.exit(1);
|
|
2590
|
-
}
|
|
2591
|
-
const zarfPath = (0, import_path2.resolve)(outputDir, "zarf.yaml");
|
|
2592
|
-
let zarf = "";
|
|
2593
|
-
if (opts.zarf === "chart") {
|
|
2594
|
-
zarf = assets.zarfYamlChart(chartPath);
|
|
2595
|
-
} else {
|
|
2596
|
-
zarf = assets.zarfYaml(yamlFile);
|
|
2597
|
-
}
|
|
2598
|
-
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2599
|
-
await import_fs8.promises.writeFile(zarfPath, zarf);
|
|
2600
|
-
await assets.generateHelmChart(outputDir);
|
|
2601
|
-
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
2439
|
+
image = checkIronBankImage(opts.registry, image, cfg.pepr.peprVersion);
|
|
2440
|
+
image !== "" ? assets.image = image : null;
|
|
2441
|
+
validImagePullSecret(opts.withPullSecret);
|
|
2442
|
+
handleValidCapabilityNames(assets.capabilities);
|
|
2443
|
+
await generateYamlAndWriteToDisk({
|
|
2444
|
+
uuid,
|
|
2445
|
+
outputDir,
|
|
2446
|
+
imagePullSecret: opts.withPullSecret,
|
|
2447
|
+
zarf: opts.zarf,
|
|
2448
|
+
assets
|
|
2449
|
+
});
|
|
2602
2450
|
}
|
|
2603
2451
|
});
|
|
2604
2452
|
}
|
|
@@ -2606,19 +2454,19 @@ var externalLibs = Object.keys(dependencies);
|
|
|
2606
2454
|
externalLibs.push("pepr");
|
|
2607
2455
|
externalLibs.push("@kubernetes/client-node");
|
|
2608
2456
|
async function loadModule(entryPoint = peprTS2) {
|
|
2609
|
-
const entryPointPath = (0,
|
|
2610
|
-
const modulePath = (0,
|
|
2611
|
-
const cfgPath = (0,
|
|
2457
|
+
const entryPointPath = (0, import_path3.resolve)(".", entryPoint);
|
|
2458
|
+
const modulePath = (0, import_path3.dirname)(entryPointPath);
|
|
2459
|
+
const cfgPath = (0, import_path3.resolve)(modulePath, "package.json");
|
|
2612
2460
|
try {
|
|
2613
|
-
await
|
|
2614
|
-
await
|
|
2461
|
+
await import_fs9.promises.access(cfgPath);
|
|
2462
|
+
await import_fs9.promises.access(entryPointPath);
|
|
2615
2463
|
} catch (e) {
|
|
2616
2464
|
console.error(
|
|
2617
2465
|
`Could not find ${cfgPath} or ${entryPointPath} in the current directory. Please run this command from the root of your module's directory.`
|
|
2618
2466
|
);
|
|
2619
2467
|
process.exit(1);
|
|
2620
2468
|
}
|
|
2621
|
-
const moduleText = await
|
|
2469
|
+
const moduleText = await import_fs9.promises.readFile(cfgPath, { encoding: "utf-8" });
|
|
2622
2470
|
const cfg = JSON.parse(moduleText);
|
|
2623
2471
|
const { uuid } = cfg.pepr;
|
|
2624
2472
|
const name2 = `pepr-${uuid}.js`;
|
|
@@ -2631,23 +2479,17 @@ async function loadModule(entryPoint = peprTS2) {
|
|
|
2631
2479
|
entryPointPath,
|
|
2632
2480
|
modulePath,
|
|
2633
2481
|
name: name2,
|
|
2634
|
-
path: (0,
|
|
2482
|
+
path: (0, import_path3.resolve)(outputDir, name2),
|
|
2635
2483
|
uuid
|
|
2636
2484
|
};
|
|
2637
2485
|
}
|
|
2638
2486
|
async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
2639
2487
|
try {
|
|
2640
2488
|
const { cfg, modulePath, path, uuid } = await loadModule(entryPoint);
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
console.log(
|
|
2644
|
-
"\x1B[33m%s\x1B[0m",
|
|
2645
|
-
"Formatting errors were found. The build will continue, but you may want to run `npx pepr format` to address any issues."
|
|
2646
|
-
);
|
|
2647
|
-
}
|
|
2648
|
-
const npmRoot = (0, import_child_process2.execFileSync)("npm", ["root"]).toString().trim();
|
|
2489
|
+
await checkFormat();
|
|
2490
|
+
const npmRoot = (0, import_child_process3.execFileSync)("npm", ["root"]).toString().trim();
|
|
2649
2491
|
const args = ["--project", `${modulePath}/tsconfig.json`, "--outdir", outputDir];
|
|
2650
|
-
(0,
|
|
2492
|
+
(0, import_child_process3.execFileSync)(`${npmRoot}/.bin/tsc`, args);
|
|
2651
2493
|
const ctxCfg = {
|
|
2652
2494
|
bundle: true,
|
|
2653
2495
|
entryPoints: [entryPoint],
|
|
@@ -2664,7 +2506,7 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
2664
2506
|
setup(build) {
|
|
2665
2507
|
build.onEnd(async (r) => {
|
|
2666
2508
|
if (r?.metafile) {
|
|
2667
|
-
console.log(await (0,
|
|
2509
|
+
console.log(await (0, import_esbuild2.analyzeMetafile)(r.metafile));
|
|
2668
2510
|
}
|
|
2669
2511
|
if (reloader) {
|
|
2670
2512
|
await reloader(r);
|
|
@@ -2682,46 +2524,52 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
2682
2524
|
}
|
|
2683
2525
|
if (!embed) {
|
|
2684
2526
|
ctxCfg.minify = false;
|
|
2685
|
-
ctxCfg.outfile = (0,
|
|
2527
|
+
ctxCfg.outfile = (0, import_path3.resolve)(outputDir, (0, import_path3.basename)(entryPoint, (0, import_path3.extname)(entryPoint))) + ".js";
|
|
2686
2528
|
ctxCfg.packages = "external";
|
|
2687
2529
|
ctxCfg.treeShaking = false;
|
|
2688
2530
|
}
|
|
2689
|
-
const ctx = await (
|
|
2690
|
-
if (reloader) {
|
|
2691
|
-
await ctx.watch();
|
|
2692
|
-
} else {
|
|
2693
|
-
await ctx.rebuild();
|
|
2694
|
-
await ctx.dispose();
|
|
2695
|
-
}
|
|
2531
|
+
const ctx = await watchForChanges(ctxCfg, reloader);
|
|
2696
2532
|
return { ctx, path, cfg, uuid };
|
|
2697
2533
|
} catch (e) {
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2534
|
+
handleModuleBuildError(e);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
function handleModuleBuildError(e) {
|
|
2538
|
+
console.error(`Error building module:`, e);
|
|
2539
|
+
if (!e.stdout) process.exit(1);
|
|
2540
|
+
const out = e.stdout.toString();
|
|
2541
|
+
const err = e.stderr.toString();
|
|
2542
|
+
console.log(out);
|
|
2543
|
+
console.error(err);
|
|
2544
|
+
if (out.includes("Types have separate declarations of a private property '_name'.")) {
|
|
2545
|
+
const pgkErrMatch = /error TS2322: .*? 'import\("\/.*?\/node_modules\/(.*?)\/node_modules/g;
|
|
2546
|
+
out.matchAll(pgkErrMatch);
|
|
2547
|
+
const conflicts = [...out.matchAll(pgkErrMatch)];
|
|
2548
|
+
if (conflicts.length < 1) {
|
|
2549
|
+
console.info(
|
|
2550
|
+
`
|
|
2711
2551
|
One or more imported Pepr Capabilities seem to be using an incompatible version of Pepr.
|
|
2712
2552
|
Try updating your Pepr Capabilities to their latest versions.`,
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2553
|
+
"Version Conflict"
|
|
2554
|
+
);
|
|
2555
|
+
}
|
|
2556
|
+
conflicts.forEach((match) => {
|
|
2557
|
+
console.info(
|
|
2558
|
+
`
|
|
2719
2559
|
Package '${match[1]}' seems to be incompatible with your current version of Pepr.
|
|
2720
2560
|
Try updating to the latest version.`,
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2561
|
+
"Version Conflict"
|
|
2562
|
+
);
|
|
2563
|
+
});
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
async function checkFormat() {
|
|
2567
|
+
const validFormat = await peprFormat(true);
|
|
2568
|
+
if (!validFormat) {
|
|
2569
|
+
console.log(
|
|
2570
|
+
"\x1B[33m%s\x1B[0m",
|
|
2571
|
+
"Formatting errors were found. The build will continue, but you may want to run `npx pepr format` to address any issues."
|
|
2572
|
+
);
|
|
2725
2573
|
}
|
|
2726
2574
|
}
|
|
2727
2575
|
|
|
@@ -2730,19 +2578,19 @@ var import_prompts = __toESM(require("prompts"));
|
|
|
2730
2578
|
|
|
2731
2579
|
// src/lib/deploymentChecks.ts
|
|
2732
2580
|
var import_kubernetes_fluent_client4 = require("kubernetes-fluent-client");
|
|
2733
|
-
async function checkDeploymentStatus(
|
|
2734
|
-
const deployments = await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.Deployment).InNamespace(
|
|
2581
|
+
async function checkDeploymentStatus(namespace) {
|
|
2582
|
+
const deployments = await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.Deployment).InNamespace(namespace).Get();
|
|
2735
2583
|
let status = false;
|
|
2736
2584
|
let readyCount = 0;
|
|
2737
|
-
for (const
|
|
2738
|
-
const readyReplicas =
|
|
2739
|
-
if (
|
|
2585
|
+
for (const deployment of deployments.items) {
|
|
2586
|
+
const readyReplicas = deployment.status?.readyReplicas ? deployment.status?.readyReplicas : 0;
|
|
2587
|
+
if (deployment.status?.readyReplicas !== deployment.spec?.replicas) {
|
|
2740
2588
|
logger_default.info(
|
|
2741
|
-
`Waiting for deployment ${
|
|
2589
|
+
`Waiting for deployment ${deployment.metadata?.name} rollout to finish: ${readyReplicas} of ${deployment.spec?.replicas} replicas are available`
|
|
2742
2590
|
);
|
|
2743
2591
|
} else {
|
|
2744
2592
|
logger_default.info(
|
|
2745
|
-
`Deployment ${
|
|
2593
|
+
`Deployment ${deployment.metadata?.name} rolled out: ${readyReplicas} of ${deployment.spec?.replicas} replicas are available`
|
|
2746
2594
|
);
|
|
2747
2595
|
readyCount++;
|
|
2748
2596
|
}
|
|
@@ -2752,87 +2600,113 @@ async function checkDeploymentStatus(namespace2) {
|
|
|
2752
2600
|
}
|
|
2753
2601
|
return status;
|
|
2754
2602
|
}
|
|
2755
|
-
async function namespaceDeploymentsReady(
|
|
2756
|
-
logger_default.info(`Checking ${
|
|
2603
|
+
async function namespaceDeploymentsReady(namespace = "pepr-system") {
|
|
2604
|
+
logger_default.info(`Checking ${namespace} deployments status...`);
|
|
2757
2605
|
let ready = false;
|
|
2758
2606
|
while (!ready) {
|
|
2759
|
-
ready = await checkDeploymentStatus(
|
|
2607
|
+
ready = await checkDeploymentStatus(namespace);
|
|
2760
2608
|
if (ready) {
|
|
2761
2609
|
return ready;
|
|
2762
2610
|
}
|
|
2763
|
-
await new Promise((
|
|
2611
|
+
await new Promise((resolve6) => setTimeout(resolve6, 1e3));
|
|
2764
2612
|
}
|
|
2765
|
-
logger_default.info(`All ${
|
|
2613
|
+
logger_default.info(`All ${namespace} deployments are ready`);
|
|
2766
2614
|
}
|
|
2767
2615
|
|
|
2768
2616
|
// src/cli/deploy.ts
|
|
2617
|
+
function validateImagePullSecretDetails(details) {
|
|
2618
|
+
if (!details.pullSecret) {
|
|
2619
|
+
return { valid: true };
|
|
2620
|
+
}
|
|
2621
|
+
if (details.pullSecret !== sanitizeName(details.pullSecret)) {
|
|
2622
|
+
return {
|
|
2623
|
+
valid: false,
|
|
2624
|
+
error: `Invalid --pullSecret. Must be valid name as defined in RFC 1123.`
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
const missing = [];
|
|
2628
|
+
if (!details.dockerEmail) {
|
|
2629
|
+
missing.push("--docker-email");
|
|
2630
|
+
}
|
|
2631
|
+
if (!details.dockerServer) {
|
|
2632
|
+
missing.push("--docker-server");
|
|
2633
|
+
}
|
|
2634
|
+
if (!details.dockerUsername) {
|
|
2635
|
+
missing.push("--docker-username");
|
|
2636
|
+
}
|
|
2637
|
+
if (!details.dockerPassword) {
|
|
2638
|
+
missing.push("--docker-password");
|
|
2639
|
+
}
|
|
2640
|
+
if (missing.length > 0) {
|
|
2641
|
+
return {
|
|
2642
|
+
valid: false,
|
|
2643
|
+
error: `Error: Must provide ${missing.join(", ")} when providing --pullSecret`
|
|
2644
|
+
};
|
|
2645
|
+
}
|
|
2646
|
+
return { valid: true };
|
|
2647
|
+
}
|
|
2648
|
+
function generateImagePullSecret(details) {
|
|
2649
|
+
const auth = Buffer.from(`${details.dockerUsername}:${details.dockerPassword}`).toString(
|
|
2650
|
+
"base64"
|
|
2651
|
+
);
|
|
2652
|
+
return {
|
|
2653
|
+
auths: {
|
|
2654
|
+
[details.dockerServer]: {
|
|
2655
|
+
username: details.dockerUsername,
|
|
2656
|
+
password: details.dockerPassword,
|
|
2657
|
+
email: details.dockerEmail,
|
|
2658
|
+
auth
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
};
|
|
2662
|
+
}
|
|
2663
|
+
async function getUserConfirmation(opts) {
|
|
2664
|
+
if (opts.confirm) {
|
|
2665
|
+
return true;
|
|
2666
|
+
}
|
|
2667
|
+
const confirm2 = await (0, import_prompts.default)({
|
|
2668
|
+
type: "confirm",
|
|
2669
|
+
name: "confirm",
|
|
2670
|
+
message: "This will remove and redeploy the module. Continue?"
|
|
2671
|
+
});
|
|
2672
|
+
return confirm2.confirm ? true : false;
|
|
2673
|
+
}
|
|
2769
2674
|
function deploy_default(program2) {
|
|
2770
2675
|
program2.command("deploy").description("Deploy a Pepr Module").option("-i, --image [image]", "Override the image tag").option("--confirm", "Skip confirmation prompt").option("--pullSecret <name>", "Deploy imagePullSecret for Controller private registry").option("--docker-server <server>", "Docker server address").option("--docker-username <username>", "Docker registry username").option("--docker-email <email>", "Email for Docker registry").option("--docker-password <password>", "Password for Docker registry").option("--force", "Force deploy the module, override manager field").action(async (opts) => {
|
|
2771
|
-
|
|
2772
|
-
if (
|
|
2773
|
-
console.error(
|
|
2774
|
-
"Error: Must provide docker server, username, email, and password when providing pull secret"
|
|
2775
|
-
);
|
|
2776
|
-
process.exit(1);
|
|
2777
|
-
} else if (opts.pullSecret && opts.pullSecret !== sanitizeName(opts.pullSecret)) {
|
|
2778
|
-
console.error(
|
|
2779
|
-
"Invalid imagePullSecret name. Please provide a valid name as defined in RFC 1123."
|
|
2780
|
-
);
|
|
2676
|
+
const valResp = validateImagePullSecretDetails(opts);
|
|
2677
|
+
if (!valResp.valid) {
|
|
2678
|
+
console.error(valResp.error);
|
|
2781
2679
|
process.exit(1);
|
|
2782
|
-
}
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
[opts.dockerServer]: {
|
|
2786
|
-
username: opts.dockerUsername,
|
|
2787
|
-
password: opts.dockerPassword,
|
|
2788
|
-
email: opts.dockerEmail,
|
|
2789
|
-
auth: Buffer.from(`${opts.dockerUsername}:${opts.dockerPassword}`).toString("base64")
|
|
2790
|
-
}
|
|
2791
|
-
}
|
|
2792
|
-
};
|
|
2793
|
-
await deployImagePullSecret(imagePullSecret, opts.pullSecret);
|
|
2680
|
+
}
|
|
2681
|
+
if (opts.pullSecret) {
|
|
2682
|
+
await deployImagePullSecret(generateImagePullSecret(opts), opts.pullSecret);
|
|
2794
2683
|
return;
|
|
2795
2684
|
}
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
message: "This will remove and redeploy the module. Continue?"
|
|
2801
|
-
});
|
|
2802
|
-
if (!confirm2.confirm) {
|
|
2803
|
-
process.exit(0);
|
|
2804
|
-
}
|
|
2685
|
+
await getUserConfirmation(opts) || process.exit(0);
|
|
2686
|
+
const builtModule = await buildModule();
|
|
2687
|
+
if (!builtModule) {
|
|
2688
|
+
return;
|
|
2805
2689
|
}
|
|
2806
|
-
const
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
);
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
const timeout = cfg.pepr.webhookTimeout ? cfg.pepr.webhookTimeout : 10;
|
|
2820
|
-
try {
|
|
2821
|
-
await webhook.deploy(opts.force, timeout);
|
|
2822
|
-
validateCapabilityNames(webhook.capabilities);
|
|
2823
|
-
await namespaceDeploymentsReady();
|
|
2824
|
-
console.info(`\u2705 Module deployed successfully`);
|
|
2825
|
-
} catch (e) {
|
|
2826
|
-
console.error(`Error deploying module:`, e);
|
|
2827
|
-
process.exit(1);
|
|
2828
|
-
}
|
|
2690
|
+
const webhook = new Assets(
|
|
2691
|
+
{ ...builtModule.cfg.pepr, description: builtModule.cfg.description },
|
|
2692
|
+
builtModule.path
|
|
2693
|
+
);
|
|
2694
|
+
webhook.image = opts.image ?? webhook.image;
|
|
2695
|
+
try {
|
|
2696
|
+
await webhook.deploy(opts.force, builtModule.cfg.pepr.webhookTimeout ?? 10);
|
|
2697
|
+
validateCapabilityNames(webhook.capabilities);
|
|
2698
|
+
await namespaceDeploymentsReady();
|
|
2699
|
+
console.info(`\u2705 Module deployed successfully`);
|
|
2700
|
+
} catch (e) {
|
|
2701
|
+
console.error(`Error deploying module:`, e);
|
|
2702
|
+
process.exit(1);
|
|
2829
2703
|
}
|
|
2830
2704
|
});
|
|
2831
2705
|
}
|
|
2832
2706
|
|
|
2833
2707
|
// src/cli/dev.ts
|
|
2834
|
-
var
|
|
2835
|
-
var
|
|
2708
|
+
var import_child_process4 = require("child_process");
|
|
2709
|
+
var import_fs10 = require("fs");
|
|
2836
2710
|
var import_prompts2 = __toESM(require("prompts"));
|
|
2837
2711
|
var import_kubernetes_fluent_client5 = require("kubernetes-fluent-client");
|
|
2838
2712
|
function dev_default(program2) {
|
|
@@ -2856,8 +2730,8 @@ function dev_default(program2) {
|
|
|
2856
2730
|
path,
|
|
2857
2731
|
opts.host
|
|
2858
2732
|
);
|
|
2859
|
-
await
|
|
2860
|
-
await
|
|
2733
|
+
await import_fs10.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
|
|
2734
|
+
await import_fs10.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
|
|
2861
2735
|
try {
|
|
2862
2736
|
let program3;
|
|
2863
2737
|
const name2 = `pepr-${cfg.pepr.uuid}`;
|
|
@@ -2872,7 +2746,7 @@ function dev_default(program2) {
|
|
|
2872
2746
|
console.error(`Error validating capability names:`, e);
|
|
2873
2747
|
process.exit(1);
|
|
2874
2748
|
}
|
|
2875
|
-
program3 = (0,
|
|
2749
|
+
program3 = (0, import_child_process4.fork)(path, {
|
|
2876
2750
|
env: {
|
|
2877
2751
|
...process.env,
|
|
2878
2752
|
LOG_LEVEL: "debug",
|
|
@@ -2921,59 +2795,15 @@ var import_kubernetes_fluent_client6 = require("kubernetes-fluent-client");
|
|
|
2921
2795
|
var import_stream = __toESM(require("stream"));
|
|
2922
2796
|
function monitor_default(program2) {
|
|
2923
2797
|
program2.command("monitor [module-uuid]").description("Monitor a Pepr Module").action(async (uuid) => {
|
|
2924
|
-
|
|
2925
|
-
let errorMessage;
|
|
2926
|
-
if (!uuid) {
|
|
2927
|
-
labels = ["pepr.dev/controller", "admission"];
|
|
2928
|
-
errorMessage = `No pods found with admission labels`;
|
|
2929
|
-
} else {
|
|
2930
|
-
labels = ["app", `pepr-${uuid}`];
|
|
2931
|
-
errorMessage = `No pods found for module ${uuid}`;
|
|
2932
|
-
}
|
|
2798
|
+
const { labels, errorMessage } = getLabelsAndErrorMessage(uuid);
|
|
2933
2799
|
const pods = await (0, import_kubernetes_fluent_client6.K8s)(import_kubernetes_fluent_client6.kind.Pod).InNamespace("pepr-system").WithLabel(labels[0], labels[1]).Get();
|
|
2934
|
-
const podNames = pods.items.flatMap((pod) => pod.metadata.name);
|
|
2800
|
+
const podNames = pods.items.flatMap((pod) => pod.metadata.name || "");
|
|
2935
2801
|
if (podNames.length < 1) {
|
|
2936
2802
|
console.error(errorMessage);
|
|
2937
2803
|
process.exit(1);
|
|
2938
2804
|
}
|
|
2939
|
-
const
|
|
2940
|
-
|
|
2941
|
-
const log = new import_client_node4.Log(kc);
|
|
2942
|
-
const logStream = new import_stream.default.PassThrough();
|
|
2943
|
-
logStream.on("data", async (chunk) => {
|
|
2944
|
-
const respMsg = `"msg":"Check response"`;
|
|
2945
|
-
const lines = await chunk.toString().split("\n");
|
|
2946
|
-
for (const line of lines) {
|
|
2947
|
-
if (!line.includes(respMsg)) continue;
|
|
2948
|
-
try {
|
|
2949
|
-
const payload = JSON.parse(line.trim());
|
|
2950
|
-
const isMutate = payload.res.patchType || payload.res.warnings;
|
|
2951
|
-
const name2 = `${payload.namespace}${payload.name}`;
|
|
2952
|
-
const uid = payload.res.uid;
|
|
2953
|
-
if (isMutate) {
|
|
2954
|
-
const plainPatch = payload.res?.patch !== void 0 && payload.res?.patch !== null ? atob(payload.res.patch) : "";
|
|
2955
|
-
const patch = plainPatch !== "" && JSON.stringify(JSON.parse(plainPatch), null, 2);
|
|
2956
|
-
const patchType = payload.res.patchType || payload.res.warnings || "";
|
|
2957
|
-
const allowOrDeny = payload.res.allowed ? "\u{1F500}" : "\u{1F6AB}";
|
|
2958
|
-
console.log(`
|
|
2959
|
-
${allowOrDeny} MUTATE ${name2} (${uid})`);
|
|
2960
|
-
patchType.length > 0 && console.log(`
|
|
2961
|
-
\x1B[1;34m${patch}\x1B[0m`);
|
|
2962
|
-
} else {
|
|
2963
|
-
const failures = Array.isArray(payload.res) ? payload.res : [payload.res];
|
|
2964
|
-
const filteredFailures = failures.filter((r) => !r.allowed).map((r) => r.status.message);
|
|
2965
|
-
console.log(
|
|
2966
|
-
`
|
|
2967
|
-
${filteredFailures.length > 0 ? "\u274C" : "\u2705"} VALIDATE ${name2} (${uid})`
|
|
2968
|
-
);
|
|
2969
|
-
console.log(
|
|
2970
|
-
filteredFailures.length > 0 ? `\x1B[1;31m${filteredFailures}\x1B[0m` : ""
|
|
2971
|
-
);
|
|
2972
|
-
}
|
|
2973
|
-
} catch {
|
|
2974
|
-
}
|
|
2975
|
-
}
|
|
2976
|
-
});
|
|
2805
|
+
const log = getK8sLogFromKubeConfig();
|
|
2806
|
+
const logStream = createLogStream();
|
|
2977
2807
|
for (const podName of podNames) {
|
|
2978
2808
|
await log.log("pepr-system", podName, "server", logStream, {
|
|
2979
2809
|
follow: true,
|
|
@@ -2983,23 +2813,90 @@ ${filteredFailures.length > 0 ? "\u274C" : "\u2705"} VALIDATE ${name2} (${uid
|
|
|
2983
2813
|
}
|
|
2984
2814
|
});
|
|
2985
2815
|
}
|
|
2816
|
+
function getLabelsAndErrorMessage(uuid) {
|
|
2817
|
+
let labels;
|
|
2818
|
+
let errorMessage;
|
|
2819
|
+
if (!uuid) {
|
|
2820
|
+
labels = ["pepr.dev/controller", "admission"];
|
|
2821
|
+
errorMessage = `No pods found with admission labels`;
|
|
2822
|
+
} else {
|
|
2823
|
+
labels = ["app", `pepr-${uuid}`];
|
|
2824
|
+
errorMessage = `No pods found for module ${uuid}`;
|
|
2825
|
+
}
|
|
2826
|
+
return { labels, errorMessage };
|
|
2827
|
+
}
|
|
2828
|
+
function getK8sLogFromKubeConfig() {
|
|
2829
|
+
const kc = new import_client_node4.KubeConfig();
|
|
2830
|
+
kc.loadFromDefault();
|
|
2831
|
+
return new import_client_node4.Log(kc);
|
|
2832
|
+
}
|
|
2833
|
+
function createLogStream() {
|
|
2834
|
+
const logStream = new import_stream.default.PassThrough();
|
|
2835
|
+
logStream.on("data", async (chunk) => {
|
|
2836
|
+
const lines = chunk.toString().split("\n");
|
|
2837
|
+
const respMsg = `"msg":"Check response"`;
|
|
2838
|
+
for (const line of lines) {
|
|
2839
|
+
if (!line.includes(respMsg)) continue;
|
|
2840
|
+
processLogLine(line);
|
|
2841
|
+
}
|
|
2842
|
+
});
|
|
2843
|
+
return logStream;
|
|
2844
|
+
}
|
|
2845
|
+
function processLogLine(line) {
|
|
2846
|
+
try {
|
|
2847
|
+
const payload = JSON.parse(line.trim());
|
|
2848
|
+
const isMutate = payload.res.patchType || payload.res.warnings;
|
|
2849
|
+
const name2 = `${payload.namespace}${payload.name}`;
|
|
2850
|
+
const uid = payload.res.uid;
|
|
2851
|
+
if (isMutate) {
|
|
2852
|
+
processMutateLog(payload, name2, uid);
|
|
2853
|
+
} else {
|
|
2854
|
+
processValidateLog(payload, name2, uid);
|
|
2855
|
+
}
|
|
2856
|
+
} catch {
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
function processMutateLog(payload, name2, uid) {
|
|
2860
|
+
const plainPatch = payload.res.patch !== void 0 && payload.res.patch !== null ? atob(payload.res.patch) : "";
|
|
2861
|
+
const patch = plainPatch !== "" && JSON.stringify(JSON.parse(plainPatch), null, 2);
|
|
2862
|
+
const patchType = payload.res.patchType || payload.res.warnings || "";
|
|
2863
|
+
const allowOrDeny = payload.res.allowed ? "\u{1F500}" : "\u{1F6AB}";
|
|
2864
|
+
console.log(`
|
|
2865
|
+
${allowOrDeny} MUTATE ${name2} (${uid})`);
|
|
2866
|
+
if (patchType.length > 0) {
|
|
2867
|
+
console.log(`
|
|
2868
|
+
\x1B[1;34m${patch}\x1B[0m`);
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
function processValidateLog(payload, name2, uid) {
|
|
2872
|
+
const failures = Array.isArray(payload.res) ? payload.res : [payload.res];
|
|
2873
|
+
const filteredFailures = failures.filter((r) => !r.allowed).map((r) => r.status?.message || "");
|
|
2874
|
+
console.log(`
|
|
2875
|
+
${filteredFailures.length > 0 ? "\u274C" : "\u2705"} VALIDATE ${name2} (${uid})`);
|
|
2876
|
+
if (filteredFailures.length > 0) {
|
|
2877
|
+
console.log(`\x1B[1;31m${filteredFailures}\x1B[0m`);
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2986
2880
|
|
|
2987
2881
|
// src/cli/init/index.ts
|
|
2988
|
-
var
|
|
2989
|
-
var
|
|
2882
|
+
var import_child_process5 = require("child_process");
|
|
2883
|
+
var import_path4 = require("path");
|
|
2990
2884
|
var import_prompts4 = __toESM(require("prompts"));
|
|
2991
2885
|
|
|
2992
2886
|
// src/cli/init/walkthrough.ts
|
|
2993
|
-
var
|
|
2887
|
+
var import_fs11 = require("fs");
|
|
2994
2888
|
var import_prompts3 = __toESM(require("prompts"));
|
|
2995
2889
|
|
|
2890
|
+
// src/cli/init/enums.ts
|
|
2891
|
+
var OnError = /* @__PURE__ */ ((OnError2) => {
|
|
2892
|
+
OnError2["AUDIT"] = "audit";
|
|
2893
|
+
OnError2["IGNORE"] = "ignore";
|
|
2894
|
+
OnError2["REJECT"] = "reject";
|
|
2895
|
+
return OnError2;
|
|
2896
|
+
})(OnError || {});
|
|
2897
|
+
|
|
2996
2898
|
// src/lib/errors.ts
|
|
2997
|
-
var
|
|
2998
|
-
audit: "audit",
|
|
2999
|
-
ignore: "ignore",
|
|
3000
|
-
reject: "reject"
|
|
3001
|
-
};
|
|
3002
|
-
var ErrorList = Object.values(Errors);
|
|
2899
|
+
var ErrorList = Object.values(OnError);
|
|
3003
2900
|
|
|
3004
2901
|
// src/cli/init/walkthrough.ts
|
|
3005
2902
|
async function walkthrough(opts) {
|
|
@@ -3018,7 +2915,7 @@ async function setName(name2) {
|
|
|
3018
2915
|
validate: async (val) => {
|
|
3019
2916
|
try {
|
|
3020
2917
|
const name3 = sanitizeName(val);
|
|
3021
|
-
await
|
|
2918
|
+
await import_fs11.promises.access(name3, import_fs11.promises.constants.F_OK);
|
|
3022
2919
|
return "A directory with this name already exists";
|
|
3023
2920
|
} catch (e) {
|
|
3024
2921
|
return val.length > 2 || "The name must be at least 3 characters long";
|
|
@@ -3055,18 +2952,18 @@ async function setErrorBehavior(errorBehavior) {
|
|
|
3055
2952
|
choices: [
|
|
3056
2953
|
{
|
|
3057
2954
|
title: "Reject the operation",
|
|
3058
|
-
value:
|
|
2955
|
+
value: "reject" /* REJECT */,
|
|
3059
2956
|
description: "In the event that Pepr is down or other module errors occur, the operation will not be allowed to continue. (Recommended for production.)"
|
|
3060
2957
|
},
|
|
3061
2958
|
{
|
|
3062
2959
|
title: "Ignore",
|
|
3063
|
-
value:
|
|
2960
|
+
value: "ignore" /* IGNORE */,
|
|
3064
2961
|
description: "In the event that Pepr is down or other module errors occur, an entry will be generated in the Pepr Controller Log and the operation will be allowed to continue. (Recommended for development, not for production.)",
|
|
3065
2962
|
selected: true
|
|
3066
2963
|
},
|
|
3067
2964
|
{
|
|
3068
2965
|
title: "Log an audit event",
|
|
3069
|
-
value:
|
|
2966
|
+
value: "audit" /* AUDIT */,
|
|
3070
2967
|
description: "Pepr will continue processing and generate an entry in the Pepr Controller log as well as an audit event in the cluster."
|
|
3071
2968
|
}
|
|
3072
2969
|
]
|
|
@@ -3114,7 +3011,7 @@ ${packageJSON2.print.replace(/^/gm, " \u2502 ")}
|
|
|
3114
3011
|
function init_default(program2) {
|
|
3115
3012
|
let response = {};
|
|
3116
3013
|
let pkgOverride = "";
|
|
3117
|
-
program2.command("init").description("Initialize a new Pepr Module").option("--confirm", "Skip verification prompt when creating a new module.").option("--description <string>", "Explain the purpose of the new module.").option("--name <string>", "Set the name of the new module.").option("--skip-post-init", "Skip npm install, git init, and VSCode launch.").option(`--errorBehavior <${ErrorList.join("|")}>`, "Set an errorBehavior.",
|
|
3014
|
+
program2.command("init").description("Initialize a new Pepr Module").option("--confirm", "Skip verification prompt when creating a new module.").option("--description <string>", "Explain the purpose of the new module.").option("--name <string>", "Set the name of the new module.").option("--skip-post-init", "Skip npm install, git init, and VSCode launch.").option(`--errorBehavior <${ErrorList.join("|")}>`, "Set an errorBehavior.", "reject" /* REJECT */).hook("preAction", async (thisCommand) => {
|
|
3118
3015
|
if (process.env.TEST_MODE === "true") {
|
|
3119
3016
|
import_prompts4.default.inject(["pepr-test-module", "A test module for Pepr", "ignore", "y"]);
|
|
3120
3017
|
pkgOverride = "file:../pepr-0.0.0-development.tgz";
|
|
@@ -3132,19 +3029,19 @@ function init_default(program2) {
|
|
|
3132
3029
|
console.log("Creating new Pepr module...");
|
|
3133
3030
|
try {
|
|
3134
3031
|
await createDir(dirName);
|
|
3135
|
-
await createDir((0,
|
|
3136
|
-
await createDir((0,
|
|
3137
|
-
await write((0,
|
|
3138
|
-
await write((0,
|
|
3139
|
-
await write((0,
|
|
3140
|
-
await write((0,
|
|
3141
|
-
await write((0,
|
|
3142
|
-
await write((0,
|
|
3143
|
-
await write((0,
|
|
3144
|
-
await write((0,
|
|
3145
|
-
await write((0,
|
|
3146
|
-
await write((0,
|
|
3147
|
-
await write((0,
|
|
3032
|
+
await createDir((0, import_path4.resolve)(dirName, ".vscode"));
|
|
3033
|
+
await createDir((0, import_path4.resolve)(dirName, "capabilities"));
|
|
3034
|
+
await write((0, import_path4.resolve)(dirName, gitignore.path), gitignore.data);
|
|
3035
|
+
await write((0, import_path4.resolve)(dirName, eslint.path), eslint.data);
|
|
3036
|
+
await write((0, import_path4.resolve)(dirName, prettier.path), prettier.data);
|
|
3037
|
+
await write((0, import_path4.resolve)(dirName, packageJSON2.path), packageJSON2.data);
|
|
3038
|
+
await write((0, import_path4.resolve)(dirName, readme.path), readme.data);
|
|
3039
|
+
await write((0, import_path4.resolve)(dirName, tsConfig.path), tsConfig.data);
|
|
3040
|
+
await write((0, import_path4.resolve)(dirName, peprTS3.path), peprTS3.data);
|
|
3041
|
+
await write((0, import_path4.resolve)(dirName, ".vscode", snippet.path), snippet.data);
|
|
3042
|
+
await write((0, import_path4.resolve)(dirName, ".vscode", codeSettings.path), codeSettings.data);
|
|
3043
|
+
await write((0, import_path4.resolve)(dirName, "capabilities", samplesYaml.path), samplesYaml.data);
|
|
3044
|
+
await write((0, import_path4.resolve)(dirName, "capabilities", helloPepr.path), helloPepr.data);
|
|
3148
3045
|
if (!opts.skipPostInit) {
|
|
3149
3046
|
doPostInitActions(dirName);
|
|
3150
3047
|
}
|
|
@@ -3161,14 +3058,14 @@ function init_default(program2) {
|
|
|
3161
3058
|
}
|
|
3162
3059
|
var doPostInitActions = (dirName) => {
|
|
3163
3060
|
process.chdir(dirName);
|
|
3164
|
-
(0,
|
|
3061
|
+
(0, import_child_process5.execSync)("npm install", {
|
|
3165
3062
|
stdio: "inherit"
|
|
3166
3063
|
});
|
|
3167
|
-
(0,
|
|
3064
|
+
(0, import_child_process5.execSync)("git init --initial-branch=main", {
|
|
3168
3065
|
stdio: "inherit"
|
|
3169
3066
|
});
|
|
3170
3067
|
try {
|
|
3171
|
-
(0,
|
|
3068
|
+
(0, import_child_process5.execSync)("code .", {
|
|
3172
3069
|
stdio: "inherit"
|
|
3173
3070
|
});
|
|
3174
3071
|
} catch (e) {
|
|
@@ -3212,9 +3109,9 @@ var RootCmd = class extends import_commander2.Command {
|
|
|
3212
3109
|
};
|
|
3213
3110
|
|
|
3214
3111
|
// src/cli/update.ts
|
|
3215
|
-
var
|
|
3216
|
-
var
|
|
3217
|
-
var
|
|
3112
|
+
var import_child_process6 = require("child_process");
|
|
3113
|
+
var import_fs12 = __toESM(require("fs"));
|
|
3114
|
+
var import_path5 = require("path");
|
|
3218
3115
|
var import_prompts5 = __toESM(require("prompts"));
|
|
3219
3116
|
function update_default(program2) {
|
|
3220
3117
|
program2.command("update").description("Update this Pepr module. Not recommended for prod as it may change files.").option("--skip-template-update", "Skip updating the template files").action(async (opts) => {
|
|
@@ -3230,11 +3127,11 @@ function update_default(program2) {
|
|
|
3230
3127
|
}
|
|
3231
3128
|
console.log("Updating the Pepr module...");
|
|
3232
3129
|
try {
|
|
3233
|
-
(0,
|
|
3130
|
+
(0, import_child_process6.execSync)("npm install pepr@latest", {
|
|
3234
3131
|
stdio: "inherit"
|
|
3235
3132
|
});
|
|
3236
3133
|
if (!opts.skipTemplateUpdate) {
|
|
3237
|
-
(0,
|
|
3134
|
+
(0, import_child_process6.execSync)("npx pepr update-templates", {
|
|
3238
3135
|
stdio: "inherit"
|
|
3239
3136
|
});
|
|
3240
3137
|
}
|
|
@@ -3248,17 +3145,17 @@ function update_default(program2) {
|
|
|
3248
3145
|
console.log("Updating Pepr config and template tiles...");
|
|
3249
3146
|
try {
|
|
3250
3147
|
if (!opts.skipTemplateUpdate) {
|
|
3251
|
-
await write((0,
|
|
3252
|
-
await write((0,
|
|
3253
|
-
await write((0,
|
|
3254
|
-
await write((0,
|
|
3255
|
-
const samplePath = (0,
|
|
3256
|
-
if (
|
|
3257
|
-
|
|
3148
|
+
await write((0, import_path5.resolve)(prettier.path), prettier.data);
|
|
3149
|
+
await write((0, import_path5.resolve)(tsConfig.path), tsConfig.data);
|
|
3150
|
+
await write((0, import_path5.resolve)(".vscode", snippet.path), snippet.data);
|
|
3151
|
+
await write((0, import_path5.resolve)(".vscode", codeSettings.path), codeSettings.data);
|
|
3152
|
+
const samplePath = (0, import_path5.resolve)("capabilities", samplesYaml.path);
|
|
3153
|
+
if (import_fs12.default.existsSync(samplePath)) {
|
|
3154
|
+
import_fs12.default.unlinkSync(samplePath);
|
|
3258
3155
|
await write(samplePath, samplesYaml.data);
|
|
3259
3156
|
}
|
|
3260
|
-
const tsPath = (0,
|
|
3261
|
-
if (
|
|
3157
|
+
const tsPath = (0, import_path5.resolve)("capabilities", helloPepr.path);
|
|
3158
|
+
if (import_fs12.default.existsSync(tsPath)) {
|
|
3262
3159
|
await write(tsPath, helloPepr.data);
|
|
3263
3160
|
}
|
|
3264
3161
|
}
|
|
@@ -3270,7 +3167,7 @@ function update_default(program2) {
|
|
|
3270
3167
|
}
|
|
3271
3168
|
|
|
3272
3169
|
// src/cli/kfc.ts
|
|
3273
|
-
var
|
|
3170
|
+
var import_child_process7 = require("child_process");
|
|
3274
3171
|
var import_prompts6 = __toESM(require("prompts"));
|
|
3275
3172
|
function kfc_default(program2) {
|
|
3276
3173
|
program2.command("kfc [args...]").description("Execute Kubernetes Fluent Client commands").action(async (args) => {
|
|
@@ -3287,7 +3184,7 @@ function kfc_default(program2) {
|
|
|
3287
3184
|
args.push("--help");
|
|
3288
3185
|
}
|
|
3289
3186
|
const argsString = args.join(" ");
|
|
3290
|
-
(0,
|
|
3187
|
+
(0, import_child_process7.execSync)(`kubernetes-fluent-client ${argsString}`, {
|
|
3291
3188
|
stdio: "inherit"
|
|
3292
3189
|
});
|
|
3293
3190
|
} catch (e) {
|