pepr 0.38.3 → 0.39.1
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 -1
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.helpers.d.ts +19 -0
- package/dist/cli/build.helpers.d.ts.map +1 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +6 -2
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/monitor.d.ts.map +1 -1
- package/dist/cli.js +294 -229
- package/dist/controller.js +53 -31
- package/dist/lib/assets/deploy.d.ts.map +1 -1
- package/dist/lib/assets/helm.d.ts +1 -0
- 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/rbac.d.ts +31 -4
- package/dist/lib/assets/rbac.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts +2 -2
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/capability.d.ts +2 -8
- package/dist/lib/capability.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts +1 -5
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/controller/storeCache.d.ts +11 -0
- package/dist/lib/controller/storeCache.d.ts.map +1 -0
- package/dist/lib/enums.d.ts +17 -0
- package/dist/lib/enums.d.ts.map +1 -0
- package/dist/lib/{adjudicators.d.ts → filter/adjudicators.d.ts} +23 -18
- package/dist/lib/filter/adjudicators.d.ts.map +1 -0
- package/dist/lib/{filter.d.ts → filter/filter.d.ts} +1 -1
- package/dist/lib/filter/filter.d.ts.map +1 -0
- package/dist/lib/helpers.d.ts +1 -2
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/k8s.d.ts +1 -1
- package/dist/lib/k8s.d.ts.map +1 -1
- package/dist/lib/logger.d.ts +4 -0
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/metrics.d.ts.map +1 -1
- package/dist/lib/module.d.ts +5 -0
- package/dist/lib/module.d.ts.map +1 -1
- package/dist/lib/mutate-processor.d.ts.map +1 -1
- package/dist/lib/mutate-request.d.ts +1 -60
- package/dist/lib/mutate-request.d.ts.map +1 -1
- package/dist/lib/types.d.ts +8 -24
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/validate-request.d.ts.map +1 -1
- package/dist/lib/watch-processor.d.ts.map +1 -1
- package/dist/lib.js +236 -299
- package/dist/lib.js.map +4 -4
- package/dist/sdk/cosign.d.ts +18 -0
- package/dist/sdk/cosign.d.ts.map +1 -0
- package/dist/sdk/heredoc.d.ts +2 -0
- package/dist/sdk/heredoc.d.ts.map +1 -0
- package/dist/sdk/sdk.d.ts +1 -2
- package/dist/sdk/sdk.d.ts.map +1 -1
- package/package.json +12 -8
- package/src/cli/build.helpers.ts +28 -0
- package/src/cli/build.ts +124 -121
- package/src/cli/deploy.ts +27 -24
- package/src/cli/dev.ts +3 -3
- package/src/cli/format.ts +3 -6
- package/src/cli/init/index.ts +23 -19
- package/src/cli/monitor.ts +34 -36
- package/src/lib/assets/deploy.ts +12 -3
- package/src/lib/assets/helm.ts +14 -0
- package/src/lib/assets/index.ts +12 -8
- package/src/lib/assets/rbac.ts +69 -17
- package/src/lib/assets/webhooks.ts +1 -1
- package/src/lib/assets/yaml.ts +8 -4
- package/src/lib/capability.ts +7 -12
- package/src/lib/controller/index.ts +3 -3
- package/src/lib/controller/store.ts +42 -202
- package/src/lib/controller/storeCache.ts +63 -0
- package/src/lib/enums.ts +21 -0
- package/src/lib/{adjudicators.ts → filter/adjudicators.ts} +56 -31
- package/src/lib/{filter.ts → filter/filter.ts} +3 -2
- package/src/lib/finalizer.ts +1 -1
- package/src/lib/helpers.ts +19 -15
- package/src/lib/k8s.ts +2 -2
- package/src/lib/logger.ts +41 -0
- package/src/lib/metrics.ts +3 -1
- package/src/lib/module.ts +5 -0
- package/src/lib/mutate-processor.ts +14 -12
- package/src/lib/mutate-request.ts +4 -69
- package/src/lib/types.ts +9 -28
- package/src/lib/validate-processor.ts +1 -1
- package/src/lib/validate-request.ts +2 -1
- package/src/lib/watch-processor.ts +34 -20
- package/src/sdk/cosign.ts +327 -0
- package/src/sdk/heredoc.ts +36 -0
- package/src/sdk/sdk.ts +1 -2
- package/dist/lib/adjudicators.d.ts.map +0 -1
- package/dist/lib/filter.d.ts.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -287,23 +287,40 @@ function sanitizeResourceName(name2) {
|
|
|
287
287
|
return name2.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 250).replace(/^[^a-z]+|[^a-z]+$/g, "");
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
// src/lib/adjudicators.ts
|
|
290
|
+
// src/lib/filter/adjudicators.ts
|
|
291
291
|
var import_ramda = require("ramda");
|
|
292
|
-
var declaredOperation = (0, import_ramda.pipe)(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
292
|
+
var declaredOperation = (0, import_ramda.pipe)(
|
|
293
|
+
(request) => request?.operation,
|
|
294
|
+
(0, import_ramda.defaultTo)("")
|
|
295
|
+
);
|
|
296
|
+
var declaredGroup = (0, import_ramda.pipe)(
|
|
297
|
+
(request) => request?.kind?.group,
|
|
298
|
+
(0, import_ramda.defaultTo)("")
|
|
299
|
+
);
|
|
300
|
+
var declaredVersion = (0, import_ramda.pipe)(
|
|
301
|
+
(request) => request?.kind?.version,
|
|
302
|
+
(0, import_ramda.defaultTo)("")
|
|
303
|
+
);
|
|
304
|
+
var declaredKind = (0, import_ramda.pipe)(
|
|
305
|
+
(request) => request?.kind?.kind,
|
|
306
|
+
(0, import_ramda.defaultTo)("")
|
|
307
|
+
);
|
|
296
308
|
var declaredUid = (0, import_ramda.pipe)((request) => request?.uid, (0, import_ramda.defaultTo)(""));
|
|
297
|
-
var carriesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
309
|
+
var carriesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
310
|
+
(kubernetesObject) => !!kubernetesObject.metadata?.deletionTimestamp,
|
|
311
|
+
(0, import_ramda.defaultTo)(false)
|
|
312
|
+
);
|
|
298
313
|
var missingDeletionTimestamp = (0, import_ramda.complement)(carriesDeletionTimestamp);
|
|
299
|
-
var
|
|
314
|
+
var carriedKind = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.kind, (0, import_ramda.defaultTo)("not set"));
|
|
315
|
+
var carriedVersion = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.version, (0, import_ramda.defaultTo)("not set"));
|
|
316
|
+
var carriedName = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.name, (0, import_ramda.defaultTo)(""));
|
|
300
317
|
var carriesName = (0, import_ramda.pipe)(carriedName, (0, import_ramda.equals)(""), import_ramda.not);
|
|
301
318
|
var missingName = (0, import_ramda.complement)(carriesName);
|
|
302
|
-
var carriedNamespace = (0, import_ramda.pipe)((
|
|
319
|
+
var carriedNamespace = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.namespace, (0, import_ramda.defaultTo)(""));
|
|
303
320
|
var carriesNamespace = (0, import_ramda.pipe)(carriedNamespace, (0, import_ramda.equals)(""), import_ramda.not);
|
|
304
|
-
var carriedAnnotations = (0, import_ramda.pipe)((
|
|
321
|
+
var carriedAnnotations = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.annotations, (0, import_ramda.defaultTo)({}));
|
|
305
322
|
var carriesAnnotations = (0, import_ramda.pipe)(carriedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
|
|
306
|
-
var carriedLabels = (0, import_ramda.pipe)((
|
|
323
|
+
var carriedLabels = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.labels, (0, import_ramda.defaultTo)({}));
|
|
307
324
|
var carriesLabels = (0, import_ramda.pipe)(carriedLabels, (0, import_ramda.equals)({}), import_ramda.not);
|
|
308
325
|
var definesDeletionTimestamp = (0, import_ramda.pipe)((binding) => binding?.filters?.deletionTimestamp, (0, import_ramda.defaultTo)(false));
|
|
309
326
|
var ignoresDeletionTimestamp = (0, import_ramda.complement)(definesDeletionTimestamp);
|
|
@@ -334,46 +351,46 @@ var definedCategory = (0, import_ramda.pipe)((binding) => {
|
|
|
334
351
|
var definedCallback = (0, import_ramda.pipe)((binding) => {
|
|
335
352
|
return binding.isFinalize ? binding.finalizeCallback : binding.isWatch ? binding.watchCallback : binding.isMutate ? binding.mutateCallback : binding.isValidate ? binding.validateCallback : null;
|
|
336
353
|
});
|
|
337
|
-
var definedCallbackName = (0, import_ramda.pipe)(definedCallback, (0, import_ramda.defaultTo)({ name: "" }), (
|
|
354
|
+
var definedCallbackName = (0, import_ramda.pipe)(definedCallback, (0, import_ramda.defaultTo)({ name: "" }), (callback) => callback.name);
|
|
338
355
|
var mismatchedDeletionTimestamp = (0, import_ramda.allPass)([
|
|
339
356
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesDeletionTimestamp),
|
|
340
357
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), missingDeletionTimestamp)
|
|
341
358
|
]);
|
|
342
359
|
var mismatchedName = (0, import_ramda.allPass)([
|
|
343
360
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesName),
|
|
344
|
-
(0, import_ramda.pipe)((
|
|
361
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => definedName(binding) !== carriedName(kubernetesObject))
|
|
345
362
|
]);
|
|
346
363
|
var mismatchedNameRegex = (0, import_ramda.allPass)([
|
|
347
364
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNameRegex),
|
|
348
|
-
(0, import_ramda.pipe)((
|
|
365
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => new RegExp(definedNameRegex(binding)).test(carriedName(kubernetesObject)), import_ramda.not)
|
|
349
366
|
]);
|
|
350
367
|
var bindsToKind = (0, import_ramda.curry)(
|
|
351
|
-
(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)((
|
|
368
|
+
(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)])
|
|
352
369
|
);
|
|
353
370
|
var bindsToNamespace = (0, import_ramda.curry)((0, import_ramda.pipe)(bindsToKind(import_ramda.__, "Namespace")));
|
|
354
371
|
var misboundNamespace = (0, import_ramda.allPass)([bindsToNamespace, definesNamespaces]);
|
|
355
372
|
var mismatchedNamespace = (0, import_ramda.allPass)([
|
|
356
373
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaces),
|
|
357
|
-
(0, import_ramda.pipe)((
|
|
374
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => definedNamespaces(binding).includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
358
375
|
]);
|
|
359
376
|
var mismatchedNamespaceRegex = (0, import_ramda.allPass)([
|
|
360
377
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaceRegexes),
|
|
361
378
|
(0, import_ramda.pipe)(
|
|
362
|
-
(
|
|
363
|
-
(0, import_ramda.any)((
|
|
379
|
+
(binding, kubernetesObject) => (0, import_ramda.pipe)(
|
|
380
|
+
(0, import_ramda.any)((regEx) => new RegExp(regEx).test(carriedNamespace(kubernetesObject))),
|
|
364
381
|
import_ramda.not
|
|
365
|
-
)(definedNamespaceRegexes(
|
|
382
|
+
)(definedNamespaceRegexes(binding))
|
|
366
383
|
)
|
|
367
384
|
]);
|
|
368
385
|
var metasMismatch = (0, import_ramda.pipe)(
|
|
369
386
|
(defined, carried) => {
|
|
370
387
|
const result = { defined, carried, unalike: {} };
|
|
371
|
-
result.unalike = Object.entries(result.defined).map(([key,
|
|
388
|
+
result.unalike = Object.entries(result.defined).map(([key, value]) => {
|
|
372
389
|
const keyMissing = !Object.hasOwn(result.carried, key);
|
|
373
|
-
const noValue = !
|
|
390
|
+
const noValue = !value;
|
|
374
391
|
const valMissing = !result.carried[key];
|
|
375
392
|
const valDiffers = result.carried[key] !== result.defined[key];
|
|
376
|
-
return keyMissing ? { [key]:
|
|
393
|
+
return keyMissing ? { [key]: value } : noValue ? {} : valMissing ? { [key]: value } : valDiffers ? { [key]: value } : {};
|
|
377
394
|
}).reduce((acc, cur) => ({ ...acc, ...cur }), {});
|
|
378
395
|
return result.unalike;
|
|
379
396
|
},
|
|
@@ -381,32 +398,37 @@ var metasMismatch = (0, import_ramda.pipe)(
|
|
|
381
398
|
);
|
|
382
399
|
var mismatchedAnnotations = (0, import_ramda.allPass)([
|
|
383
400
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesAnnotations),
|
|
384
|
-
(0, import_ramda.pipe)((
|
|
401
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedAnnotations(binding), carriedAnnotations(kubernetesObject)))
|
|
385
402
|
]);
|
|
386
403
|
var mismatchedLabels = (0, import_ramda.allPass)([
|
|
387
404
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesLabels),
|
|
388
|
-
(0, import_ramda.pipe)((
|
|
405
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedLabels(binding), carriedLabels(kubernetesObject)))
|
|
389
406
|
]);
|
|
390
407
|
var uncarryableNamespace = (0, import_ramda.allPass)([
|
|
391
408
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
392
409
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
393
|
-
(0, import_ramda.pipe)((
|
|
410
|
+
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
394
411
|
]);
|
|
395
412
|
var carriesIgnoredNamespace = (0, import_ramda.allPass)([
|
|
396
413
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
397
414
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
398
|
-
(0, import_ramda.pipe)((
|
|
415
|
+
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)))
|
|
399
416
|
]);
|
|
400
417
|
var unbindableNamespaces = (0, import_ramda.allPass)([
|
|
401
418
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
402
419
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), definesNamespaces),
|
|
403
|
-
(0, import_ramda.pipe)(
|
|
420
|
+
(0, import_ramda.pipe)(
|
|
421
|
+
(namespaceSelector, binding) => (0, import_ramda.difference)(definedNamespaces(binding), namespaceSelector),
|
|
422
|
+
import_ramda.length,
|
|
423
|
+
(0, import_ramda.equals)(0),
|
|
424
|
+
import_ramda.not
|
|
425
|
+
)
|
|
404
426
|
]);
|
|
405
427
|
var misboundDeleteWithDeletionTimestamp = (0, import_ramda.allPass)([definesDelete, definesDeletionTimestamp]);
|
|
406
428
|
var operationMatchesEvent = (0, import_ramda.anyPass)([
|
|
407
429
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), (0, import_ramda.equals)("*" /* Any */)),
|
|
408
|
-
(0, import_ramda.pipe)((
|
|
409
|
-
(0, import_ramda.pipe)((
|
|
430
|
+
(0, import_ramda.pipe)((operation, event) => operation === event),
|
|
431
|
+
(0, import_ramda.pipe)((operation, event) => operation ? event.includes(operation) : false)
|
|
410
432
|
]);
|
|
411
433
|
var mismatchedEvent = (0, import_ramda.pipe)(
|
|
412
434
|
(binding, request) => operationMatchesEvent(declaredOperation(request), definedEvent(binding)),
|
|
@@ -462,6 +484,12 @@ function createRBACMap(capabilities) {
|
|
|
462
484
|
plural: binding.kind.plural || `${binding.kind.kind.toLowerCase()}s`
|
|
463
485
|
};
|
|
464
486
|
}
|
|
487
|
+
if (binding.isFinalize) {
|
|
488
|
+
acc[key] = {
|
|
489
|
+
verbs: ["patch"],
|
|
490
|
+
plural: binding.kind.plural || `${binding.kind.kind.toLowerCase()}s`
|
|
491
|
+
};
|
|
492
|
+
}
|
|
465
493
|
});
|
|
466
494
|
return acc;
|
|
467
495
|
}, {});
|
|
@@ -529,12 +557,7 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
529
557
|
if (bindingRegexNamespaces && bindingRegexNamespaces.length > 0 && capabilityNamespaces && capabilityNamespaces.length > 0) {
|
|
530
558
|
for (const regexNamespace of bindingRegexNamespaces) {
|
|
531
559
|
let matches = false;
|
|
532
|
-
|
|
533
|
-
if (regexNamespace !== "" && matchesRegex(regexNamespace, capabilityNamespace)) {
|
|
534
|
-
matches = true;
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
560
|
+
matches = regexNamespace !== "" && capabilityNamespaces.some((capabilityNamespace) => matchesRegex(regexNamespace, capabilityNamespace));
|
|
538
561
|
if (!matches) {
|
|
539
562
|
throw new Error(
|
|
540
563
|
`Ignoring Watch Callback: Object namespace does not match any capability namespace with regex ${regexNamespace}.`
|
|
@@ -544,12 +567,11 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
544
567
|
}
|
|
545
568
|
if (bindingRegexNamespaces && bindingRegexNamespaces.length > 0 && ignoredNamespaces && ignoredNamespaces.length > 0) {
|
|
546
569
|
for (const regexNamespace of bindingRegexNamespaces) {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}
|
|
570
|
+
const matchedNS = ignoredNamespaces.find((ignoredNS) => matchesRegex(regexNamespace, ignoredNS));
|
|
571
|
+
if (matchedNS) {
|
|
572
|
+
throw new Error(
|
|
573
|
+
`Ignoring Watch Callback: Regex namespace: ${regexNamespace}, is an ignored namespace: ${matchedNS}.`
|
|
574
|
+
);
|
|
553
575
|
}
|
|
554
576
|
}
|
|
555
577
|
}
|
|
@@ -973,23 +995,33 @@ function genEnv(config, watchMode = false, ignoreWatchMode = false) {
|
|
|
973
995
|
}
|
|
974
996
|
|
|
975
997
|
// src/lib/assets/rbac.ts
|
|
976
|
-
function clusterRole(name2, capabilities, rbacMode = "") {
|
|
998
|
+
function clusterRole(name2, capabilities, rbacMode = "admin", customRbac) {
|
|
977
999
|
const rbacMap = createRBACMap(capabilities);
|
|
1000
|
+
const scopedRules = Object.keys(rbacMap).map((key) => {
|
|
1001
|
+
let group2;
|
|
1002
|
+
key.split("/").length < 3 ? group2 = "" : group2 = key.split("/")[0];
|
|
1003
|
+
return {
|
|
1004
|
+
apiGroups: [group2],
|
|
1005
|
+
resources: [rbacMap[key].plural],
|
|
1006
|
+
verbs: rbacMap[key].verbs
|
|
1007
|
+
};
|
|
1008
|
+
});
|
|
1009
|
+
const mergedRBAC = [...Array.isArray(customRbac) ? customRbac : [], ...scopedRules];
|
|
1010
|
+
const deduper = {};
|
|
1011
|
+
mergedRBAC.forEach((rule) => {
|
|
1012
|
+
const key = `${rule.apiGroups}/${rule.resources}`;
|
|
1013
|
+
if (deduper[key]) {
|
|
1014
|
+
deduper[key].verbs = Array.from(/* @__PURE__ */ new Set([...deduper[key].verbs, ...rule.verbs]));
|
|
1015
|
+
} else {
|
|
1016
|
+
deduper[key] = { ...rule, verbs: rule.verbs || [] };
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
const deduplicatedRules = Object.values(deduper);
|
|
978
1020
|
return {
|
|
979
1021
|
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
980
1022
|
kind: "ClusterRole",
|
|
981
1023
|
metadata: { name: name2 },
|
|
982
|
-
rules: rbacMode === "scoped" ? [
|
|
983
|
-
...Object.keys(rbacMap).map((key) => {
|
|
984
|
-
let group2;
|
|
985
|
-
key.split("/").length < 3 ? group2 = "" : group2 = key.split("/")[0];
|
|
986
|
-
return {
|
|
987
|
-
apiGroups: [group2],
|
|
988
|
-
resources: [rbacMap[key].plural],
|
|
989
|
-
verbs: rbacMap[key].verbs
|
|
990
|
-
};
|
|
991
|
-
})
|
|
992
|
-
] : [
|
|
1024
|
+
rules: rbacMode === "scoped" ? deduplicatedRules : [
|
|
993
1025
|
{
|
|
994
1026
|
apiGroups: ["*"],
|
|
995
1027
|
resources: ["*"],
|
|
@@ -1066,14 +1098,14 @@ function storeRoleBinding(name2) {
|
|
|
1066
1098
|
|
|
1067
1099
|
// src/lib/k8s.ts
|
|
1068
1100
|
var import_kubernetes_fluent_client3 = require("kubernetes-fluent-client");
|
|
1069
|
-
var
|
|
1101
|
+
var Store = class extends import_kubernetes_fluent_client3.GenericKind {
|
|
1070
1102
|
};
|
|
1071
1103
|
var peprStoreGVK = {
|
|
1072
1104
|
kind: "PeprStore",
|
|
1073
1105
|
version: "v1",
|
|
1074
1106
|
group: "pepr.dev"
|
|
1075
1107
|
};
|
|
1076
|
-
(0, import_kubernetes_fluent_client3.RegisterKind)(
|
|
1108
|
+
(0, import_kubernetes_fluent_client3.RegisterKind)(Store, peprStoreGVK);
|
|
1077
1109
|
|
|
1078
1110
|
// src/lib/assets/store.ts
|
|
1079
1111
|
var { group, version, kind: kind3 } = peprStoreGVK;
|
|
@@ -1273,16 +1305,17 @@ async function deploy(assets, force, webhookTimeout) {
|
|
|
1273
1305
|
if (code.length < 1) {
|
|
1274
1306
|
throw new Error("No code provided");
|
|
1275
1307
|
}
|
|
1276
|
-
await setupRBAC(name2, assets.capabilities, force);
|
|
1308
|
+
await setupRBAC(name2, assets.capabilities, force, assets.config);
|
|
1277
1309
|
await setupController(assets, code, hash, force);
|
|
1278
1310
|
await setupWatcher(assets, hash, force);
|
|
1279
1311
|
}
|
|
1280
|
-
async function setupRBAC(name2, capabilities, force) {
|
|
1312
|
+
async function setupRBAC(name2, capabilities, force, config) {
|
|
1313
|
+
const { rbacMode, rbac } = config;
|
|
1281
1314
|
logger_default.info("Applying cluster role binding");
|
|
1282
1315
|
const crb = clusterRoleBinding(name2);
|
|
1283
1316
|
await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.ClusterRoleBinding).Apply(crb, { force });
|
|
1284
1317
|
logger_default.info("Applying cluster role");
|
|
1285
|
-
const cr = clusterRole(name2, capabilities);
|
|
1318
|
+
const cr = clusterRole(name2, capabilities, rbacMode, rbac);
|
|
1286
1319
|
await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.ClusterRole).Apply(cr, { force });
|
|
1287
1320
|
logger_default.info("Applying service account");
|
|
1288
1321
|
const sa = serviceAccount(name2);
|
|
@@ -1352,8 +1385,10 @@ function loadCapabilities(path) {
|
|
|
1352
1385
|
var import_client_node = require("@kubernetes/client-node");
|
|
1353
1386
|
var import_crypto2 = __toESM(require("crypto"));
|
|
1354
1387
|
var import_fs4 = require("fs");
|
|
1355
|
-
async function overridesFile({ hash, name: name2, image, config, apiToken }, path) {
|
|
1388
|
+
async function overridesFile({ hash, name: name2, image, config, apiToken, capabilities }, path) {
|
|
1389
|
+
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
1356
1390
|
const overrides = {
|
|
1391
|
+
rbac: rbacOverrides,
|
|
1357
1392
|
secrets: {
|
|
1358
1393
|
apiToken: Buffer.from(apiToken).toString("base64")
|
|
1359
1394
|
},
|
|
@@ -1555,8 +1590,8 @@ function zarfYamlChart({ name: name2, image, config }, path) {
|
|
|
1555
1590
|
};
|
|
1556
1591
|
return (0, import_client_node.dumpYaml)(zarfCfg, { noRefs: true });
|
|
1557
1592
|
}
|
|
1558
|
-
async function allYaml(assets,
|
|
1559
|
-
const { name: name2, tls, apiToken, path } = assets;
|
|
1593
|
+
async function allYaml(assets, imagePullSecret) {
|
|
1594
|
+
const { name: name2, tls, apiToken, path, config } = assets;
|
|
1560
1595
|
const code = await import_fs4.promises.readFile(path);
|
|
1561
1596
|
assets.hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
1562
1597
|
const mutateWebhook = await webhookConfig(assets, "mutate", assets.config.webhookTimeout);
|
|
@@ -1564,7 +1599,7 @@ async function allYaml(assets, rbacMode, imagePullSecret) {
|
|
|
1564
1599
|
const watchDeployment = watcher(assets, assets.hash, assets.buildTimestamp, imagePullSecret);
|
|
1565
1600
|
const resources = [
|
|
1566
1601
|
namespace(assets.config.customLabels?.namespace),
|
|
1567
|
-
clusterRole(name2, assets.capabilities, rbacMode),
|
|
1602
|
+
clusterRole(name2, assets.capabilities, config.rbacMode, config.rbac),
|
|
1568
1603
|
clusterRoleBinding(name2),
|
|
1569
1604
|
serviceAccount(name2),
|
|
1570
1605
|
apiTokenSecret(name2, apiToken),
|
|
@@ -1592,6 +1627,19 @@ async function allYaml(assets, rbacMode, imagePullSecret) {
|
|
|
1592
1627
|
var import_path = require("path");
|
|
1593
1628
|
|
|
1594
1629
|
// src/lib/assets/helm.ts
|
|
1630
|
+
function clusterRoleTemplate() {
|
|
1631
|
+
return `
|
|
1632
|
+
apiVersion: rbac.authorization.k8s.io/v1
|
|
1633
|
+
kind: ClusterRole
|
|
1634
|
+
metadata:
|
|
1635
|
+
name: {{ .Values.uuid }}
|
|
1636
|
+
namespace: pepr-system
|
|
1637
|
+
rules:
|
|
1638
|
+
{{- if .Values.rbac }}
|
|
1639
|
+
{{- toYaml .Values.rbac | nindent 2 }}
|
|
1640
|
+
{{- end }}
|
|
1641
|
+
`;
|
|
1642
|
+
}
|
|
1595
1643
|
function nsTemplate() {
|
|
1596
1644
|
return `
|
|
1597
1645
|
apiVersion: v1
|
|
@@ -1860,12 +1908,12 @@ var Assets = class {
|
|
|
1860
1908
|
};
|
|
1861
1909
|
zarfYaml = (path) => zarfYaml(this, path);
|
|
1862
1910
|
zarfYamlChart = (path) => zarfYamlChart(this, path);
|
|
1863
|
-
allYaml = async (
|
|
1911
|
+
allYaml = async (imagePullSecret) => {
|
|
1864
1912
|
this.capabilities = await loadCapabilities(this.path);
|
|
1865
1913
|
for (const capability of this.capabilities) {
|
|
1866
1914
|
namespaceComplianceValidator(capability, this.alwaysIgnore?.namespaces);
|
|
1867
1915
|
}
|
|
1868
|
-
return allYaml(this,
|
|
1916
|
+
return allYaml(this, imagePullSecret);
|
|
1869
1917
|
};
|
|
1870
1918
|
generateHelmChart = async (basePath) => {
|
|
1871
1919
|
const CHART_DIR = `${basePath}/${this.config.uuid}-chart`;
|
|
@@ -1904,10 +1952,7 @@ var Assets = class {
|
|
|
1904
1952
|
await import_fs5.promises.writeFile(moduleSecretPath, (0, import_client_node2.dumpYaml)(moduleSecret(this.name, code, this.hash), { noRefs: true }));
|
|
1905
1953
|
await import_fs5.promises.writeFile(storeRolePath, (0, import_client_node2.dumpYaml)(storeRole(this.name), { noRefs: true }));
|
|
1906
1954
|
await import_fs5.promises.writeFile(storeRoleBindingPath, (0, import_client_node2.dumpYaml)(storeRoleBinding(this.name), { noRefs: true }));
|
|
1907
|
-
await import_fs5.promises.writeFile(
|
|
1908
|
-
clusterRolePath,
|
|
1909
|
-
(0, import_client_node2.dumpYaml)(clusterRole(this.name, this.capabilities, "rbac"), { noRefs: true })
|
|
1910
|
-
);
|
|
1955
|
+
await import_fs5.promises.writeFile(clusterRolePath, dedent(clusterRoleTemplate()));
|
|
1911
1956
|
await import_fs5.promises.writeFile(clusterRoleBindingPath, (0, import_client_node2.dumpYaml)(clusterRoleBinding(this.name), { noRefs: true }));
|
|
1912
1957
|
await import_fs5.promises.writeFile(serviceAccountPath, (0, import_client_node2.dumpYaml)(serviceAccount(this.name), { noRefs: true }));
|
|
1913
1958
|
const mutateWebhook = await webhookConfig(this, "mutate", this.config.webhookTimeout);
|
|
@@ -2161,7 +2206,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
2161
2206
|
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';
|
|
2162
2207
|
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';
|
|
2163
2208
|
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 nock from "nock";\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 // Set up Nock to mock the API calls globally with header matching\n nock(jokeURL).get("/").reply(200, {\n id: "R7UfaahVfFd",\n joke: "Funny joke goes here.",\n status: 200,\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';
|
|
2164
|
-
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.
|
|
2209
|
+
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.39.1", 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.1", "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.1", pino: "9.5.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.0.0" }, devDependencies: { "@commitlint/cli": "19.5.0", "@commitlint/config-conventional": "19.5.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", nock: "^13.5.4", "ts-jest": "29.2.5" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/parser": "7.18.0", commander: "12.1.0", esbuild: "0.23.0", eslint: "8.57.0", "node-forge": "1.3.1", prettier: "3.3.3", prompts: "2.4.2", typescript: "5.3.3", uuid: "10.0.0" } };
|
|
2165
2210
|
|
|
2166
2211
|
// src/templates/pepr.code-snippets.json
|
|
2167
2212
|
var pepr_code_snippets_default = {
|
|
@@ -2381,11 +2426,9 @@ async function peprFormat(validateOnly) {
|
|
|
2381
2426
|
const content = await import_fs7.promises.readFile(filePath, "utf8");
|
|
2382
2427
|
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
2383
2428
|
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
2384
|
-
if (validateOnly) {
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
console.error(`File ${filePath} is not formatted correctly`);
|
|
2388
|
-
}
|
|
2429
|
+
if (validateOnly && formatted !== content) {
|
|
2430
|
+
hasFailure = true;
|
|
2431
|
+
console.error(`File ${filePath} is not formatted correctly`);
|
|
2389
2432
|
} else {
|
|
2390
2433
|
await import_fs7.promises.writeFile(filePath, formatted);
|
|
2391
2434
|
}
|
|
@@ -2400,6 +2443,19 @@ async function peprFormat(validateOnly) {
|
|
|
2400
2443
|
|
|
2401
2444
|
// src/cli/build.ts
|
|
2402
2445
|
var import_commander = require("commander");
|
|
2446
|
+
|
|
2447
|
+
// src/cli/build.helpers.ts
|
|
2448
|
+
function determineRbacMode(opts, cfg) {
|
|
2449
|
+
if (opts.rbacMode) {
|
|
2450
|
+
return opts.rbacMode;
|
|
2451
|
+
}
|
|
2452
|
+
if (cfg.pepr.rbacMode && cfg.pepr.rbacMode !== "scoped") {
|
|
2453
|
+
return "admin";
|
|
2454
|
+
}
|
|
2455
|
+
return cfg.pepr.rbacMode || "admin";
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2458
|
+
// src/cli/build.ts
|
|
2403
2459
|
var peprTS2 = "pepr.ts";
|
|
2404
2460
|
var outputDir = "dist";
|
|
2405
2461
|
function build_default(program2) {
|
|
@@ -2433,7 +2489,9 @@ function build_default(program2) {
|
|
|
2433
2489
|
"Zarf package type: manifest, chart (default: manifest)"
|
|
2434
2490
|
).choices(["manifest", "chart"]).default("manifest")
|
|
2435
2491
|
).addOption(
|
|
2436
|
-
new import_commander.Option("--rbac-mode [admin|scoped]", "Rbac Mode: admin, scoped (default: admin)").choices(
|
|
2492
|
+
new import_commander.Option("--rbac-mode [admin|scoped]", "Rbac Mode: admin, scoped (default: admin)").choices(
|
|
2493
|
+
["admin", "scoped"]
|
|
2494
|
+
)
|
|
2437
2495
|
).action(async (opts) => {
|
|
2438
2496
|
if (opts.outputDir) {
|
|
2439
2497
|
outputDir = opts.outputDir;
|
|
@@ -2442,83 +2500,90 @@ function build_default(program2) {
|
|
|
2442
2500
|
process.exit(1);
|
|
2443
2501
|
});
|
|
2444
2502
|
}
|
|
2445
|
-
const
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2503
|
+
const buildModuleResult = await buildModule(void 0, opts.entryPoint, opts.embed);
|
|
2504
|
+
if (buildModuleResult?.cfg && buildModuleResult.path && buildModuleResult.uuid) {
|
|
2505
|
+
const { cfg, path, uuid } = buildModuleResult;
|
|
2506
|
+
const { includedFiles } = cfg.pepr;
|
|
2507
|
+
let image = "";
|
|
2508
|
+
if (opts.customImage) {
|
|
2509
|
+
if (opts.registry) {
|
|
2510
|
+
console.error(`Custom Image and registry cannot be used together.`);
|
|
2511
|
+
process.exit(1);
|
|
2512
|
+
}
|
|
2513
|
+
image = opts.customImage;
|
|
2452
2514
|
}
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
if (opts.timeout !== void 0) {
|
|
2456
|
-
cfg.pepr.webhookTimeout = opts.timeout;
|
|
2457
|
-
}
|
|
2458
|
-
if (opts.registryInfo !== void 0) {
|
|
2459
|
-
console.info(`Including ${includedFiles.length} files in controller image.`);
|
|
2460
|
-
image = `${opts.registryInfo}/custom-pepr-controller:${cfg.pepr.peprVersion}`;
|
|
2461
|
-
if (includedFiles.length > 0) {
|
|
2462
|
-
await createDockerfile(cfg.pepr.peprVersion, cfg.description, includedFiles);
|
|
2463
|
-
(0, import_child_process2.execSync)(`docker build --tag ${image} -f Dockerfile.controller .`, { stdio: "inherit" });
|
|
2464
|
-
(0, import_child_process2.execSync)(`docker push ${image}`, { stdio: "inherit" });
|
|
2515
|
+
if (opts.timeout !== void 0) {
|
|
2516
|
+
cfg.pepr.webhookTimeout = opts.timeout;
|
|
2465
2517
|
}
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2518
|
+
if (opts.registryInfo !== void 0) {
|
|
2519
|
+
console.info(`Including ${includedFiles.length} files in controller image.`);
|
|
2520
|
+
image = `${opts.registryInfo}/custom-pepr-controller:${cfg.pepr.peprVersion}`;
|
|
2521
|
+
if (includedFiles.length > 0) {
|
|
2522
|
+
await createDockerfile(cfg.pepr.peprVersion, cfg.description, includedFiles);
|
|
2523
|
+
(0, import_child_process2.execSync)(`docker build --tag ${image} -f Dockerfile.controller .`, {
|
|
2524
|
+
stdio: "inherit"
|
|
2525
|
+
});
|
|
2526
|
+
(0, import_child_process2.execSync)(`docker push ${image}`, { stdio: "inherit" });
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
if (!opts.embed) {
|
|
2530
|
+
console.info(`\u2705 Module built successfully at ${path}`);
|
|
2531
|
+
return;
|
|
2532
|
+
}
|
|
2533
|
+
if (opts.version) {
|
|
2534
|
+
cfg.pepr.peprVersion = opts.version;
|
|
2535
|
+
}
|
|
2536
|
+
const assets = new Assets(
|
|
2537
|
+
{
|
|
2538
|
+
...cfg.pepr,
|
|
2539
|
+
appVersion: cfg.version,
|
|
2540
|
+
description: cfg.description,
|
|
2541
|
+
// Can override the rbacMode with the CLI option
|
|
2542
|
+
rbacMode: determineRbacMode(opts, cfg)
|
|
2543
|
+
},
|
|
2544
|
+
path
|
|
2545
|
+
);
|
|
2546
|
+
if (opts?.registry === "Iron Bank") {
|
|
2547
|
+
console.info(
|
|
2548
|
+
`
|
|
2485
2549
|
This command assumes the latest release. Pepr's Iron Bank image release cycle is dictated by renovate and is typically released a few days after the GitHub release.
|
|
2486
2550
|
As an alternative you may consider custom --custom-image to target a specific image and version.`
|
|
2487
|
-
);
|
|
2488
|
-
image = `registry1.dso.mil/ironbank/opensource/defenseunicorns/pepr/controller:v${cfg.pepr.peprVersion}`;
|
|
2489
|
-
}
|
|
2490
|
-
if (image !== "") {
|
|
2491
|
-
assets.image = image;
|
|
2492
|
-
}
|
|
2493
|
-
if (opts.withPullSecret) {
|
|
2494
|
-
if (sanitizeResourceName(opts.withPullSecret) !== opts.withPullSecret) {
|
|
2495
|
-
console.error(
|
|
2496
|
-
"Invalid imagePullSecret. Please provide a valid name as defined in RFC 1123."
|
|
2497
2551
|
);
|
|
2552
|
+
image = `registry1.dso.mil/ironbank/opensource/defenseunicorns/pepr/controller:v${cfg.pepr.peprVersion}`;
|
|
2553
|
+
}
|
|
2554
|
+
if (image !== "") {
|
|
2555
|
+
assets.image = image;
|
|
2556
|
+
}
|
|
2557
|
+
if (opts.withPullSecret) {
|
|
2558
|
+
if (sanitizeResourceName(opts.withPullSecret) !== opts.withPullSecret) {
|
|
2559
|
+
console.error(
|
|
2560
|
+
"Invalid imagePullSecret. Please provide a valid name as defined in RFC 1123."
|
|
2561
|
+
);
|
|
2562
|
+
process.exit(1);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
2566
|
+
const chartPath = `${uuid}-chart`;
|
|
2567
|
+
const yamlPath = (0, import_path2.resolve)(outputDir, yamlFile);
|
|
2568
|
+
const yaml = await assets.allYaml(opts.withPullSecret);
|
|
2569
|
+
try {
|
|
2570
|
+
validateCapabilityNames(assets.capabilities);
|
|
2571
|
+
} catch (e) {
|
|
2572
|
+
console.error(`Error loading capability:`, e);
|
|
2498
2573
|
process.exit(1);
|
|
2499
2574
|
}
|
|
2575
|
+
const zarfPath = (0, import_path2.resolve)(outputDir, "zarf.yaml");
|
|
2576
|
+
let zarf = "";
|
|
2577
|
+
if (opts.zarf === "chart") {
|
|
2578
|
+
zarf = assets.zarfYamlChart(chartPath);
|
|
2579
|
+
} else {
|
|
2580
|
+
zarf = assets.zarfYaml(yamlFile);
|
|
2581
|
+
}
|
|
2582
|
+
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2583
|
+
await import_fs8.promises.writeFile(zarfPath, zarf);
|
|
2584
|
+
await assets.generateHelmChart(outputDir);
|
|
2585
|
+
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
2500
2586
|
}
|
|
2501
|
-
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
2502
|
-
const chartPath = `${uuid}-chart`;
|
|
2503
|
-
const yamlPath = (0, import_path2.resolve)(outputDir, yamlFile);
|
|
2504
|
-
const yaml = await assets.allYaml(opts.rbacMode, opts.withPullSecret);
|
|
2505
|
-
try {
|
|
2506
|
-
validateCapabilityNames(assets.capabilities);
|
|
2507
|
-
} catch (e) {
|
|
2508
|
-
console.error(`Error loading capability:`, e);
|
|
2509
|
-
process.exit(1);
|
|
2510
|
-
}
|
|
2511
|
-
const zarfPath = (0, import_path2.resolve)(outputDir, "zarf.yaml");
|
|
2512
|
-
let zarf = "";
|
|
2513
|
-
if (opts.zarf === "chart") {
|
|
2514
|
-
zarf = assets.zarfYamlChart(chartPath);
|
|
2515
|
-
} else {
|
|
2516
|
-
zarf = assets.zarfYaml(yamlFile);
|
|
2517
|
-
}
|
|
2518
|
-
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2519
|
-
await import_fs8.promises.writeFile(zarfPath, zarf);
|
|
2520
|
-
await assets.generateHelmChart(outputDir);
|
|
2521
|
-
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
2522
2587
|
});
|
|
2523
2588
|
}
|
|
2524
2589
|
var externalLibs = Object.keys(dependencies);
|
|
@@ -2615,34 +2680,32 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
2615
2680
|
return { ctx, path, cfg, uuid };
|
|
2616
2681
|
} catch (e) {
|
|
2617
2682
|
console.error(`Error building module:`, e);
|
|
2618
|
-
if (e.stdout)
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2683
|
+
if (!e.stdout) process.exit(1);
|
|
2684
|
+
const out = e.stdout.toString();
|
|
2685
|
+
const err = e.stderr.toString();
|
|
2686
|
+
console.log(out);
|
|
2687
|
+
console.error(err);
|
|
2688
|
+
if (out.includes("Types have separate declarations of a private property '_name'.")) {
|
|
2689
|
+
const pgkErrMatch = /error TS2322: .*? 'import\("\/.*?\/node_modules\/(.*?)\/node_modules/g;
|
|
2690
|
+
out.matchAll(pgkErrMatch);
|
|
2691
|
+
const conflicts = [...out.matchAll(pgkErrMatch)];
|
|
2692
|
+
if (conflicts.length < 1) {
|
|
2693
|
+
console.info(
|
|
2694
|
+
`
|
|
2630
2695
|
One or more imported Pepr Capabilities seem to be using an incompatible version of Pepr.
|
|
2631
2696
|
Try updating your Pepr Capabilities to their latest versions.`,
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2697
|
+
"Version Conflict"
|
|
2698
|
+
);
|
|
2699
|
+
}
|
|
2700
|
+
conflicts.forEach((match) => {
|
|
2701
|
+
console.info(
|
|
2702
|
+
`
|
|
2638
2703
|
Package '${match[1]}' seems to be incompatible with your current version of Pepr.
|
|
2639
2704
|
Try updating to the latest version.`,
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
}
|
|
2705
|
+
"Version Conflict"
|
|
2706
|
+
);
|
|
2707
|
+
});
|
|
2644
2708
|
}
|
|
2645
|
-
process.exit(1);
|
|
2646
2709
|
}
|
|
2647
2710
|
}
|
|
2648
2711
|
|
|
@@ -2685,26 +2748,29 @@ function deploy_default(program2) {
|
|
|
2685
2748
|
process.exit(0);
|
|
2686
2749
|
}
|
|
2687
2750
|
}
|
|
2688
|
-
const
|
|
2689
|
-
|
|
2690
|
-
{
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2751
|
+
const buildModuleResult = await buildModule();
|
|
2752
|
+
if (buildModuleResult?.cfg && buildModuleResult?.path) {
|
|
2753
|
+
const { cfg, path } = buildModuleResult;
|
|
2754
|
+
const webhook = new Assets(
|
|
2755
|
+
{
|
|
2756
|
+
...cfg.pepr,
|
|
2757
|
+
description: cfg.description
|
|
2758
|
+
},
|
|
2759
|
+
path
|
|
2760
|
+
);
|
|
2761
|
+
if (opts.image) {
|
|
2762
|
+
webhook.image = opts.image;
|
|
2763
|
+
}
|
|
2764
|
+
const timeout = cfg.pepr.webhookTimeout ? cfg.pepr.webhookTimeout : 10;
|
|
2765
|
+
try {
|
|
2766
|
+
await webhook.deploy(opts.force, timeout);
|
|
2767
|
+
validateCapabilityNames(webhook.capabilities);
|
|
2768
|
+
await namespaceDeploymentsReady();
|
|
2769
|
+
console.info(`\u2705 Module deployed successfully`);
|
|
2770
|
+
} catch (e) {
|
|
2771
|
+
console.error(`Error deploying module:`, e);
|
|
2772
|
+
process.exit(1);
|
|
2773
|
+
}
|
|
2708
2774
|
}
|
|
2709
2775
|
});
|
|
2710
2776
|
}
|
|
@@ -2767,8 +2833,8 @@ function dev_default(program2) {
|
|
|
2767
2833
|
await Promise.all([
|
|
2768
2834
|
(0, import_kubernetes_fluent_client5.K8s)(import_kubernetes_fluent_client5.kind.MutatingWebhookConfiguration).Delete(name2),
|
|
2769
2835
|
(0, import_kubernetes_fluent_client5.K8s)(import_kubernetes_fluent_client5.kind.ValidatingWebhookConfiguration).Delete(name2),
|
|
2770
|
-
(0, import_kubernetes_fluent_client5.K8s)(
|
|
2771
|
-
(0, import_kubernetes_fluent_client5.K8s)(
|
|
2836
|
+
(0, import_kubernetes_fluent_client5.K8s)(Store).InNamespace("pepr-system").Delete(scheduleStore),
|
|
2837
|
+
(0, import_kubernetes_fluent_client5.K8s)(Store).InNamespace("pepr-system").Delete(store)
|
|
2772
2838
|
]);
|
|
2773
2839
|
});
|
|
2774
2840
|
process.on("SIGINT", () => {
|
|
@@ -2823,37 +2889,33 @@ function monitor_default(program2) {
|
|
|
2823
2889
|
const respMsg = `"msg":"Check response"`;
|
|
2824
2890
|
const lines = await chunk.toString().split("\n");
|
|
2825
2891
|
for (const line of lines) {
|
|
2826
|
-
if (line.includes(respMsg))
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2892
|
+
if (!line.includes(respMsg)) continue;
|
|
2893
|
+
try {
|
|
2894
|
+
const payload = JSON.parse(line.trim());
|
|
2895
|
+
const isMutate = payload.res.patchType || payload.res.warnings;
|
|
2896
|
+
const name2 = `${payload.namespace}${payload.name}`;
|
|
2897
|
+
const uid = payload.res.uid;
|
|
2898
|
+
if (isMutate) {
|
|
2899
|
+
const plainPatch = payload.res?.patch !== void 0 && payload.res?.patch !== null ? atob(payload.res.patch) : "";
|
|
2900
|
+
const patch = plainPatch !== "" && JSON.stringify(JSON.parse(plainPatch), null, 2);
|
|
2901
|
+
const patchType = payload.res.patchType || payload.res.warnings || "";
|
|
2902
|
+
const allowOrDeny = payload.res.allowed ? "\u{1F500}" : "\u{1F6AB}";
|
|
2903
|
+
console.log(`
|
|
2838
2904
|
${allowOrDeny} MUTATE ${name2} (${uid})`);
|
|
2839
|
-
|
|
2840
|
-
console.log(`
|
|
2905
|
+
patchType.length > 0 && console.log(`
|
|
2841
2906
|
\x1B[1;34m${patch}\x1B[0m`);
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
}
|
|
2851
|
-
|
|
2852
|
-
\u2705 VALIDATE ${name2} (${uid})`);
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
|
-
} catch {
|
|
2907
|
+
} else {
|
|
2908
|
+
const failures = Array.isArray(payload.res) ? payload.res : [payload.res];
|
|
2909
|
+
const filteredFailures = failures.filter((r) => !r.allowed).map((r) => r.status.message);
|
|
2910
|
+
console.log(
|
|
2911
|
+
`
|
|
2912
|
+
${filteredFailures.length > 0 ? "\u274C" : "\u2705"} VALIDATE ${name2} (${uid})`
|
|
2913
|
+
);
|
|
2914
|
+
console.log(
|
|
2915
|
+
filteredFailures.length > 0 ? `\x1B[1;31m${filteredFailures}\x1B[0m` : ""
|
|
2916
|
+
);
|
|
2856
2917
|
}
|
|
2918
|
+
} catch {
|
|
2857
2919
|
}
|
|
2858
2920
|
}
|
|
2859
2921
|
});
|
|
@@ -3029,19 +3091,7 @@ function init_default(program2) {
|
|
|
3029
3091
|
await write((0, import_path3.resolve)(dirName, "capabilities", samplesYaml.path), samplesYaml.data);
|
|
3030
3092
|
await write((0, import_path3.resolve)(dirName, "capabilities", helloPepr.path), helloPepr.data);
|
|
3031
3093
|
if (!opts.skipPostInit) {
|
|
3032
|
-
|
|
3033
|
-
(0, import_child_process4.execSync)("npm install", {
|
|
3034
|
-
stdio: "inherit"
|
|
3035
|
-
});
|
|
3036
|
-
(0, import_child_process4.execSync)("git init --initial-branch=main", {
|
|
3037
|
-
stdio: "inherit"
|
|
3038
|
-
});
|
|
3039
|
-
try {
|
|
3040
|
-
(0, import_child_process4.execSync)("code .", {
|
|
3041
|
-
stdio: "inherit"
|
|
3042
|
-
});
|
|
3043
|
-
} catch (e) {
|
|
3044
|
-
}
|
|
3094
|
+
doPostInitActions(dirName);
|
|
3045
3095
|
}
|
|
3046
3096
|
console.log(`New Pepr module created at ${dirName}`);
|
|
3047
3097
|
console.log(`Open VSCode or your editor of choice in ${dirName} to get started!`);
|
|
@@ -3054,6 +3104,21 @@ function init_default(program2) {
|
|
|
3054
3104
|
}
|
|
3055
3105
|
});
|
|
3056
3106
|
}
|
|
3107
|
+
var doPostInitActions = (dirName) => {
|
|
3108
|
+
process.chdir(dirName);
|
|
3109
|
+
(0, import_child_process4.execSync)("npm install", {
|
|
3110
|
+
stdio: "inherit"
|
|
3111
|
+
});
|
|
3112
|
+
(0, import_child_process4.execSync)("git init --initial-branch=main", {
|
|
3113
|
+
stdio: "inherit"
|
|
3114
|
+
});
|
|
3115
|
+
try {
|
|
3116
|
+
(0, import_child_process4.execSync)("code .", {
|
|
3117
|
+
stdio: "inherit"
|
|
3118
|
+
});
|
|
3119
|
+
} catch (e) {
|
|
3120
|
+
}
|
|
3121
|
+
};
|
|
3057
3122
|
|
|
3058
3123
|
// src/cli/uuid.ts
|
|
3059
3124
|
var import_kubernetes_fluent_client7 = require("kubernetes-fluent-client");
|