pepr 0.46.1-nightly.1 → 0.46.1-nightly.3
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 +1 -1
- package/dist/controller.js +1 -1
- package/dist/lib/assets/defaultTestObjects.d.ts +8 -0
- package/dist/lib/assets/defaultTestObjects.d.ts.map +1 -1
- package/dist/lib/processors/decode-utils.d.ts +8 -0
- package/dist/lib/processors/decode-utils.d.ts.map +1 -0
- package/dist/lib/processors/mutate-processor.d.ts +0 -5
- package/dist/lib/processors/mutate-processor.d.ts.map +1 -1
- package/dist/lib.js +22 -17
- package/dist/lib.js.map +4 -4
- package/package.json +1 -1
- package/src/lib/assets/defaultTestObjects.ts +18 -1
- package/src/lib/processors/decode-utils.ts +31 -0
- package/src/lib/processors/mutate-processor.ts +7 -30
package/package.json
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
|
-
import { GenericClass } from "kubernetes-fluent-client";
|
|
1
|
+
import { GenericClass, GroupVersionKind } from "kubernetes-fluent-client";
|
|
2
2
|
import { Event } from "../enums";
|
|
3
3
|
import { Binding, CapabilityExport } from "../types";
|
|
4
4
|
import { defaultFilters } from "../filter/adjudicators/defaultTestObjects";
|
|
5
5
|
import { V1PolicyRule as PolicyRule } from "@kubernetes/client-node";
|
|
6
|
+
import { AdmissionRequest, GroupVersionResource } from "../types";
|
|
7
|
+
import { Operation } from "../enums";
|
|
8
|
+
|
|
9
|
+
export const createMockAdmissionRequest = (
|
|
10
|
+
kind: GroupVersionKind = { kind: "kind", group: "group", version: "version" },
|
|
11
|
+
resource: GroupVersionResource = { group: "group", version: "version", resource: "resource" },
|
|
12
|
+
object: { metadata: { name: string } } = { metadata: { name: "create-me" } },
|
|
13
|
+
operation: Operation = Operation.CREATE,
|
|
14
|
+
): AdmissionRequest => ({
|
|
15
|
+
uid: "uid",
|
|
16
|
+
kind,
|
|
17
|
+
resource,
|
|
18
|
+
name: "",
|
|
19
|
+
object,
|
|
20
|
+
operation,
|
|
21
|
+
userInfo: {},
|
|
22
|
+
});
|
|
6
23
|
|
|
7
24
|
export const createMockRbacRule = (
|
|
8
25
|
apiGroups: string[] = ["pepr.dev"],
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { convertFromBase64Map, convertToBase64Map } from "../utils";
|
|
2
|
+
import { kind, KubernetesObject } from "kubernetes-fluent-client";
|
|
3
|
+
import { PeprMutateRequest } from "../mutate-request";
|
|
4
|
+
import { clone } from "ramda";
|
|
5
|
+
|
|
6
|
+
export function decodeData(wrapped: PeprMutateRequest<KubernetesObject>): {
|
|
7
|
+
skipped: string[];
|
|
8
|
+
wrapped: PeprMutateRequest<KubernetesObject>;
|
|
9
|
+
} {
|
|
10
|
+
let skipped: string[] = [];
|
|
11
|
+
|
|
12
|
+
const isSecret = wrapped.Request.kind.version === "v1" && wrapped.Request.kind.kind === "Secret";
|
|
13
|
+
if (isSecret) {
|
|
14
|
+
// convertFromBase64Map modifies it's arg rather than returing a mod'ed copy (ye olde side-effect special, blerg)
|
|
15
|
+
skipped = convertFromBase64Map(wrapped.Raw as unknown as kind.Secret);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return { skipped, wrapped };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function reencodeData(wrapped: PeprMutateRequest<KubernetesObject>, skipped: string[]): KubernetesObject {
|
|
22
|
+
const transformed = clone(wrapped.Raw);
|
|
23
|
+
|
|
24
|
+
const isSecret = wrapped.Request.kind.version === "v1" && wrapped.Request.kind.kind === "Secret";
|
|
25
|
+
if (isSecret) {
|
|
26
|
+
// convertToBase64Map modifies it's arg rather than returing a mod'ed copy (ye olde side-effect special, blerg)
|
|
27
|
+
convertToBase64Map(transformed as unknown as kind.Secret, skipped);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return transformed;
|
|
31
|
+
}
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
3
|
|
|
4
4
|
import jsonPatch from "fast-json-patch";
|
|
5
|
-
import {
|
|
6
|
-
import { clone } from "ramda";
|
|
5
|
+
import { KubernetesObject } from "kubernetes-fluent-client";
|
|
7
6
|
import { MeasureWebhookTimeout } from "../telemetry/webhookTimeouts";
|
|
8
7
|
import { Capability } from "../core/capability";
|
|
9
8
|
import { shouldSkipRequest } from "../filter/filter";
|
|
@@ -12,11 +11,13 @@ import { AdmissionRequest, Binding } from "../types";
|
|
|
12
11
|
import Log from "../telemetry/logger";
|
|
13
12
|
import { ModuleConfig } from "../types";
|
|
14
13
|
import { PeprMutateRequest } from "../mutate-request";
|
|
15
|
-
import { base64Encode
|
|
14
|
+
import { base64Encode } from "../utils";
|
|
16
15
|
import { OnError } from "../../cli/init/enums";
|
|
17
16
|
import { resolveIgnoreNamespaces } from "../assets/webhooks";
|
|
18
17
|
import { Operation } from "fast-json-patch";
|
|
19
18
|
import { WebhookType } from "../enums";
|
|
19
|
+
import { decodeData, reencodeData } from "./decode-utils";
|
|
20
|
+
|
|
20
21
|
export interface Bindable {
|
|
21
22
|
req: AdmissionRequest;
|
|
22
23
|
config: ModuleConfig;
|
|
@@ -60,33 +61,6 @@ export function logMutateErrorMessage(e: Error): string {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
export function decodeData(wrapped: PeprMutateRequest<KubernetesObject>): {
|
|
64
|
-
skipped: string[];
|
|
65
|
-
wrapped: PeprMutateRequest<KubernetesObject>;
|
|
66
|
-
} {
|
|
67
|
-
let skipped: string[] = [];
|
|
68
|
-
|
|
69
|
-
const isSecret = wrapped.Request.kind.version === "v1" && wrapped.Request.kind.kind === "Secret";
|
|
70
|
-
if (isSecret) {
|
|
71
|
-
// convertFromBase64Map modifies it's arg rather than returing a mod'ed copy (ye olde side-effect special, blerg)
|
|
72
|
-
skipped = convertFromBase64Map(wrapped.Raw as unknown as kind.Secret);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return { skipped, wrapped };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function reencodeData(wrapped: PeprMutateRequest<KubernetesObject>, skipped: string[]): KubernetesObject {
|
|
79
|
-
const transformed = clone(wrapped.Raw);
|
|
80
|
-
|
|
81
|
-
const isSecret = wrapped.Request.kind.version === "v1" && wrapped.Request.kind.kind === "Secret";
|
|
82
|
-
if (isSecret) {
|
|
83
|
-
// convertToBase64Map modifies it's arg rather than returing a mod'ed copy (ye olde side-effect special, blerg)
|
|
84
|
-
convertToBase64Map(transformed as unknown as kind.Secret, skipped);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return transformed;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
64
|
export async function processRequest(
|
|
91
65
|
bindable: Bindable,
|
|
92
66
|
wrapped: PeprMutateRequest<KubernetesObject>,
|
|
@@ -186,6 +160,7 @@ export async function mutateProcessor(
|
|
|
186
160
|
for (const bindable of bindables) {
|
|
187
161
|
({ wrapped, response } = await processRequest(bindable, wrapped, response));
|
|
188
162
|
if (config.onError === OnError.REJECT && response?.warnings!.length > 0) {
|
|
163
|
+
webhookTimer.stop();
|
|
189
164
|
return response;
|
|
190
165
|
}
|
|
191
166
|
}
|
|
@@ -196,11 +171,13 @@ export async function mutateProcessor(
|
|
|
196
171
|
// If no capability matched the request, exit early
|
|
197
172
|
if (bindables.length === 0) {
|
|
198
173
|
Log.info(reqMetadata, `No matching actions found`);
|
|
174
|
+
webhookTimer.stop();
|
|
199
175
|
return response;
|
|
200
176
|
}
|
|
201
177
|
|
|
202
178
|
// delete operations can't be mutate, just return before the transformation
|
|
203
179
|
if (req.operation === "DELETE") {
|
|
180
|
+
webhookTimer.stop();
|
|
204
181
|
return response;
|
|
205
182
|
}
|
|
206
183
|
|