pepr 0.50.0 → 0.51.0-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli/crd/create.d.ts.map +1 -1
- package/dist/cli/deploy.d.ts +3 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/docs/cli.helper.d.ts.map +1 -1
- package/dist/cli/docs/markdown.helper.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +2 -19
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/update/index.d.ts.map +1 -1
- package/dist/cli.js +232 -248
- package/dist/controller.js +1 -1
- package/dist/lib/assets/assets.d.ts.map +1 -1
- package/dist/lib/assets/defaultTestObjects.d.ts.map +1 -1
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/storeCache.d.ts.map +1 -1
- package/dist/lib/core/capability.d.ts.map +1 -1
- package/dist/lib/core/module.d.ts.map +1 -1
- package/dist/lib/core/storage.d.ts.map +1 -1
- package/dist/lib/deploymentChecks.d.ts +9 -0
- package/dist/lib/deploymentChecks.d.ts.map +1 -1
- package/dist/lib/filter/adjudicators/binding.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/mutate-request.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib/validate-request.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/cli/deploy.ts +12 -8
- package/src/cli/init/templates.ts +18 -4
- package/src/cli/update/index.ts +4 -29
- package/src/lib/deploymentChecks.ts +21 -12
- package/src/templates/capabilities/hello-pepr.ts +1 -1
- package/src/templates/eslint.config.mjs +45 -0
- package/src/templates/.eslintrc.json +0 -6
- package/src/templates/.eslintrc.template.json +0 -18
package/dist/cli.js
CHANGED
|
@@ -103,17 +103,17 @@ var require_visit = __commonJS({
|
|
|
103
103
|
visit.BREAK = BREAK;
|
|
104
104
|
visit.SKIP = SKIP;
|
|
105
105
|
visit.REMOVE = REMOVE;
|
|
106
|
-
function visit_(key, node, visitor,
|
|
107
|
-
const ctrl = callVisitor(key, node, visitor,
|
|
106
|
+
function visit_(key, node, visitor, path4) {
|
|
107
|
+
const ctrl = callVisitor(key, node, visitor, path4);
|
|
108
108
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
109
|
-
replaceNode(key,
|
|
110
|
-
return visit_(key, ctrl, visitor,
|
|
109
|
+
replaceNode(key, path4, ctrl);
|
|
110
|
+
return visit_(key, ctrl, visitor, path4);
|
|
111
111
|
}
|
|
112
112
|
if (typeof ctrl !== "symbol") {
|
|
113
113
|
if (identity.isCollection(node)) {
|
|
114
|
-
|
|
114
|
+
path4 = Object.freeze(path4.concat(node));
|
|
115
115
|
for (let i = 0; i < node.items.length; ++i) {
|
|
116
|
-
const ci = visit_(i, node.items[i], visitor,
|
|
116
|
+
const ci = visit_(i, node.items[i], visitor, path4);
|
|
117
117
|
if (typeof ci === "number")
|
|
118
118
|
i = ci - 1;
|
|
119
119
|
else if (ci === BREAK)
|
|
@@ -124,13 +124,13 @@ var require_visit = __commonJS({
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
} else if (identity.isPair(node)) {
|
|
127
|
-
|
|
128
|
-
const ck = visit_("key", node.key, visitor,
|
|
127
|
+
path4 = Object.freeze(path4.concat(node));
|
|
128
|
+
const ck = visit_("key", node.key, visitor, path4);
|
|
129
129
|
if (ck === BREAK)
|
|
130
130
|
return BREAK;
|
|
131
131
|
else if (ck === REMOVE)
|
|
132
132
|
node.key = null;
|
|
133
|
-
const cv = visit_("value", node.value, visitor,
|
|
133
|
+
const cv = visit_("value", node.value, visitor, path4);
|
|
134
134
|
if (cv === BREAK)
|
|
135
135
|
return BREAK;
|
|
136
136
|
else if (cv === REMOVE)
|
|
@@ -151,17 +151,17 @@ var require_visit = __commonJS({
|
|
|
151
151
|
visitAsync.BREAK = BREAK;
|
|
152
152
|
visitAsync.SKIP = SKIP;
|
|
153
153
|
visitAsync.REMOVE = REMOVE;
|
|
154
|
-
async function visitAsync_(key, node, visitor,
|
|
155
|
-
const ctrl = await callVisitor(key, node, visitor,
|
|
154
|
+
async function visitAsync_(key, node, visitor, path4) {
|
|
155
|
+
const ctrl = await callVisitor(key, node, visitor, path4);
|
|
156
156
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
157
|
-
replaceNode(key,
|
|
158
|
-
return visitAsync_(key, ctrl, visitor,
|
|
157
|
+
replaceNode(key, path4, ctrl);
|
|
158
|
+
return visitAsync_(key, ctrl, visitor, path4);
|
|
159
159
|
}
|
|
160
160
|
if (typeof ctrl !== "symbol") {
|
|
161
161
|
if (identity.isCollection(node)) {
|
|
162
|
-
|
|
162
|
+
path4 = Object.freeze(path4.concat(node));
|
|
163
163
|
for (let i = 0; i < node.items.length; ++i) {
|
|
164
|
-
const ci = await visitAsync_(i, node.items[i], visitor,
|
|
164
|
+
const ci = await visitAsync_(i, node.items[i], visitor, path4);
|
|
165
165
|
if (typeof ci === "number")
|
|
166
166
|
i = ci - 1;
|
|
167
167
|
else if (ci === BREAK)
|
|
@@ -172,13 +172,13 @@ var require_visit = __commonJS({
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
} else if (identity.isPair(node)) {
|
|
175
|
-
|
|
176
|
-
const ck = await visitAsync_("key", node.key, visitor,
|
|
175
|
+
path4 = Object.freeze(path4.concat(node));
|
|
176
|
+
const ck = await visitAsync_("key", node.key, visitor, path4);
|
|
177
177
|
if (ck === BREAK)
|
|
178
178
|
return BREAK;
|
|
179
179
|
else if (ck === REMOVE)
|
|
180
180
|
node.key = null;
|
|
181
|
-
const cv = await visitAsync_("value", node.value, visitor,
|
|
181
|
+
const cv = await visitAsync_("value", node.value, visitor, path4);
|
|
182
182
|
if (cv === BREAK)
|
|
183
183
|
return BREAK;
|
|
184
184
|
else if (cv === REMOVE)
|
|
@@ -205,23 +205,23 @@ var require_visit = __commonJS({
|
|
|
205
205
|
}
|
|
206
206
|
return visitor;
|
|
207
207
|
}
|
|
208
|
-
function callVisitor(key, node, visitor,
|
|
208
|
+
function callVisitor(key, node, visitor, path4) {
|
|
209
209
|
if (typeof visitor === "function")
|
|
210
|
-
return visitor(key, node,
|
|
210
|
+
return visitor(key, node, path4);
|
|
211
211
|
if (identity.isMap(node))
|
|
212
|
-
return visitor.Map?.(key, node,
|
|
212
|
+
return visitor.Map?.(key, node, path4);
|
|
213
213
|
if (identity.isSeq(node))
|
|
214
|
-
return visitor.Seq?.(key, node,
|
|
214
|
+
return visitor.Seq?.(key, node, path4);
|
|
215
215
|
if (identity.isPair(node))
|
|
216
|
-
return visitor.Pair?.(key, node,
|
|
216
|
+
return visitor.Pair?.(key, node, path4);
|
|
217
217
|
if (identity.isScalar(node))
|
|
218
|
-
return visitor.Scalar?.(key, node,
|
|
218
|
+
return visitor.Scalar?.(key, node, path4);
|
|
219
219
|
if (identity.isAlias(node))
|
|
220
|
-
return visitor.Alias?.(key, node,
|
|
220
|
+
return visitor.Alias?.(key, node, path4);
|
|
221
221
|
return void 0;
|
|
222
222
|
}
|
|
223
|
-
function replaceNode(key,
|
|
224
|
-
const parent =
|
|
223
|
+
function replaceNode(key, path4, node) {
|
|
224
|
+
const parent = path4[path4.length - 1];
|
|
225
225
|
if (identity.isCollection(parent)) {
|
|
226
226
|
parent.items[key] = node;
|
|
227
227
|
} else if (identity.isPair(parent)) {
|
|
@@ -450,8 +450,7 @@ var require_anchors = __commonJS({
|
|
|
450
450
|
return {
|
|
451
451
|
onAnchor: (source) => {
|
|
452
452
|
aliasObjects.push(source);
|
|
453
|
-
|
|
454
|
-
prevAnchors = anchorNames(doc);
|
|
453
|
+
prevAnchors ?? (prevAnchors = anchorNames(doc));
|
|
455
454
|
const anchor = findNewAnchor(prefix, prevAnchors);
|
|
456
455
|
prevAnchors.add(anchor);
|
|
457
456
|
return anchor;
|
|
@@ -627,23 +626,35 @@ var require_Alias = __commonJS({
|
|
|
627
626
|
* Resolve the value of this alias within `doc`, finding the last
|
|
628
627
|
* instance of the `source` anchor before this node.
|
|
629
628
|
*/
|
|
630
|
-
resolve(doc) {
|
|
629
|
+
resolve(doc, ctx) {
|
|
630
|
+
let nodes;
|
|
631
|
+
if (ctx?.aliasResolveCache) {
|
|
632
|
+
nodes = ctx.aliasResolveCache;
|
|
633
|
+
} else {
|
|
634
|
+
nodes = [];
|
|
635
|
+
visit.visit(doc, {
|
|
636
|
+
Node: (_key, node) => {
|
|
637
|
+
if (identity.isAlias(node) || identity.hasAnchor(node))
|
|
638
|
+
nodes.push(node);
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
if (ctx)
|
|
642
|
+
ctx.aliasResolveCache = nodes;
|
|
643
|
+
}
|
|
631
644
|
let found = void 0;
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
}
|
|
639
|
-
});
|
|
645
|
+
for (const node of nodes) {
|
|
646
|
+
if (node === this)
|
|
647
|
+
break;
|
|
648
|
+
if (node.anchor === this.source)
|
|
649
|
+
found = node;
|
|
650
|
+
}
|
|
640
651
|
return found;
|
|
641
652
|
}
|
|
642
653
|
toJSON(_arg, ctx) {
|
|
643
654
|
if (!ctx)
|
|
644
655
|
return { source: this.source };
|
|
645
656
|
const { anchors: anchors2, doc, maxAliasCount } = ctx;
|
|
646
|
-
const source = this.resolve(doc);
|
|
657
|
+
const source = this.resolve(doc, ctx);
|
|
647
658
|
if (!source) {
|
|
648
659
|
const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
|
|
649
660
|
throw new ReferenceError(msg);
|
|
@@ -772,8 +783,7 @@ var require_createNode = __commonJS({
|
|
|
772
783
|
if (aliasDuplicateObjects && value && typeof value === "object") {
|
|
773
784
|
ref = sourceObjects.get(value);
|
|
774
785
|
if (ref) {
|
|
775
|
-
|
|
776
|
-
ref.anchor = onAnchor(value);
|
|
786
|
+
ref.anchor ?? (ref.anchor = onAnchor(value));
|
|
777
787
|
return new Alias.Alias(ref.anchor);
|
|
778
788
|
} else {
|
|
779
789
|
ref = { anchor: null, node: null };
|
|
@@ -819,10 +829,10 @@ var require_Collection = __commonJS({
|
|
|
819
829
|
var createNode = require_createNode();
|
|
820
830
|
var identity = require_identity();
|
|
821
831
|
var Node2 = require_Node();
|
|
822
|
-
function collectionFromPath(schema,
|
|
832
|
+
function collectionFromPath(schema, path4, value) {
|
|
823
833
|
let v = value;
|
|
824
|
-
for (let i =
|
|
825
|
-
const k =
|
|
834
|
+
for (let i = path4.length - 1; i >= 0; --i) {
|
|
835
|
+
const k = path4[i];
|
|
826
836
|
if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
|
|
827
837
|
const a = [];
|
|
828
838
|
a[k] = v;
|
|
@@ -841,7 +851,7 @@ var require_Collection = __commonJS({
|
|
|
841
851
|
sourceObjects: /* @__PURE__ */ new Map()
|
|
842
852
|
});
|
|
843
853
|
}
|
|
844
|
-
var isEmptyPath = (
|
|
854
|
+
var isEmptyPath = (path4) => path4 == null || typeof path4 === "object" && !!path4[Symbol.iterator]().next().done;
|
|
845
855
|
var Collection = class extends Node2.NodeBase {
|
|
846
856
|
constructor(type, schema) {
|
|
847
857
|
super(type);
|
|
@@ -871,11 +881,11 @@ var require_Collection = __commonJS({
|
|
|
871
881
|
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
872
882
|
* that already exists in the map.
|
|
873
883
|
*/
|
|
874
|
-
addIn(
|
|
875
|
-
if (isEmptyPath(
|
|
884
|
+
addIn(path4, value) {
|
|
885
|
+
if (isEmptyPath(path4))
|
|
876
886
|
this.add(value);
|
|
877
887
|
else {
|
|
878
|
-
const [key, ...rest] =
|
|
888
|
+
const [key, ...rest] = path4;
|
|
879
889
|
const node = this.get(key, true);
|
|
880
890
|
if (identity.isCollection(node))
|
|
881
891
|
node.addIn(rest, value);
|
|
@@ -889,8 +899,8 @@ var require_Collection = __commonJS({
|
|
|
889
899
|
* Removes a value from the collection.
|
|
890
900
|
* @returns `true` if the item was found and removed.
|
|
891
901
|
*/
|
|
892
|
-
deleteIn(
|
|
893
|
-
const [key, ...rest] =
|
|
902
|
+
deleteIn(path4) {
|
|
903
|
+
const [key, ...rest] = path4;
|
|
894
904
|
if (rest.length === 0)
|
|
895
905
|
return this.delete(key);
|
|
896
906
|
const node = this.get(key, true);
|
|
@@ -904,8 +914,8 @@ var require_Collection = __commonJS({
|
|
|
904
914
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
905
915
|
* `true` (collections are always returned intact).
|
|
906
916
|
*/
|
|
907
|
-
getIn(
|
|
908
|
-
const [key, ...rest] =
|
|
917
|
+
getIn(path4, keepScalar) {
|
|
918
|
+
const [key, ...rest] = path4;
|
|
909
919
|
const node = this.get(key, true);
|
|
910
920
|
if (rest.length === 0)
|
|
911
921
|
return !keepScalar && identity.isScalar(node) ? node.value : node;
|
|
@@ -923,8 +933,8 @@ var require_Collection = __commonJS({
|
|
|
923
933
|
/**
|
|
924
934
|
* Checks if the collection includes a value with the key `key`.
|
|
925
935
|
*/
|
|
926
|
-
hasIn(
|
|
927
|
-
const [key, ...rest] =
|
|
936
|
+
hasIn(path4) {
|
|
937
|
+
const [key, ...rest] = path4;
|
|
928
938
|
if (rest.length === 0)
|
|
929
939
|
return this.has(key);
|
|
930
940
|
const node = this.get(key, true);
|
|
@@ -934,8 +944,8 @@ var require_Collection = __commonJS({
|
|
|
934
944
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
935
945
|
* boolean to add/remove the item from the set.
|
|
936
946
|
*/
|
|
937
|
-
setIn(
|
|
938
|
-
const [key, ...rest] =
|
|
947
|
+
setIn(path4, value) {
|
|
948
|
+
const [key, ...rest] = path4;
|
|
939
949
|
if (rest.length === 0) {
|
|
940
950
|
this.set(key, value);
|
|
941
951
|
} else {
|
|
@@ -1330,7 +1340,7 @@ ${indent}${start}${value}${end}`;
|
|
|
1330
1340
|
if (implicitKey && value.includes("\n") || inFlow && /[[\]{},]/.test(value)) {
|
|
1331
1341
|
return quotedString(value, ctx);
|
|
1332
1342
|
}
|
|
1333
|
-
if (
|
|
1343
|
+
if (/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
|
|
1334
1344
|
return implicitKey || inFlow || !value.includes("\n") ? quotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
|
|
1335
1345
|
}
|
|
1336
1346
|
if (!implicitKey && !inFlow && type !== Scalar.Scalar.PLAIN && value.includes("\n")) {
|
|
@@ -1462,7 +1472,7 @@ var require_stringify = __commonJS({
|
|
|
1462
1472
|
tagObj = tags.find((t) => t.nodeClass && obj instanceof t.nodeClass);
|
|
1463
1473
|
}
|
|
1464
1474
|
if (!tagObj) {
|
|
1465
|
-
const name2 = obj?.constructor?.name ?? typeof obj;
|
|
1475
|
+
const name2 = obj?.constructor?.name ?? (obj === null ? "null" : typeof obj);
|
|
1466
1476
|
throw new Error(`Tag not resolved for ${name2} value`);
|
|
1467
1477
|
}
|
|
1468
1478
|
return tagObj;
|
|
@@ -1476,7 +1486,7 @@ var require_stringify = __commonJS({
|
|
|
1476
1486
|
anchors$1.add(anchor);
|
|
1477
1487
|
props.push(`&${anchor}`);
|
|
1478
1488
|
}
|
|
1479
|
-
const tag = node.tag
|
|
1489
|
+
const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);
|
|
1480
1490
|
if (tag)
|
|
1481
1491
|
props.push(doc.directives.tagString(tag));
|
|
1482
1492
|
return props.join(" ");
|
|
@@ -1499,8 +1509,7 @@ var require_stringify = __commonJS({
|
|
|
1499
1509
|
}
|
|
1500
1510
|
let tagObj = void 0;
|
|
1501
1511
|
const node = identity.isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: (o) => tagObj = o });
|
|
1502
|
-
|
|
1503
|
-
tagObj = getTagObject(ctx.doc.schema.tags, node);
|
|
1512
|
+
tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));
|
|
1504
1513
|
const props = stringifyProps(node, tagObj, ctx);
|
|
1505
1514
|
if (props.length > 0)
|
|
1506
1515
|
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
|
|
@@ -1652,7 +1661,7 @@ ${ctx.indent}`;
|
|
|
1652
1661
|
var require_log = __commonJS({
|
|
1653
1662
|
"node_modules/yaml/dist/log.js"(exports2) {
|
|
1654
1663
|
"use strict";
|
|
1655
|
-
var node_process = require("
|
|
1664
|
+
var node_process = require("process");
|
|
1656
1665
|
function debug(logLevel, ...messages) {
|
|
1657
1666
|
if (logLevel === "debug")
|
|
1658
1667
|
console.log(...messages);
|
|
@@ -2557,7 +2566,7 @@ var require_schema2 = __commonJS({
|
|
|
2557
2566
|
var require_binary = __commonJS({
|
|
2558
2567
|
"node_modules/yaml/dist/schema/yaml-1.1/binary.js"(exports2) {
|
|
2559
2568
|
"use strict";
|
|
2560
|
-
var node_buffer = require("
|
|
2569
|
+
var node_buffer = require("buffer");
|
|
2561
2570
|
var Scalar = require_Scalar();
|
|
2562
2571
|
var stringifyString = require_stringifyString();
|
|
2563
2572
|
var binary = {
|
|
@@ -2602,8 +2611,7 @@ var require_binary = __commonJS({
|
|
|
2602
2611
|
} else {
|
|
2603
2612
|
throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");
|
|
2604
2613
|
}
|
|
2605
|
-
|
|
2606
|
-
type = Scalar.Scalar.BLOCK_LITERAL;
|
|
2614
|
+
type ?? (type = Scalar.Scalar.BLOCK_LITERAL);
|
|
2607
2615
|
if (type !== Scalar.Scalar.QUOTE_DOUBLE) {
|
|
2608
2616
|
const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);
|
|
2609
2617
|
const n = Math.ceil(str.length / lineWidth);
|
|
@@ -3441,9 +3449,9 @@ var require_Document = __commonJS({
|
|
|
3441
3449
|
this.contents.add(value);
|
|
3442
3450
|
}
|
|
3443
3451
|
/** Adds a value to the document. */
|
|
3444
|
-
addIn(
|
|
3452
|
+
addIn(path4, value) {
|
|
3445
3453
|
if (assertCollection(this.contents))
|
|
3446
|
-
this.contents.addIn(
|
|
3454
|
+
this.contents.addIn(path4, value);
|
|
3447
3455
|
}
|
|
3448
3456
|
/**
|
|
3449
3457
|
* Create a new `Alias` node, ensuring that the target `node` has the required anchor.
|
|
@@ -3518,14 +3526,14 @@ var require_Document = __commonJS({
|
|
|
3518
3526
|
* Removes a value from the document.
|
|
3519
3527
|
* @returns `true` if the item was found and removed.
|
|
3520
3528
|
*/
|
|
3521
|
-
deleteIn(
|
|
3522
|
-
if (Collection.isEmptyPath(
|
|
3529
|
+
deleteIn(path4) {
|
|
3530
|
+
if (Collection.isEmptyPath(path4)) {
|
|
3523
3531
|
if (this.contents == null)
|
|
3524
3532
|
return false;
|
|
3525
3533
|
this.contents = null;
|
|
3526
3534
|
return true;
|
|
3527
3535
|
}
|
|
3528
|
-
return assertCollection(this.contents) ? this.contents.deleteIn(
|
|
3536
|
+
return assertCollection(this.contents) ? this.contents.deleteIn(path4) : false;
|
|
3529
3537
|
}
|
|
3530
3538
|
/**
|
|
3531
3539
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
@@ -3540,10 +3548,10 @@ var require_Document = __commonJS({
|
|
|
3540
3548
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
3541
3549
|
* `true` (collections are always returned intact).
|
|
3542
3550
|
*/
|
|
3543
|
-
getIn(
|
|
3544
|
-
if (Collection.isEmptyPath(
|
|
3551
|
+
getIn(path4, keepScalar) {
|
|
3552
|
+
if (Collection.isEmptyPath(path4))
|
|
3545
3553
|
return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
|
|
3546
|
-
return identity.isCollection(this.contents) ? this.contents.getIn(
|
|
3554
|
+
return identity.isCollection(this.contents) ? this.contents.getIn(path4, keepScalar) : void 0;
|
|
3547
3555
|
}
|
|
3548
3556
|
/**
|
|
3549
3557
|
* Checks if the document includes a value with the key `key`.
|
|
@@ -3554,10 +3562,10 @@ var require_Document = __commonJS({
|
|
|
3554
3562
|
/**
|
|
3555
3563
|
* Checks if the document includes a value at `path`.
|
|
3556
3564
|
*/
|
|
3557
|
-
hasIn(
|
|
3558
|
-
if (Collection.isEmptyPath(
|
|
3565
|
+
hasIn(path4) {
|
|
3566
|
+
if (Collection.isEmptyPath(path4))
|
|
3559
3567
|
return this.contents !== void 0;
|
|
3560
|
-
return identity.isCollection(this.contents) ? this.contents.hasIn(
|
|
3568
|
+
return identity.isCollection(this.contents) ? this.contents.hasIn(path4) : false;
|
|
3561
3569
|
}
|
|
3562
3570
|
/**
|
|
3563
3571
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
@@ -3574,13 +3582,13 @@ var require_Document = __commonJS({
|
|
|
3574
3582
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
3575
3583
|
* boolean to add/remove the item from the set.
|
|
3576
3584
|
*/
|
|
3577
|
-
setIn(
|
|
3578
|
-
if (Collection.isEmptyPath(
|
|
3585
|
+
setIn(path4, value) {
|
|
3586
|
+
if (Collection.isEmptyPath(path4)) {
|
|
3579
3587
|
this.contents = value;
|
|
3580
3588
|
} else if (this.contents == null) {
|
|
3581
|
-
this.contents = Collection.collectionFromPath(this.schema, Array.from(
|
|
3589
|
+
this.contents = Collection.collectionFromPath(this.schema, Array.from(path4), value);
|
|
3582
3590
|
} else if (assertCollection(this.contents)) {
|
|
3583
|
-
this.contents.setIn(
|
|
3591
|
+
this.contents.setIn(path4, value);
|
|
3584
3592
|
}
|
|
3585
3593
|
}
|
|
3586
3594
|
/**
|
|
@@ -3807,8 +3815,7 @@ var require_resolve_props = __commonJS({
|
|
|
3807
3815
|
if (token.source.endsWith(":"))
|
|
3808
3816
|
onError(token.offset + token.source.length - 1, "BAD_ALIAS", "Anchor ending in : is ambiguous", true);
|
|
3809
3817
|
anchor = token;
|
|
3810
|
-
|
|
3811
|
-
start = token.offset;
|
|
3818
|
+
start ?? (start = token.offset);
|
|
3812
3819
|
atNewline = false;
|
|
3813
3820
|
hasSpace = false;
|
|
3814
3821
|
reqSpace = true;
|
|
@@ -3817,8 +3824,7 @@ var require_resolve_props = __commonJS({
|
|
|
3817
3824
|
if (tag)
|
|
3818
3825
|
onError(token, "MULTIPLE_TAGS", "A node can have at most one tag");
|
|
3819
3826
|
tag = token;
|
|
3820
|
-
|
|
3821
|
-
start = token.offset;
|
|
3827
|
+
start ?? (start = token.offset);
|
|
3822
3828
|
atNewline = false;
|
|
3823
3829
|
hasSpace = false;
|
|
3824
3830
|
reqSpace = true;
|
|
@@ -4899,8 +4905,7 @@ var require_util_empty_scalar_position = __commonJS({
|
|
|
4899
4905
|
"use strict";
|
|
4900
4906
|
function emptyScalarPosition(offset, before, pos) {
|
|
4901
4907
|
if (before) {
|
|
4902
|
-
|
|
4903
|
-
pos = before.length;
|
|
4908
|
+
pos ?? (pos = before.length);
|
|
4904
4909
|
for (let i = pos - 1; i >= 0; --i) {
|
|
4905
4910
|
let st = before[i];
|
|
4906
4911
|
switch (st.type) {
|
|
@@ -5072,7 +5077,7 @@ var require_compose_doc = __commonJS({
|
|
|
5072
5077
|
var require_composer = __commonJS({
|
|
5073
5078
|
"node_modules/yaml/dist/compose/composer.js"(exports2) {
|
|
5074
5079
|
"use strict";
|
|
5075
|
-
var node_process = require("
|
|
5080
|
+
var node_process = require("process");
|
|
5076
5081
|
var directives = require_directives();
|
|
5077
5082
|
var Document = require_Document();
|
|
5078
5083
|
var errors = require_errors();
|
|
@@ -5535,9 +5540,9 @@ var require_cst_visit = __commonJS({
|
|
|
5535
5540
|
visit.BREAK = BREAK;
|
|
5536
5541
|
visit.SKIP = SKIP;
|
|
5537
5542
|
visit.REMOVE = REMOVE;
|
|
5538
|
-
visit.itemAtPath = (cst,
|
|
5543
|
+
visit.itemAtPath = (cst, path4) => {
|
|
5539
5544
|
let item = cst;
|
|
5540
|
-
for (const [field, index] of
|
|
5545
|
+
for (const [field, index] of path4) {
|
|
5541
5546
|
const tok = item?.[field];
|
|
5542
5547
|
if (tok && "items" in tok) {
|
|
5543
5548
|
item = tok.items[index];
|
|
@@ -5546,23 +5551,23 @@ var require_cst_visit = __commonJS({
|
|
|
5546
5551
|
}
|
|
5547
5552
|
return item;
|
|
5548
5553
|
};
|
|
5549
|
-
visit.parentCollection = (cst,
|
|
5550
|
-
const parent = visit.itemAtPath(cst,
|
|
5551
|
-
const field =
|
|
5554
|
+
visit.parentCollection = (cst, path4) => {
|
|
5555
|
+
const parent = visit.itemAtPath(cst, path4.slice(0, -1));
|
|
5556
|
+
const field = path4[path4.length - 1][0];
|
|
5552
5557
|
const coll = parent?.[field];
|
|
5553
5558
|
if (coll && "items" in coll)
|
|
5554
5559
|
return coll;
|
|
5555
5560
|
throw new Error("Parent collection not found");
|
|
5556
5561
|
};
|
|
5557
|
-
function _visit(
|
|
5558
|
-
let ctrl = visitor(item,
|
|
5562
|
+
function _visit(path4, item, visitor) {
|
|
5563
|
+
let ctrl = visitor(item, path4);
|
|
5559
5564
|
if (typeof ctrl === "symbol")
|
|
5560
5565
|
return ctrl;
|
|
5561
5566
|
for (const field of ["key", "value"]) {
|
|
5562
5567
|
const token = item[field];
|
|
5563
5568
|
if (token && "items" in token) {
|
|
5564
5569
|
for (let i = 0; i < token.items.length; ++i) {
|
|
5565
|
-
const ci = _visit(Object.freeze(
|
|
5570
|
+
const ci = _visit(Object.freeze(path4.concat([[field, i]])), token.items[i], visitor);
|
|
5566
5571
|
if (typeof ci === "number")
|
|
5567
5572
|
i = ci - 1;
|
|
5568
5573
|
else if (ci === BREAK)
|
|
@@ -5573,10 +5578,10 @@ var require_cst_visit = __commonJS({
|
|
|
5573
5578
|
}
|
|
5574
5579
|
}
|
|
5575
5580
|
if (typeof ctrl === "function" && field === "key")
|
|
5576
|
-
ctrl = ctrl(item,
|
|
5581
|
+
ctrl = ctrl(item, path4);
|
|
5577
5582
|
}
|
|
5578
5583
|
}
|
|
5579
|
-
return typeof ctrl === "function" ? ctrl(item,
|
|
5584
|
+
return typeof ctrl === "function" ? ctrl(item, path4) : ctrl;
|
|
5580
5585
|
}
|
|
5581
5586
|
exports2.visit = visit;
|
|
5582
5587
|
}
|
|
@@ -6298,7 +6303,7 @@ var require_line_counter = __commonJS({
|
|
|
6298
6303
|
var require_parser = __commonJS({
|
|
6299
6304
|
"node_modules/yaml/dist/parse/parser.js"(exports2) {
|
|
6300
6305
|
"use strict";
|
|
6301
|
-
var node_process = require("
|
|
6306
|
+
var node_process = require("process");
|
|
6302
6307
|
var cst = require_cst();
|
|
6303
6308
|
var lexer = require_lexer();
|
|
6304
6309
|
function includesToken(list, type) {
|
|
@@ -7375,8 +7380,8 @@ var banner = `\x1B[107;40m\x1B[38;5;m \x1B[38;5;m \x1B[38;5;m \x1B[38;5;m \x1B[3
|
|
|
7375
7380
|
// src/cli/build.ts
|
|
7376
7381
|
var import_child_process3 = require("child_process");
|
|
7377
7382
|
var import_esbuild2 = require("esbuild");
|
|
7378
|
-
var
|
|
7379
|
-
var
|
|
7383
|
+
var import_fs10 = require("fs");
|
|
7384
|
+
var import_path4 = require("path");
|
|
7380
7385
|
|
|
7381
7386
|
// src/lib/assets/assets.ts
|
|
7382
7387
|
var import_crypto = __toESM(require("crypto"));
|
|
@@ -7736,12 +7741,12 @@ function serviceMonitorTemplate(name2, type) {
|
|
|
7736
7741
|
|
|
7737
7742
|
// src/lib/filesystemService.ts
|
|
7738
7743
|
var import_fs = require("fs");
|
|
7739
|
-
async function createDirectoryIfNotExists(
|
|
7744
|
+
async function createDirectoryIfNotExists(path4) {
|
|
7740
7745
|
try {
|
|
7741
|
-
await import_fs.promises.access(
|
|
7746
|
+
await import_fs.promises.access(path4);
|
|
7742
7747
|
} catch (error) {
|
|
7743
7748
|
if (error.code === "ENOENT") {
|
|
7744
|
-
await import_fs.promises.mkdir(
|
|
7749
|
+
await import_fs.promises.mkdir(path4, { recursive: true });
|
|
7745
7750
|
} else {
|
|
7746
7751
|
throw error;
|
|
7747
7752
|
}
|
|
@@ -8086,7 +8091,7 @@ function resolveIgnoreNamespaces(ignoredNSConfig = []) {
|
|
|
8086
8091
|
}
|
|
8087
8092
|
|
|
8088
8093
|
// src/lib/assets/yaml/overridesFile.ts
|
|
8089
|
-
async function overridesFile({ hash, name: name2, image, config, apiPath, capabilities },
|
|
8094
|
+
async function overridesFile({ hash, name: name2, image, config, apiPath, capabilities }, path4, imagePullSecrets) {
|
|
8090
8095
|
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
8091
8096
|
const overrides = {
|
|
8092
8097
|
imagePullSecrets,
|
|
@@ -8241,7 +8246,7 @@ async function overridesFile({ hash, name: name2, image, config, apiPath, capabi
|
|
|
8241
8246
|
}
|
|
8242
8247
|
}
|
|
8243
8248
|
};
|
|
8244
|
-
await import_fs2.promises.writeFile(
|
|
8249
|
+
await import_fs2.promises.writeFile(path4, (0, import_client_node.dumpYaml)(overrides, { noRefs: true, forceQuotes: true }));
|
|
8245
8250
|
}
|
|
8246
8251
|
|
|
8247
8252
|
// src/lib/assets/index.ts
|
|
@@ -8326,9 +8331,9 @@ function helmLayout(basePath, unique) {
|
|
|
8326
8331
|
|
|
8327
8332
|
// src/lib/assets/loader.ts
|
|
8328
8333
|
var import_child_process = require("child_process");
|
|
8329
|
-
function loadCapabilities(
|
|
8334
|
+
function loadCapabilities(path4) {
|
|
8330
8335
|
return new Promise((resolve6, reject) => {
|
|
8331
|
-
const program2 = (0, import_child_process.fork)(
|
|
8336
|
+
const program2 = (0, import_child_process.fork)(path4, {
|
|
8332
8337
|
env: {
|
|
8333
8338
|
...process.env,
|
|
8334
8339
|
LOG_LEVEL: "warn",
|
|
@@ -8446,12 +8451,12 @@ var Assets = class {
|
|
|
8446
8451
|
image;
|
|
8447
8452
|
buildTimestamp;
|
|
8448
8453
|
host;
|
|
8449
|
-
constructor(config,
|
|
8454
|
+
constructor(config, path4, imagePullSecrets, host) {
|
|
8450
8455
|
this.name = `pepr-${config.uuid}`;
|
|
8451
8456
|
this.imagePullSecrets = imagePullSecrets;
|
|
8452
8457
|
this.buildTimestamp = `${Date.now()}`;
|
|
8453
8458
|
this.config = config;
|
|
8454
|
-
this.path =
|
|
8459
|
+
this.path = path4;
|
|
8455
8460
|
this.host = host;
|
|
8456
8461
|
this.alwaysIgnore = config.alwaysIgnore;
|
|
8457
8462
|
this.image = `ghcr.io/defenseunicorns/pepr/controller:v${config.peprVersion}`;
|
|
@@ -8463,8 +8468,8 @@ var Assets = class {
|
|
|
8463
8468
|
const timeout = typeof webhookTimeout === "number" ? webhookTimeout : 10;
|
|
8464
8469
|
await deployFunction(this, force, timeout);
|
|
8465
8470
|
}
|
|
8466
|
-
zarfYaml = (zarfYamlGenerator,
|
|
8467
|
-
zarfYamlChart = (zarfYamlGenerator,
|
|
8471
|
+
zarfYaml = (zarfYamlGenerator, path4) => zarfYamlGenerator(this, path4, "manifests");
|
|
8472
|
+
zarfYamlChart = (zarfYamlGenerator, path4) => zarfYamlGenerator(this, path4, "charts");
|
|
8468
8473
|
allYaml = async (yamlGenerationFunction, getDeploymentFunction, getWatcherFunction, imagePullSecret) => {
|
|
8469
8474
|
this.capabilities = await loadCapabilities(this.path);
|
|
8470
8475
|
for (const capability of this.capabilities) {
|
|
@@ -8594,26 +8599,8 @@ var Assets = class {
|
|
|
8594
8599
|
var import_client_node3 = require("@kubernetes/client-node");
|
|
8595
8600
|
var import_util = require("util");
|
|
8596
8601
|
var import_uuid = require("uuid");
|
|
8597
|
-
|
|
8598
|
-
|
|
8599
|
-
var eslintrc_template_default = {
|
|
8600
|
-
env: {
|
|
8601
|
-
browser: false,
|
|
8602
|
-
es2021: true
|
|
8603
|
-
},
|
|
8604
|
-
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
8605
|
-
parser: "@typescript-eslint/parser",
|
|
8606
|
-
parserOptions: {
|
|
8607
|
-
project: ["./tsconfig.json"],
|
|
8608
|
-
ecmaVersion: 2022
|
|
8609
|
-
},
|
|
8610
|
-
plugins: ["@typescript-eslint"],
|
|
8611
|
-
ignorePatterns: ["node_modules", "dist"],
|
|
8612
|
-
root: true,
|
|
8613
|
-
rules: {
|
|
8614
|
-
"@typescript-eslint/no-floating-promises": ["error"]
|
|
8615
|
-
}
|
|
8616
|
-
};
|
|
8602
|
+
var import_fs5 = require("fs");
|
|
8603
|
+
var import_path2 = __toESM(require("path"));
|
|
8617
8604
|
|
|
8618
8605
|
// src/templates/pepr.code-snippets.json
|
|
8619
8606
|
var pepr_code_snippets_default = {
|
|
@@ -8853,8 +8840,8 @@ var tsconfig_module_default = {
|
|
|
8853
8840
|
var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\ndist\ninsecure*\n";
|
|
8854
8841
|
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';
|
|
8855
8842
|
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';
|
|
8856
|
-
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.SetLabel("pepr", "was-here").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).IsCreated().InNamespace("pepr-demo-2").WithName("example-4a").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';
|
|
8857
|
-
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", "!src/fixtures/**", "!dist/**/*.test.d.ts*", "!src/cli/docs/**"], version: "0.
|
|
8843
|
+
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.SetLabel("pepr", "was-here").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>): void {\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).IsCreated().InNamespace("pepr-demo-2").WithName("example-4a").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';
|
|
8844
|
+
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", "!src/fixtures/**", "!dist/**/*.test.d.ts*", "!src/cli/docs/**"], version: "0.51.0-nightly.0", 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", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", "build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) .", "set:version": "node scripts/set-version.js", test: "npm run test:unit && npm run test:journey && npm run test:journey-wasm", "test:artifacts": "npm run build && jest src/build-artifact.test.ts", "test:docs": "jest --verbose src/cli/docs/*.test.ts", "test:integration": "npm run test:integration:prep && npm run test:integration:run", "test:integration:prep": "./integration/prep.sh", "test:integration:run": "jest --maxWorkers=4 integration", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey-wasm:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run-wasm", "test:journey:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr:dev -c pepr-dev", "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:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && npm run test:journey:run", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "test:unit": 'npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns="build-artifact.test.ts|src/cli/docs/.*\\.test\\.ts"', "format:check": "eslint --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --check", "format:fix": "eslint --fix --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", commander: "14.0.0", express: "5.1.0", "fast-json-patch": "3.1.1", heredoc: "^1.3.1", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.5.5", pino: "9.7.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.1.0", "ts-morph": "^26.0.0" }, devDependencies: { "@commitlint/cli": "19.8.1", "@commitlint/config-conventional": "19.8.1", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.2", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^4.0.0", globals: "^16.0.0", husky: "^9.1.6", jest: "29.7.0", "js-yaml": "^4.1.0", shellcheck: "^3.0.0", "ts-jest": "29.3.4", undici: "^7.0.1" }, overrides: { glob: "^9.0.0" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "8.32.1", "@typescript-eslint/parser": "8.32.1", esbuild: "0.25.0", eslint: "^9.26.0", "node-forge": "1.3.1", prettier: "3.5.3", prompts: "2.4.2", typescript: "5.8.3", uuid: "11.1.0" } };
|
|
8858
8845
|
|
|
8859
8846
|
// src/cli/init/utils.ts
|
|
8860
8847
|
var import_fs4 = require("fs");
|
|
@@ -8880,11 +8867,11 @@ async function createDir(dir) {
|
|
|
8880
8867
|
}
|
|
8881
8868
|
}
|
|
8882
8869
|
}
|
|
8883
|
-
function write(
|
|
8870
|
+
function write(path4, data) {
|
|
8884
8871
|
if (typeof data !== "string") {
|
|
8885
8872
|
data = JSON.stringify(data, null, 2);
|
|
8886
8873
|
}
|
|
8887
|
-
return import_fs4.promises.writeFile(
|
|
8874
|
+
return import_fs4.promises.writeFile(path4, data);
|
|
8888
8875
|
}
|
|
8889
8876
|
|
|
8890
8877
|
// src/cli/init/templates.ts
|
|
@@ -8903,7 +8890,7 @@ function genPkgJSON(opts, pgkVerOverride) {
|
|
|
8903
8890
|
description: opts.description,
|
|
8904
8891
|
keywords: ["pepr", "k8s", "policy-engine", "pepr-module", "security"],
|
|
8905
8892
|
engines: {
|
|
8906
|
-
node: ">=
|
|
8893
|
+
node: ">=20.0.0"
|
|
8907
8894
|
},
|
|
8908
8895
|
pepr: {
|
|
8909
8896
|
uuid: pgkVerOverride ? "static-test" : uuid,
|
|
@@ -8984,8 +8971,19 @@ var prettier = {
|
|
|
8984
8971
|
data: prettierrc_default
|
|
8985
8972
|
};
|
|
8986
8973
|
var eslint = {
|
|
8987
|
-
path: ".
|
|
8988
|
-
data:
|
|
8974
|
+
path: "eslint.config.mjs",
|
|
8975
|
+
data: (0, import_fs5.readFileSync)(
|
|
8976
|
+
import_path2.default.resolve(
|
|
8977
|
+
(() => {
|
|
8978
|
+
const fullPath = __dirname;
|
|
8979
|
+
const lengthOfSuffix = "pepr/".length;
|
|
8980
|
+
const lastPeprIndex = fullPath.lastIndexOf("pepr/");
|
|
8981
|
+
return fullPath.substring(0, lastPeprIndex + lengthOfSuffix);
|
|
8982
|
+
})(),
|
|
8983
|
+
"src/templates/eslint.config.mjs"
|
|
8984
|
+
),
|
|
8985
|
+
"utf-8"
|
|
8986
|
+
)
|
|
8989
8987
|
};
|
|
8990
8988
|
|
|
8991
8989
|
// src/cli/build.ts
|
|
@@ -8995,19 +8993,19 @@ var import_commander = require("commander");
|
|
|
8995
8993
|
var import_eslint = require("eslint");
|
|
8996
8994
|
|
|
8997
8995
|
// src/cli/format/format.helpers.ts
|
|
8998
|
-
var
|
|
8996
|
+
var import_fs6 = require("fs");
|
|
8999
8997
|
var import_prettier = require("prettier");
|
|
9000
8998
|
async function formatWithPrettier(results, validateOnly) {
|
|
9001
8999
|
let hasFailure = false;
|
|
9002
9000
|
for (const { filePath } of results) {
|
|
9003
|
-
const content = await
|
|
9001
|
+
const content = await import_fs6.promises.readFile(filePath, "utf8");
|
|
9004
9002
|
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
9005
9003
|
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
9006
9004
|
if (validateOnly && formatted !== content) {
|
|
9007
9005
|
hasFailure = true;
|
|
9008
9006
|
console.error(`File ${filePath} is not formatted correctly`);
|
|
9009
9007
|
} else {
|
|
9010
|
-
await
|
|
9008
|
+
await import_fs6.promises.writeFile(filePath, formatted);
|
|
9011
9009
|
}
|
|
9012
9010
|
}
|
|
9013
9011
|
return hasFailure;
|
|
@@ -9054,7 +9052,7 @@ async function peprFormat(validateOnly) {
|
|
|
9054
9052
|
}
|
|
9055
9053
|
|
|
9056
9054
|
// src/lib/included-files.ts
|
|
9057
|
-
var
|
|
9055
|
+
var import_fs7 = require("fs");
|
|
9058
9056
|
async function createDockerfile(version3, description, includedFiles) {
|
|
9059
9057
|
const file = `
|
|
9060
9058
|
# Use an official Node.js runtime as the base image
|
|
@@ -9066,14 +9064,14 @@ async function createDockerfile(version3, description, includedFiles) {
|
|
|
9066
9064
|
${includedFiles.map((f) => `ADD ${f} ${f}`).join("\n")}
|
|
9067
9065
|
|
|
9068
9066
|
`;
|
|
9069
|
-
await
|
|
9067
|
+
await import_fs7.promises.writeFile("Dockerfile.controller", file, { encoding: "utf-8" });
|
|
9070
9068
|
}
|
|
9071
9069
|
|
|
9072
9070
|
// src/cli/build.helpers.ts
|
|
9073
9071
|
var import_child_process2 = require("child_process");
|
|
9074
9072
|
var import_esbuild = require("esbuild");
|
|
9075
|
-
var
|
|
9076
|
-
var
|
|
9073
|
+
var import_path3 = require("path");
|
|
9074
|
+
var import_fs9 = require("fs");
|
|
9077
9075
|
|
|
9078
9076
|
// src/lib/assets/yaml/generateAllYaml.ts
|
|
9079
9077
|
var import_crypto2 = __toESM(require("crypto"));
|
|
@@ -9388,7 +9386,7 @@ function getDeployment(assets, hash, buildTimestamp, imagePullSecret) {
|
|
|
9388
9386
|
}
|
|
9389
9387
|
function getModuleSecret(name2, data, hash) {
|
|
9390
9388
|
const compressed = (0, import_zlib.gzipSync)(data);
|
|
9391
|
-
const
|
|
9389
|
+
const path4 = `module-${hash}.js.gz`;
|
|
9392
9390
|
const compressedData = compressed.toString("base64");
|
|
9393
9391
|
if (secretOverLimit(compressedData)) {
|
|
9394
9392
|
const error = new Error(`Module secret for ${name2} is over the 1MB limit`);
|
|
@@ -9403,14 +9401,14 @@ function getModuleSecret(name2, data, hash) {
|
|
|
9403
9401
|
},
|
|
9404
9402
|
type: "Opaque",
|
|
9405
9403
|
data: {
|
|
9406
|
-
[
|
|
9404
|
+
[path4]: compressed.toString("base64")
|
|
9407
9405
|
}
|
|
9408
9406
|
};
|
|
9409
9407
|
}
|
|
9410
9408
|
}
|
|
9411
9409
|
|
|
9412
9410
|
// src/lib/assets/yaml/generateAllYaml.ts
|
|
9413
|
-
var
|
|
9411
|
+
var import_fs8 = require("fs");
|
|
9414
9412
|
|
|
9415
9413
|
// src/lib/assets/webhooks.ts
|
|
9416
9414
|
var import_ramda = require("ramda");
|
|
@@ -9497,8 +9495,8 @@ async function webhookConfigGenerator(assets, mutateOrValidate, timeoutSeconds =
|
|
|
9497
9495
|
|
|
9498
9496
|
// src/lib/assets/yaml/generateAllYaml.ts
|
|
9499
9497
|
async function generateAllYaml(assets, deployments) {
|
|
9500
|
-
const { name: name2, tls, apiPath, path:
|
|
9501
|
-
const code = await
|
|
9498
|
+
const { name: name2, tls, apiPath, path: path4, config } = assets;
|
|
9499
|
+
const code = await import_fs8.promises.readFile(path4);
|
|
9502
9500
|
const hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
9503
9501
|
const resources = [
|
|
9504
9502
|
getNamespace(assets.config.customLabels?.namespace),
|
|
@@ -9531,18 +9529,18 @@ async function generateAllYaml(assets, deployments) {
|
|
|
9531
9529
|
|
|
9532
9530
|
// src/lib/assets/yaml/generateZarfYaml.ts
|
|
9533
9531
|
var import_client_node5 = require("@kubernetes/client-node");
|
|
9534
|
-
function generateZarfYamlGeneric(assets,
|
|
9532
|
+
function generateZarfYamlGeneric(assets, path4, type) {
|
|
9535
9533
|
const zarfComponentName = process.env.PEPR_CUSTOM_BUILD_NAME ?? "module";
|
|
9536
9534
|
const manifestSettings = {
|
|
9537
9535
|
name: zarfComponentName,
|
|
9538
9536
|
namespace: "pepr-system",
|
|
9539
|
-
files: [
|
|
9537
|
+
files: [path4]
|
|
9540
9538
|
};
|
|
9541
9539
|
const chartSettings = {
|
|
9542
9540
|
name: zarfComponentName,
|
|
9543
9541
|
namespace: "pepr-system",
|
|
9544
9542
|
version: `${assets.config.appVersion || "0.0.1"}`,
|
|
9545
|
-
localPath:
|
|
9543
|
+
localPath: path4
|
|
9546
9544
|
};
|
|
9547
9545
|
const component = {
|
|
9548
9546
|
name: zarfComponentName,
|
|
@@ -9642,18 +9640,18 @@ async function generateYamlAndWriteToDisk(obj) {
|
|
|
9642
9640
|
const { uuid, imagePullSecret, outputDir: outputDir2, assets, zarf } = obj;
|
|
9643
9641
|
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
9644
9642
|
const chartPath = `${uuid}-chart`;
|
|
9645
|
-
const yamlPath = (0,
|
|
9643
|
+
const yamlPath = (0, import_path3.resolve)(outputDir2, yamlFile);
|
|
9646
9644
|
try {
|
|
9647
9645
|
const yaml = await assets.allYaml(generateAllYaml, getDeployment, getWatcher, imagePullSecret);
|
|
9648
|
-
const zarfPath = (0,
|
|
9646
|
+
const zarfPath = (0, import_path3.resolve)(outputDir2, "zarf.yaml");
|
|
9649
9647
|
let localZarf = "";
|
|
9650
9648
|
if (zarf === "chart") {
|
|
9651
9649
|
localZarf = assets.zarfYamlChart(generateZarfYamlGeneric, chartPath);
|
|
9652
9650
|
} else {
|
|
9653
9651
|
localZarf = assets.zarfYaml(generateZarfYamlGeneric, yamlFile);
|
|
9654
9652
|
}
|
|
9655
|
-
await
|
|
9656
|
-
await
|
|
9653
|
+
await import_fs9.promises.writeFile(yamlPath, yaml);
|
|
9654
|
+
await import_fs9.promises.writeFile(zarfPath, localZarf);
|
|
9657
9655
|
await assets.generateHelmChart(webhookConfigGenerator, getWatcher, getModuleSecret, outputDir2);
|
|
9658
9656
|
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
9659
9657
|
} catch (error) {
|
|
@@ -9709,7 +9707,7 @@ function build_default(program2) {
|
|
|
9709
9707
|
).action(async (opts) => {
|
|
9710
9708
|
outputDir = await handleCustomOutputDir(opts.outputDir);
|
|
9711
9709
|
const buildModuleResult = await buildModule(void 0, opts.entryPoint, opts.embed);
|
|
9712
|
-
const { cfg, path:
|
|
9710
|
+
const { cfg, path: path4 } = buildModuleResult;
|
|
9713
9711
|
if (opts.customName) {
|
|
9714
9712
|
process.env.PEPR_CUSTOM_BUILD_NAME = opts.customName;
|
|
9715
9713
|
}
|
|
@@ -9732,7 +9730,7 @@ function build_default(program2) {
|
|
|
9732
9730
|
);
|
|
9733
9731
|
}
|
|
9734
9732
|
if (!opts.embed) {
|
|
9735
|
-
console.info(`\u2705 Module built successfully at ${
|
|
9733
|
+
console.info(`\u2705 Module built successfully at ${path4}`);
|
|
9736
9734
|
return;
|
|
9737
9735
|
}
|
|
9738
9736
|
const assets = new Assets(
|
|
@@ -9746,7 +9744,7 @@ function build_default(program2) {
|
|
|
9746
9744
|
// Can override the rbacMode with the CLI option
|
|
9747
9745
|
rbacMode: determineRbacMode(opts, cfg)
|
|
9748
9746
|
},
|
|
9749
|
-
|
|
9747
|
+
path4,
|
|
9750
9748
|
opts.withPullSecret === "" ? [] : [opts.withPullSecret]
|
|
9751
9749
|
);
|
|
9752
9750
|
if (image !== "") assets.image = image;
|
|
@@ -9765,19 +9763,19 @@ var externalLibs = Object.keys(dependencies);
|
|
|
9765
9763
|
externalLibs.push("pepr");
|
|
9766
9764
|
externalLibs.push("@kubernetes/client-node");
|
|
9767
9765
|
async function loadModule(entryPoint = peprTS2) {
|
|
9768
|
-
const entryPointPath = (0,
|
|
9769
|
-
const modulePath = (0,
|
|
9770
|
-
const cfgPath = (0,
|
|
9766
|
+
const entryPointPath = (0, import_path4.resolve)(".", entryPoint);
|
|
9767
|
+
const modulePath = (0, import_path4.dirname)(entryPointPath);
|
|
9768
|
+
const cfgPath = (0, import_path4.resolve)(modulePath, "package.json");
|
|
9771
9769
|
try {
|
|
9772
|
-
await
|
|
9773
|
-
await
|
|
9770
|
+
await import_fs10.promises.access(cfgPath);
|
|
9771
|
+
await import_fs10.promises.access(entryPointPath);
|
|
9774
9772
|
} catch {
|
|
9775
9773
|
console.error(
|
|
9776
9774
|
`Could not find ${cfgPath} or ${entryPointPath} in the current directory. Please run this command from the root of your module's directory.`
|
|
9777
9775
|
);
|
|
9778
9776
|
process.exit(1);
|
|
9779
9777
|
}
|
|
9780
|
-
const moduleText = await
|
|
9778
|
+
const moduleText = await import_fs10.promises.readFile(cfgPath, { encoding: "utf-8" });
|
|
9781
9779
|
const cfg = JSON.parse(moduleText);
|
|
9782
9780
|
const { uuid } = cfg.pepr;
|
|
9783
9781
|
const name2 = `pepr-${uuid}.js`;
|
|
@@ -9790,13 +9788,13 @@ async function loadModule(entryPoint = peprTS2) {
|
|
|
9790
9788
|
entryPointPath,
|
|
9791
9789
|
modulePath,
|
|
9792
9790
|
name: name2,
|
|
9793
|
-
path: (0,
|
|
9791
|
+
path: (0, import_path4.resolve)(outputDir, name2),
|
|
9794
9792
|
uuid
|
|
9795
9793
|
};
|
|
9796
9794
|
}
|
|
9797
9795
|
async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
9798
9796
|
try {
|
|
9799
|
-
const { cfg, modulePath, path:
|
|
9797
|
+
const { cfg, modulePath, path: path4, uuid } = await loadModule(entryPoint);
|
|
9800
9798
|
await checkFormat();
|
|
9801
9799
|
const npmRoot = (0, import_child_process3.execFileSync)("npm", ["root"]).toString().trim();
|
|
9802
9800
|
const args = ["--project", `${modulePath}/tsconfig.json`, "--outdir", outputDir];
|
|
@@ -9810,7 +9808,7 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
9810
9808
|
legalComments: "external",
|
|
9811
9809
|
metafile: true,
|
|
9812
9810
|
minify: true,
|
|
9813
|
-
outfile:
|
|
9811
|
+
outfile: path4,
|
|
9814
9812
|
plugins: [
|
|
9815
9813
|
{
|
|
9816
9814
|
name: "reload-server",
|
|
@@ -9835,12 +9833,12 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
9835
9833
|
}
|
|
9836
9834
|
if (!embed) {
|
|
9837
9835
|
ctxCfg.minify = false;
|
|
9838
|
-
ctxCfg.outfile = (0,
|
|
9836
|
+
ctxCfg.outfile = (0, import_path4.resolve)(outputDir, (0, import_path4.basename)(entryPoint, (0, import_path4.extname)(entryPoint))) + ".js";
|
|
9839
9837
|
ctxCfg.packages = "external";
|
|
9840
9838
|
ctxCfg.treeShaking = false;
|
|
9841
9839
|
}
|
|
9842
9840
|
const ctx = await watchForChanges(ctxCfg, reloader);
|
|
9843
|
-
return { ctx, path:
|
|
9841
|
+
return { ctx, path: path4, cfg, uuid };
|
|
9844
9842
|
} catch (e) {
|
|
9845
9843
|
handleModuleBuildError(e);
|
|
9846
9844
|
}
|
|
@@ -9889,7 +9887,7 @@ var import_prompts = __toESM(require("prompts"));
|
|
|
9889
9887
|
|
|
9890
9888
|
// src/lib/assets/deploy.ts
|
|
9891
9889
|
var import_crypto3 = __toESM(require("crypto"));
|
|
9892
|
-
var
|
|
9890
|
+
var import_fs11 = require("fs");
|
|
9893
9891
|
var import_kubernetes_fluent_client3 = require("kubernetes-fluent-client");
|
|
9894
9892
|
|
|
9895
9893
|
// src/lib/k8s.ts
|
|
@@ -9998,7 +9996,7 @@ async function deployWebhook(assets, force, webhookTimeout) {
|
|
|
9998
9996
|
logger_default.info("Applying the Pepr Store CRD if it doesn't exist");
|
|
9999
9997
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.CustomResourceDefinition).Apply(peprStoreCRD, { force });
|
|
10000
9998
|
if (assets.host) return;
|
|
10001
|
-
const code = await
|
|
9999
|
+
const code = await import_fs11.promises.readFile(assets.path);
|
|
10002
10000
|
if (!code.length) throw new Error("No code provided");
|
|
10003
10001
|
const hash = import_crypto3.default.createHash("sha256").update(code).digest("hex");
|
|
10004
10002
|
await setupRBAC(assets.name, assets.capabilities, force, assets.config);
|
|
@@ -10056,25 +10054,23 @@ async function setupWatcher(assets, hash, force) {
|
|
|
10056
10054
|
var import_kubernetes_fluent_client4 = require("kubernetes-fluent-client");
|
|
10057
10055
|
async function checkDeploymentStatus(namespace) {
|
|
10058
10056
|
const deployments = await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.Deployment).InNamespace(namespace).Get();
|
|
10059
|
-
let
|
|
10060
|
-
let readyCount = 0;
|
|
10057
|
+
let allReady = true;
|
|
10061
10058
|
for (const deployment of deployments.items) {
|
|
10062
|
-
const
|
|
10063
|
-
|
|
10059
|
+
const name2 = deployment.metadata?.name ?? "unknown";
|
|
10060
|
+
const specReplicas = deployment.spec?.replicas ?? 0;
|
|
10061
|
+
const readyReplicas = deployment.status?.readyReplicas ?? 0;
|
|
10062
|
+
if (readyReplicas !== specReplicas) {
|
|
10064
10063
|
logger_default.info(
|
|
10065
|
-
`Waiting for deployment ${
|
|
10064
|
+
`Waiting for deployment ${name2} rollout to finish: ${readyReplicas} of ${specReplicas} replicas are available`
|
|
10066
10065
|
);
|
|
10066
|
+
allReady = false;
|
|
10067
10067
|
} else {
|
|
10068
10068
|
logger_default.info(
|
|
10069
|
-
`Deployment ${
|
|
10069
|
+
`Deployment ${name2} rolled out: ${readyReplicas} of ${specReplicas} replicas are available`
|
|
10070
10070
|
);
|
|
10071
|
-
readyCount++;
|
|
10072
10071
|
}
|
|
10073
10072
|
}
|
|
10074
|
-
|
|
10075
|
-
status = true;
|
|
10076
|
-
}
|
|
10077
|
-
return status;
|
|
10073
|
+
return allReady;
|
|
10078
10074
|
}
|
|
10079
10075
|
async function namespaceDeploymentsReady(namespace = "pepr-system") {
|
|
10080
10076
|
logger_default.info(`Checking ${namespace} deployments status...`);
|
|
@@ -10160,13 +10156,7 @@ async function buildAndDeployModule(image, force) {
|
|
|
10160
10156
|
webhook.image = image ?? webhook.image;
|
|
10161
10157
|
const capabilities = await loadCapabilities(webhook.path);
|
|
10162
10158
|
for (const capability of capabilities) {
|
|
10163
|
-
|
|
10164
|
-
namespaceComplianceValidator(
|
|
10165
|
-
capability,
|
|
10166
|
-
webhook.config.admission?.alwaysIgnore?.namespaces,
|
|
10167
|
-
false
|
|
10168
|
-
);
|
|
10169
|
-
namespaceComplianceValidator(capability, webhook.config.watch?.alwaysIgnore?.namespaces, true);
|
|
10159
|
+
validateNamespaces(capability, webhook);
|
|
10170
10160
|
}
|
|
10171
10161
|
try {
|
|
10172
10162
|
await webhook.deploy(deployWebhook, force, builtModule.cfg.pepr.webhookTimeout ?? 10);
|
|
@@ -10195,12 +10185,21 @@ function deploy_default(program2) {
|
|
|
10195
10185
|
await buildAndDeployModule(opts.image, opts.force);
|
|
10196
10186
|
});
|
|
10197
10187
|
}
|
|
10188
|
+
function validateNamespaces(capability, webhook) {
|
|
10189
|
+
namespaceComplianceValidator(capability, webhook.alwaysIgnore?.namespaces);
|
|
10190
|
+
namespaceComplianceValidator(
|
|
10191
|
+
capability,
|
|
10192
|
+
webhook.config.admission?.alwaysIgnore?.namespaces,
|
|
10193
|
+
false
|
|
10194
|
+
);
|
|
10195
|
+
namespaceComplianceValidator(capability, webhook.config.watch?.alwaysIgnore?.namespaces, true);
|
|
10196
|
+
}
|
|
10198
10197
|
|
|
10199
10198
|
// src/cli/dev.ts
|
|
10200
10199
|
var import_prompts2 = __toESM(require("prompts"));
|
|
10201
10200
|
var import_child_process4 = require("child_process");
|
|
10202
10201
|
var import_kubernetes_fluent_client5 = require("kubernetes-fluent-client");
|
|
10203
|
-
var
|
|
10202
|
+
var import_fs12 = require("fs");
|
|
10204
10203
|
function dev_default(program2) {
|
|
10205
10204
|
program2.command("dev").description("Setup a local webhook development environment").option("-h, --host [host]", "Host to listen on", "host.k3d.internal").option("--confirm", "Skip confirmation prompt").action(async (opts) => {
|
|
10206
10205
|
if (!opts.confirm) {
|
|
@@ -10213,25 +10212,25 @@ function dev_default(program2) {
|
|
|
10213
10212
|
process.exit(0);
|
|
10214
10213
|
}
|
|
10215
10214
|
}
|
|
10216
|
-
const { cfg, path:
|
|
10215
|
+
const { cfg, path: path4 } = await loadModule();
|
|
10217
10216
|
const webhook = new Assets(
|
|
10218
10217
|
{
|
|
10219
10218
|
...cfg.pepr,
|
|
10220
10219
|
description: cfg.description
|
|
10221
10220
|
},
|
|
10222
|
-
|
|
10221
|
+
path4,
|
|
10223
10222
|
[],
|
|
10224
10223
|
opts.host
|
|
10225
10224
|
);
|
|
10226
|
-
await
|
|
10227
|
-
await
|
|
10225
|
+
await import_fs12.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
|
|
10226
|
+
await import_fs12.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
|
|
10228
10227
|
try {
|
|
10229
10228
|
let program3;
|
|
10230
10229
|
const name2 = `pepr-${cfg.pepr.uuid}`;
|
|
10231
10230
|
const scheduleStore = `pepr-${cfg.pepr.uuid}-schedule`;
|
|
10232
10231
|
const store = `pepr-${cfg.pepr.uuid}-store`;
|
|
10233
10232
|
const runFork = async () => {
|
|
10234
|
-
console.info(`Running module ${
|
|
10233
|
+
console.info(`Running module ${path4}`);
|
|
10235
10234
|
await webhook.deploy(deployWebhook, false, 30);
|
|
10236
10235
|
try {
|
|
10237
10236
|
validateCapabilityNames(webhook.capabilities);
|
|
@@ -10239,7 +10238,7 @@ function dev_default(program2) {
|
|
|
10239
10238
|
console.error(`Error validating capability names:`, e);
|
|
10240
10239
|
process.exit(1);
|
|
10241
10240
|
}
|
|
10242
|
-
program3 = (0, import_child_process4.fork)(
|
|
10241
|
+
program3 = (0, import_child_process4.fork)(path4, {
|
|
10243
10242
|
env: {
|
|
10244
10243
|
...process.env,
|
|
10245
10244
|
LOG_LEVEL: process.env.LOG_LEVEL ?? "debug",
|
|
@@ -10373,11 +10372,11 @@ ${filteredFailures.length > 0 ? "\u274C" : "\u2705"} VALIDATE ${name2} (${uid
|
|
|
10373
10372
|
|
|
10374
10373
|
// src/cli/init/index.ts
|
|
10375
10374
|
var import_child_process5 = require("child_process");
|
|
10376
|
-
var
|
|
10375
|
+
var import_path5 = require("path");
|
|
10377
10376
|
var import_prompts4 = __toESM(require("prompts"));
|
|
10378
10377
|
|
|
10379
10378
|
// src/cli/init/walkthrough.ts
|
|
10380
|
-
var
|
|
10379
|
+
var import_fs13 = require("fs");
|
|
10381
10380
|
var import_prompts3 = __toESM(require("prompts"));
|
|
10382
10381
|
|
|
10383
10382
|
// src/cli/init/enums.ts
|
|
@@ -10424,7 +10423,7 @@ async function setName(name2) {
|
|
|
10424
10423
|
validate: async (val) => {
|
|
10425
10424
|
try {
|
|
10426
10425
|
const name3 = sanitizeName(val);
|
|
10427
|
-
await
|
|
10426
|
+
await import_fs13.promises.access(name3, import_fs13.promises.constants.F_OK);
|
|
10428
10427
|
return "A directory with this name already exists";
|
|
10429
10428
|
} catch {
|
|
10430
10429
|
return val.length > 2 || "The name must be at least 3 characters long";
|
|
@@ -10569,8 +10568,8 @@ function init_default(program2) {
|
|
|
10569
10568
|
}
|
|
10570
10569
|
async function setupProjectStructure(dirName) {
|
|
10571
10570
|
await createDir(dirName);
|
|
10572
|
-
await createDir((0,
|
|
10573
|
-
await createDir((0,
|
|
10571
|
+
await createDir((0, import_path5.resolve)(dirName, ".vscode"));
|
|
10572
|
+
await createDir((0, import_path5.resolve)(dirName, "capabilities"));
|
|
10574
10573
|
}
|
|
10575
10574
|
async function createProjectFiles(dirName, packageJSON2) {
|
|
10576
10575
|
const files = [
|
|
@@ -10589,10 +10588,10 @@ async function createProjectFiles(dirName, packageJSON2) {
|
|
|
10589
10588
|
{ dir: "capabilities", path: helloPepr.path, data: helloPepr.data }
|
|
10590
10589
|
];
|
|
10591
10590
|
for (const file of files) {
|
|
10592
|
-
await write((0,
|
|
10591
|
+
await write((0, import_path5.resolve)(dirName, file.path), file.data);
|
|
10593
10592
|
}
|
|
10594
10593
|
for (const file of nestedFiles) {
|
|
10595
|
-
await write((0,
|
|
10594
|
+
await write((0, import_path5.resolve)(dirName, file.dir, file.path), file.data);
|
|
10596
10595
|
}
|
|
10597
10596
|
}
|
|
10598
10597
|
var doPostInitActions = (dirName) => {
|
|
@@ -10650,8 +10649,8 @@ var RootCmd = class extends import_commander2.Command {
|
|
|
10650
10649
|
|
|
10651
10650
|
// src/cli/update/index.ts
|
|
10652
10651
|
var import_child_process6 = require("child_process");
|
|
10653
|
-
var
|
|
10654
|
-
var
|
|
10652
|
+
var import_fs14 = __toESM(require("fs"));
|
|
10653
|
+
var import_path6 = require("path");
|
|
10655
10654
|
var import_prompts5 = __toESM(require("prompts"));
|
|
10656
10655
|
function update_default(program2) {
|
|
10657
10656
|
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) => {
|
|
@@ -10667,22 +10666,6 @@ function update_default(program2) {
|
|
|
10667
10666
|
}
|
|
10668
10667
|
console.log("Updating the Pepr module...");
|
|
10669
10668
|
try {
|
|
10670
|
-
let packageLockContent = "";
|
|
10671
|
-
let foundPackageLock = false;
|
|
10672
|
-
try {
|
|
10673
|
-
if (import_fs13.default.existsSync("./package-lock.json")) {
|
|
10674
|
-
packageLockContent = import_fs13.default.readFileSync("./package-lock.json", "utf-8");
|
|
10675
|
-
foundPackageLock = true;
|
|
10676
|
-
}
|
|
10677
|
-
} catch {
|
|
10678
|
-
}
|
|
10679
|
-
if (foundPackageLock && packageLockContent) {
|
|
10680
|
-
if (packageLockContent.indexOf('"eslint":') >= 0 && packageLockContent.match(/"eslint":\s*"[~^]?8\.[0-9]+\.[0-9]+"/)) {
|
|
10681
|
-
console.warn(
|
|
10682
|
-
"\nWarning: This Pepr module uses ESLint v8. Pepr will be upgraded to use v9 in a future release.\nSee eslint@9.0.0 release notes for more details: https://eslint.org/blog/2024/04/eslint-v9.0.0-released/"
|
|
10683
|
-
);
|
|
10684
|
-
}
|
|
10685
|
-
}
|
|
10686
10669
|
(0, import_child_process6.execSync)("npm install pepr@latest", {
|
|
10687
10670
|
stdio: "inherit"
|
|
10688
10671
|
});
|
|
@@ -10694,30 +10677,31 @@ function update_default(program2) {
|
|
|
10694
10677
|
console.log(`\u2705 Module updated successfully`);
|
|
10695
10678
|
} catch (e) {
|
|
10696
10679
|
console.error(`Error updating Pepr module:`, e);
|
|
10697
|
-
process.
|
|
10680
|
+
process.exitCode = 1;
|
|
10698
10681
|
}
|
|
10699
10682
|
});
|
|
10700
10683
|
program2.command("update-templates", { hidden: true }).description("Perform template updates").action(async (opts) => {
|
|
10701
10684
|
console.log("Updating Pepr config and template tiles...");
|
|
10702
10685
|
try {
|
|
10703
10686
|
if (!opts.skipTemplateUpdate) {
|
|
10704
|
-
await write((0,
|
|
10705
|
-
await write((0,
|
|
10706
|
-
await write((0,
|
|
10707
|
-
await write((0,
|
|
10708
|
-
const samplePath = (0,
|
|
10709
|
-
if (
|
|
10710
|
-
|
|
10687
|
+
await write((0, import_path6.resolve)(prettier.path), prettier.data);
|
|
10688
|
+
await write((0, import_path6.resolve)(tsConfig.path), tsConfig.data);
|
|
10689
|
+
await write((0, import_path6.resolve)(".vscode", snippet.path), snippet.data);
|
|
10690
|
+
await write((0, import_path6.resolve)(".vscode", codeSettings.path), codeSettings.data);
|
|
10691
|
+
const samplePath = (0, import_path6.resolve)("capabilities", samplesYaml.path);
|
|
10692
|
+
if (import_fs14.default.existsSync(samplePath)) {
|
|
10693
|
+
import_fs14.default.unlinkSync(samplePath);
|
|
10711
10694
|
await write(samplePath, samplesYaml.data);
|
|
10712
10695
|
}
|
|
10713
|
-
const tsPath = (0,
|
|
10714
|
-
if (
|
|
10696
|
+
const tsPath = (0, import_path6.resolve)("capabilities", helloPepr.path);
|
|
10697
|
+
if (import_fs14.default.existsSync(tsPath)) {
|
|
10715
10698
|
await write(tsPath, helloPepr.data);
|
|
10716
10699
|
}
|
|
10717
10700
|
}
|
|
10701
|
+
throw new Error("another error, for testing");
|
|
10718
10702
|
} catch (e) {
|
|
10719
10703
|
console.error(`Error updating template files:`, e);
|
|
10720
|
-
process.
|
|
10704
|
+
process.exitCode = 1;
|
|
10721
10705
|
}
|
|
10722
10706
|
});
|
|
10723
10707
|
}
|
|
@@ -10752,8 +10736,8 @@ function kfc_default(program2) {
|
|
|
10752
10736
|
|
|
10753
10737
|
// src/cli/crd/create.ts
|
|
10754
10738
|
var import_commander3 = require("commander");
|
|
10755
|
-
var
|
|
10756
|
-
var
|
|
10739
|
+
var import_fs15 = require("fs");
|
|
10740
|
+
var import_path7 = __toESM(require("path"));
|
|
10757
10741
|
var create = new import_commander3.Command("create").description("Create a new CRD TypeScript definition").requiredOption("--group <group>", "API group (e.g. cache)").requiredOption("--version <version>", "API version (e.g. v1alpha1)").requiredOption("--kind <kind>", "Kind name (e.g. Memcached)").option("--domain <domain>", "Optional domain (e.g. pepr.dev)", "pepr.dev").option(
|
|
10758
10742
|
"--scope <Namespaced | Cluster>",
|
|
10759
10743
|
"Whether the resulting custom resource is cluster- or namespace-scoped",
|
|
@@ -10761,9 +10745,9 @@ var create = new import_commander3.Command("create").description("Create a new C
|
|
|
10761
10745
|
"Namespaced"
|
|
10762
10746
|
).option("--plural <plural>", "Plural name (e.g. memcacheds)", "").option("--shortName <shortName>", "Short name (e.g. mc)", "").action(async ({ group: group2, version: version3, kind: kind8, domain, scope, plural: plural2, shortName }) => {
|
|
10763
10747
|
console.log("This feature is currently in alpha.\n");
|
|
10764
|
-
const outputDir2 =
|
|
10748
|
+
const outputDir2 = import_path7.default.resolve(`./api/${version3}`);
|
|
10765
10749
|
await createDirectoryIfNotExists(outputDir2);
|
|
10766
|
-
await
|
|
10750
|
+
await import_fs15.promises.writeFile(
|
|
10767
10751
|
`./api/${version3}/${kind8.toLowerCase()}_types.ts`,
|
|
10768
10752
|
generateCRDScaffold(group2, version3, kind8, { domain, scope, plural: plural2, shortName })
|
|
10769
10753
|
);
|
|
@@ -10858,8 +10842,8 @@ function validateScope(value) {
|
|
|
10858
10842
|
|
|
10859
10843
|
// src/cli/crd/generate.ts
|
|
10860
10844
|
var import_commander4 = require("commander");
|
|
10861
|
-
var
|
|
10862
|
-
var
|
|
10845
|
+
var import_fs16 = __toESM(require("fs"));
|
|
10846
|
+
var import_path8 = __toESM(require("path"));
|
|
10863
10847
|
var import_yaml = __toESM(require_dist());
|
|
10864
10848
|
var import_ts_morph = require("ts-morph");
|
|
10865
10849
|
|
|
@@ -10889,24 +10873,24 @@ function extractCRDDetails(content, sourceFile) {
|
|
|
10889
10873
|
}
|
|
10890
10874
|
async function generateCRDs(options) {
|
|
10891
10875
|
console.log("This feature is currently in alpha.\n");
|
|
10892
|
-
const outputDir2 =
|
|
10876
|
+
const outputDir2 = import_path8.default.resolve(options.output);
|
|
10893
10877
|
await createDirectoryIfNotExists(outputDir2);
|
|
10894
10878
|
const project = new import_ts_morph.Project();
|
|
10895
|
-
const apiRoot =
|
|
10879
|
+
const apiRoot = import_path8.default.resolve("api");
|
|
10896
10880
|
const versions = getAPIVersions(apiRoot);
|
|
10897
10881
|
for (const version3 of versions) {
|
|
10898
|
-
const sourceFiles = loadVersionFiles(project,
|
|
10882
|
+
const sourceFiles = loadVersionFiles(project, import_path8.default.join(apiRoot, version3));
|
|
10899
10883
|
for (const sourceFile of sourceFiles) {
|
|
10900
10884
|
processSourceFile(sourceFile, version3, outputDir2);
|
|
10901
10885
|
}
|
|
10902
10886
|
}
|
|
10903
10887
|
}
|
|
10904
10888
|
function getAPIVersions(apiRoot) {
|
|
10905
|
-
return
|
|
10889
|
+
return import_fs16.default.readdirSync(apiRoot).filter((v) => import_fs16.default.statSync(import_path8.default.join(apiRoot, v)).isDirectory());
|
|
10906
10890
|
}
|
|
10907
10891
|
function loadVersionFiles(project, versionDir) {
|
|
10908
|
-
const files =
|
|
10909
|
-
const filePaths = files.map((f) =>
|
|
10892
|
+
const files = import_fs16.default.readdirSync(versionDir).filter((f) => f.endsWith(".ts"));
|
|
10893
|
+
const filePaths = files.map((f) => import_path8.default.join(versionDir, f));
|
|
10910
10894
|
return project.addSourceFilesAtPaths(filePaths);
|
|
10911
10895
|
}
|
|
10912
10896
|
function processSourceFile(sourceFile, version3, outputDir2) {
|
|
@@ -10934,8 +10918,8 @@ function processSourceFile(sourceFile, version3, outputDir2) {
|
|
|
10934
10918
|
specSchema,
|
|
10935
10919
|
conditionSchema
|
|
10936
10920
|
});
|
|
10937
|
-
const outPath =
|
|
10938
|
-
|
|
10921
|
+
const outPath = import_path8.default.join(outputDir2, `${kind8.toLowerCase()}.yaml`);
|
|
10922
|
+
import_fs16.default.writeFileSync(outPath, (0, import_yaml.stringify)(crd), "utf8");
|
|
10939
10923
|
console.log(`\u2714 Created ${outPath}`);
|
|
10940
10924
|
}
|
|
10941
10925
|
function extractSingleLineComment(content, label) {
|