pepr 0.13.2 → 0.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +88 -70
- package/dist/controller.js +2 -2
- package/dist/lib/filter.d.ts +1 -1
- package/dist/lib/filter.d.ts.map +1 -1
- package/dist/lib.js +7 -6
- package/dist/lib.js.map +2 -2
- package/journey/k8s.ts +20 -1
- package/journey/pepr-deploy.ts +43 -2
- package/package.json +8 -8
- package/src/lib/filter.ts +3 -2
- package/src/lib/mutate-processor.ts +2 -2
- package/src/lib/validate-processor.ts +2 -2
- package/src/runtime/controller.ts +1 -1
- package/src/templates/.eslintrc.template.json +18 -0
- package/src/templates/.prettierrc.json +13 -0
- package/src/templates/README.md +21 -0
- package/src/templates/capabilities/hello-pepr.samples.json +160 -0
- package/src/templates/capabilities/hello-pepr.ts +372 -0
- package/src/templates/gitignore +4 -0
- package/src/templates/package.json +14 -0
- package/src/templates/pepr.code-snippets.json +21 -0
- package/src/templates/pepr.ts +17 -0
- package/src/templates/settings.json +9 -0
- package/src/templates/tsconfig.json +9 -0
- package/src/templates/tsconfig.module.json +19 -0
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=18.0.0"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.13.
|
|
12
|
+
"version": "0.13.4",
|
|
13
13
|
"main": "dist/lib.js",
|
|
14
14
|
"types": "dist/lib.d.ts",
|
|
15
15
|
"scripts": {
|
|
@@ -27,28 +27,28 @@
|
|
|
27
27
|
"format:fix": "eslint src --fix && prettier src --write"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@kubernetes/client-node": "0.
|
|
30
|
+
"@kubernetes/client-node": "0.19.0",
|
|
31
31
|
"express": "4.18.2",
|
|
32
32
|
"fast-json-patch": "3.1.1",
|
|
33
33
|
"http-status-codes": "2.2.0",
|
|
34
34
|
"node-fetch": "2.7.0",
|
|
35
|
-
"pino": "8.15.
|
|
35
|
+
"pino": "8.15.1",
|
|
36
36
|
"pino-pretty": "10.2.0",
|
|
37
37
|
"prom-client": "14.2.0",
|
|
38
38
|
"ramda": "0.29.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@jest/globals": "29.
|
|
41
|
+
"@jest/globals": "29.7.0",
|
|
42
42
|
"@types/eslint": "8.44.2",
|
|
43
43
|
"@types/express": "4.17.17",
|
|
44
44
|
"@types/node": "18.x.x",
|
|
45
45
|
"@types/node-fetch": "2.6.4",
|
|
46
|
-
"@types/node-forge": "1.3.
|
|
46
|
+
"@types/node-forge": "1.3.5",
|
|
47
47
|
"@types/prettier": "3.0.0",
|
|
48
48
|
"@types/prompts": "2.4.4",
|
|
49
|
-
"@types/ramda": "0.29.
|
|
50
|
-
"@types/uuid": "9.0.
|
|
51
|
-
"jest": "29.
|
|
49
|
+
"@types/ramda": "0.29.4",
|
|
50
|
+
"@types/uuid": "9.0.4",
|
|
51
|
+
"jest": "29.7.0",
|
|
52
52
|
"nock": "13.3.3",
|
|
53
53
|
"ts-jest": "29.1.1"
|
|
54
54
|
},
|
package/src/lib/filter.ts
CHANGED
|
@@ -12,13 +12,14 @@ import { Binding, Event } from "./types";
|
|
|
12
12
|
* @param req the incoming request
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
|
15
|
-
export function shouldSkipRequest(binding: Binding, req: Request) {
|
|
15
|
+
export function shouldSkipRequest(binding: Binding, req: Request, capabilityNamespaces: string[]) {
|
|
16
16
|
const { group, kind, version } = binding.kind || {};
|
|
17
17
|
const { namespaces, labels, annotations, name } = binding.filters || {};
|
|
18
18
|
const operation = req.operation.toUpperCase();
|
|
19
19
|
// Use the old object if the request is a DELETE operation
|
|
20
20
|
const srcObject = operation === Operation.DELETE ? req.oldObject : req.object;
|
|
21
21
|
const { metadata } = srcObject || {};
|
|
22
|
+
const combinedNamespaces = [...namespaces, ...capabilityNamespaces];
|
|
22
23
|
|
|
23
24
|
// Test for matching operation
|
|
24
25
|
if (!binding.event.includes(operation) && !binding.event.includes(Event.Any)) {
|
|
@@ -46,7 +47,7 @@ export function shouldSkipRequest(binding: Binding, req: Request) {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
// Test for matching namespaces
|
|
49
|
-
if (
|
|
50
|
+
if (combinedNamespaces.length && !combinedNamespaces.includes(req.namespace || "")) {
|
|
50
51
|
logger.debug("Namespace does not match");
|
|
51
52
|
return true;
|
|
52
53
|
}
|
|
@@ -40,7 +40,7 @@ export async function mutateProcessor(
|
|
|
40
40
|
|
|
41
41
|
Log.info(reqMetadata, `Processing request`);
|
|
42
42
|
|
|
43
|
-
for (const { name, bindings } of capabilities) {
|
|
43
|
+
for (const { name, bindings, namespaces } of capabilities) {
|
|
44
44
|
const actionMetadata = { ...reqMetadata, name };
|
|
45
45
|
|
|
46
46
|
for (const action of bindings) {
|
|
@@ -50,7 +50,7 @@ export async function mutateProcessor(
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Continue to the next action without doing anything if this one should be skipped
|
|
53
|
-
if (shouldSkipRequest(action, req)) {
|
|
53
|
+
if (shouldSkipRequest(action, req, namespaces)) {
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -28,7 +28,7 @@ export async function validateProcessor(
|
|
|
28
28
|
|
|
29
29
|
Log.info(reqMetadata, `Processing validation request`);
|
|
30
30
|
|
|
31
|
-
for (const { name, bindings } of capabilities) {
|
|
31
|
+
for (const { name, bindings, namespaces } of capabilities) {
|
|
32
32
|
const actionMetadata = { ...reqMetadata, name };
|
|
33
33
|
|
|
34
34
|
for (const action of bindings) {
|
|
@@ -38,7 +38,7 @@ export async function validateProcessor(
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// Continue to the next action without doing anything if this one should be skipped
|
|
41
|
-
if (shouldSkipRequest(action, req)) {
|
|
41
|
+
if (shouldSkipRequest(action, req, namespaces)) {
|
|
42
42
|
continue;
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": false,
|
|
4
|
+
"es2021": true
|
|
5
|
+
},
|
|
6
|
+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
7
|
+
"parser": "@typescript-eslint/parser",
|
|
8
|
+
"parserOptions": {
|
|
9
|
+
"project": ["./tsconfig.json"],
|
|
10
|
+
"ecmaVersion": 2022
|
|
11
|
+
},
|
|
12
|
+
"plugins": ["@typescript-eslint"],
|
|
13
|
+
"ignorePatterns": ["node_modules", "dist"],
|
|
14
|
+
"root": true,
|
|
15
|
+
"rules": {
|
|
16
|
+
"@typescript-eslint/no-floating-promises": ["error"]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"arrowParens": "avoid",
|
|
3
|
+
"bracketSameLine": false,
|
|
4
|
+
"bracketSpacing": true,
|
|
5
|
+
"embeddedLanguageFormatting": "auto",
|
|
6
|
+
"insertPragma": false,
|
|
7
|
+
"printWidth": 80,
|
|
8
|
+
"quoteProps": "as-needed",
|
|
9
|
+
"requirePragma": false,
|
|
10
|
+
"semi": true,
|
|
11
|
+
"tabWidth": 2,
|
|
12
|
+
"useTabs": false
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Pepr Module
|
|
2
|
+
|
|
3
|
+
This is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.
|
|
4
|
+
|
|
5
|
+
The `capabilities` directory contains all the capabilities for this module. By default,
|
|
6
|
+
a capability is a single typescript file in the format of `capability-name.ts` that is
|
|
7
|
+
imported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.
|
|
8
|
+
Because this is typescript, you can organize this however you choose, e.g. creating a sub-folder
|
|
9
|
+
per-capability or common logic in shared files or folders.
|
|
10
|
+
|
|
11
|
+
Example Structure:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Module Root
|
|
15
|
+
├── package.json
|
|
16
|
+
├── pepr.ts
|
|
17
|
+
└── capabilities
|
|
18
|
+
├── example-one.ts
|
|
19
|
+
├── example-three.ts
|
|
20
|
+
└── example-two.ts
|
|
21
|
+
```
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"apiVersion": "v1",
|
|
4
|
+
"kind": "Namespace",
|
|
5
|
+
"metadata": {
|
|
6
|
+
"name": "pepr-demo",
|
|
7
|
+
"labels": {
|
|
8
|
+
"keep-me": "please",
|
|
9
|
+
"remove-me": "please"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"apiVersion": "v1",
|
|
15
|
+
"kind": "Namespace",
|
|
16
|
+
"metadata": {
|
|
17
|
+
"name": "pepr-demo-2"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"apiVersion": "v1",
|
|
22
|
+
"kind": "Secret",
|
|
23
|
+
"metadata": {
|
|
24
|
+
"name": "secret-1",
|
|
25
|
+
"namespace": "pepr-demo"
|
|
26
|
+
},
|
|
27
|
+
"data": {
|
|
28
|
+
"example": "dW5pY29ybiBtYWdpYw==",
|
|
29
|
+
"binary-data": "iCZQUg8xYucNUqD+8lyl2YcKjYYygvTtiDSEV9b9WKUkxSSLFJTgIWMJ9GcFFYs4T9JCdda51u74jfq8yHzRuEASl60EdTS/NfWgIIFTGqcNRfqMw+vgpyTMmCyJVaJEDFq6AA==",
|
|
30
|
+
"ascii-with-white-space": "VGhpcyBpcyBzb21lIHJhbmRvbSB0ZXh0OgoKICAgIC0gd2l0aCBsaW5lIGJyZWFrcwogICAgLSBhbmQgdGFicw=="
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"apiVersion": "v1",
|
|
35
|
+
"kind": "ConfigMap",
|
|
36
|
+
"metadata": {
|
|
37
|
+
"name": "example-1",
|
|
38
|
+
"namespace": "pepr-demo"
|
|
39
|
+
},
|
|
40
|
+
"data": {
|
|
41
|
+
"key": "ex-1-val"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"apiVersion": "v1",
|
|
46
|
+
"kind": "ConfigMap",
|
|
47
|
+
"metadata": {
|
|
48
|
+
"name": "example-2",
|
|
49
|
+
"namespace": "pepr-demo"
|
|
50
|
+
},
|
|
51
|
+
"data": {
|
|
52
|
+
"key": "ex-2-val"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"apiVersion": "v1",
|
|
57
|
+
"kind": "ConfigMap",
|
|
58
|
+
"metadata": {
|
|
59
|
+
"name": "example-evil-cm",
|
|
60
|
+
"namespace": "pepr-demo",
|
|
61
|
+
"annotations": {
|
|
62
|
+
"evil": "true"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"data": {
|
|
66
|
+
"key": "ex-evil-cm-val"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"apiVersion": "v1",
|
|
71
|
+
"kind": "ConfigMap",
|
|
72
|
+
"metadata": {
|
|
73
|
+
"name": "example-3",
|
|
74
|
+
"namespace": "pepr-demo",
|
|
75
|
+
"labels": {
|
|
76
|
+
"change": "by-label"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"data": {
|
|
80
|
+
"key": "ex-3-val"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"apiVersion": "v1",
|
|
85
|
+
"kind": "ConfigMap",
|
|
86
|
+
"metadata": {
|
|
87
|
+
"name": "example-4",
|
|
88
|
+
"namespace": "pepr-demo"
|
|
89
|
+
},
|
|
90
|
+
"data": {
|
|
91
|
+
"key": "ex-4-val"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"apiVersion": "v1",
|
|
96
|
+
"kind": "ConfigMap",
|
|
97
|
+
"metadata": {
|
|
98
|
+
"name": "example-4a",
|
|
99
|
+
"namespace": "pepr-demo-2"
|
|
100
|
+
},
|
|
101
|
+
"data": {
|
|
102
|
+
"key": "ex-4-val"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"apiVersion": "v1",
|
|
107
|
+
"kind": "ConfigMap",
|
|
108
|
+
"metadata": {
|
|
109
|
+
"name": "example-5",
|
|
110
|
+
"namespace": "pepr-demo",
|
|
111
|
+
"labels": {
|
|
112
|
+
"chuck-norris": "test"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"data": {
|
|
116
|
+
"key": "ex-5-val"
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"apiVersion": "apiextensions.k8s.io/v1",
|
|
121
|
+
"kind": "CustomResourceDefinition",
|
|
122
|
+
"metadata": {
|
|
123
|
+
"name": "unicorns.pepr.dev"
|
|
124
|
+
},
|
|
125
|
+
"spec": {
|
|
126
|
+
"group": "pepr.dev",
|
|
127
|
+
"versions": [
|
|
128
|
+
{
|
|
129
|
+
"name": "v1",
|
|
130
|
+
"served": true,
|
|
131
|
+
"storage": true,
|
|
132
|
+
"schema": {
|
|
133
|
+
"openAPIV3Schema": {
|
|
134
|
+
"type": "object",
|
|
135
|
+
"properties": {
|
|
136
|
+
"spec": {
|
|
137
|
+
"type": "object",
|
|
138
|
+
"properties": {
|
|
139
|
+
"message": {
|
|
140
|
+
"type": "string"
|
|
141
|
+
},
|
|
142
|
+
"counter": {
|
|
143
|
+
"type": "number"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
"scope": "Namespaced",
|
|
153
|
+
"names": {
|
|
154
|
+
"plural": "unicorns",
|
|
155
|
+
"singular": "unicorn",
|
|
156
|
+
"kind": "Unicorn"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
]
|