pepr 0.32.0 → 0.32.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/cli.d.ts +3 -0
  2. package/dist/cli.js +1 -1
  3. package/dist/controller.js +1 -1
  4. package/dist/lib/assets/deploy.d.ts +3 -0
  5. package/dist/lib/assets/destroy.d.ts +2 -0
  6. package/dist/lib/assets/helm.d.ts +5 -0
  7. package/dist/lib/assets/index.d.ts +25 -0
  8. package/dist/lib/assets/loader.d.ts +8 -0
  9. package/dist/lib/assets/networking.d.ts +7 -0
  10. package/dist/lib/assets/pods.d.ts +126 -0
  11. package/dist/lib/assets/rbac.d.ts +14 -0
  12. package/dist/lib/assets/store.d.ts +7 -0
  13. package/dist/lib/assets/webhooks.d.ts +6 -0
  14. package/dist/lib/assets/yaml.d.ts +6 -0
  15. package/dist/lib/capability.d.ts +66 -0
  16. package/dist/lib/controller/index.d.ts +10 -0
  17. package/dist/lib/controller/store.d.ts +7 -0
  18. package/dist/lib/errors.d.ts +12 -0
  19. package/dist/lib/filter.d.ts +11 -0
  20. package/dist/lib/helpers.d.ts +34 -0
  21. package/dist/lib/included-files.d.ts +2 -0
  22. package/dist/lib/k8s.d.ts +132 -0
  23. package/dist/lib/logger.d.ts +3 -0
  24. package/dist/lib/metrics.d.ts +39 -0
  25. package/dist/lib/module.d.ts +62 -0
  26. package/dist/lib/mutate-processor.d.ts +5 -0
  27. package/dist/lib/mutate-request.d.ts +79 -0
  28. package/dist/lib/queue.d.ts +19 -0
  29. package/dist/lib/schedule.d.ts +76 -0
  30. package/dist/lib/storage.d.ts +83 -0
  31. package/dist/lib/tls.d.ts +18 -0
  32. package/dist/lib/types.d.ts +192 -0
  33. package/dist/lib/utils.d.ts +23 -0
  34. package/dist/lib/validate-processor.d.ts +4 -0
  35. package/dist/lib/validate-request.d.ts +55 -0
  36. package/dist/lib/watch-processor.d.ts +10 -0
  37. package/dist/lib.d.ts +11 -0
  38. package/dist/runtime/controller.d.ts +3 -0
  39. package/dist/sdk/sdk.d.ts +38 -0
  40. package/package.json +2 -2
@@ -0,0 +1,39 @@
1
+ /**
2
+ * MetricsCollector class handles metrics collection using prom-client and performance hooks.
3
+ */
4
+ export declare class MetricsCollector {
5
+ #private;
6
+ /**
7
+ * Creates a MetricsCollector instance with prefixed metrics.
8
+ * @param [prefix='pepr'] - The prefix for the metric names.
9
+ */
10
+ constructor(prefix?: string);
11
+ addCounter: (name: string, help: string) => void;
12
+ addSummary: (name: string, help: string) => void;
13
+ incCounter: (name: string) => void;
14
+ /**
15
+ * Increments the error counter.
16
+ */
17
+ error: () => void;
18
+ /**
19
+ * Increments the alerts counter.
20
+ */
21
+ alert: () => void;
22
+ /**
23
+ * Observes the duration since the provided start time and updates the summary.
24
+ * @param startTime - The start time.
25
+ * @param name - The metrics summary to increment.
26
+ */
27
+ observeEnd: (startTime: number, name?: string) => void;
28
+ /**
29
+ * Fetches the current metrics from the registry.
30
+ * @returns The metrics.
31
+ */
32
+ getMetrics: () => Promise<string>;
33
+ /**
34
+ * Returns the current timestamp from performance.now() method. Useful for start timing an operation.
35
+ * @returns The timestamp.
36
+ */
37
+ static observeStart(): number;
38
+ }
39
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { Capability } from "./capability";
2
+ import { AdmissionRequest, MutateResponse, ValidateResponse, WebhookIgnore } from "./k8s";
3
+ /** Custom Labels Type for package.json */
4
+ export interface CustomLabels {
5
+ namespace?: Record<string, string>;
6
+ }
7
+ /** Global configuration for the Pepr runtime. */
8
+ export type ModuleConfig = {
9
+ /** The Pepr version this module uses */
10
+ peprVersion?: string;
11
+ /** The user-defined version of the module */
12
+ appVersion?: string;
13
+ /** A unique identifier for this Pepr module. This is automatically generated by Pepr. */
14
+ uuid: string;
15
+ /** A description of the Pepr module and what it does. */
16
+ description?: string;
17
+ /** The webhookTimeout */
18
+ webhookTimeout?: number;
19
+ /** Reject K8s resource AdmissionRequests on error. */
20
+ onError?: string;
21
+ /** Configure global exclusions that will never be processed by Pepr. */
22
+ alwaysIgnore: WebhookIgnore;
23
+ /** Define the log level for the in-cluster controllers */
24
+ logLevel?: string;
25
+ /** Propagate env variables to in-cluster controllers */
26
+ env?: Record<string, string>;
27
+ /** Custom Labels for Kubernetes Objects */
28
+ customLabels?: CustomLabels;
29
+ };
30
+ export type PackageJSON = {
31
+ description: string;
32
+ pepr: ModuleConfig;
33
+ };
34
+ export type PeprModuleOptions = {
35
+ deferStart?: boolean;
36
+ /** A user-defined callback to pre-process or intercept a Pepr request from K8s immediately before it is processed */
37
+ beforeHook?: (req: AdmissionRequest) => void;
38
+ /** A user-defined callback to post-process or intercept a Pepr response just before it is returned to K8s */
39
+ afterHook?: (res: MutateResponse | ValidateResponse) => void;
40
+ };
41
+ export declare const isWatchMode: () => boolean;
42
+ export declare const isBuildMode: () => boolean;
43
+ export declare const isDevMode: () => boolean;
44
+ export declare class PeprModule {
45
+ #private;
46
+ /**
47
+ * Create a new Pepr runtime
48
+ *
49
+ * @param config The configuration for the Pepr runtime
50
+ * @param capabilities The capabilities to be loaded into the Pepr runtime
51
+ * @param opts Options for the Pepr runtime
52
+ */
53
+ constructor({ description, pepr }: PackageJSON, capabilities?: Capability[], opts?: PeprModuleOptions);
54
+ /**
55
+ * Start the Pepr runtime manually.
56
+ * Normally this is called automatically when the Pepr module is instantiated, but can be called manually if `deferStart` is set to `true` in the constructor.
57
+ *
58
+ * @param port
59
+ */
60
+ start: (port?: number) => void;
61
+ }
62
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1,5 @@
1
+ import { Capability } from "./capability";
2
+ import { MutateResponse, AdmissionRequest } from "./k8s";
3
+ import { ModuleConfig } from "./module";
4
+ export declare function mutateProcessor(config: ModuleConfig, capabilities: Capability[], req: AdmissionRequest, reqMetadata: Record<string, string>): Promise<MutateResponse>;
5
+ //# sourceMappingURL=mutate-processor.d.ts.map
@@ -0,0 +1,79 @@
1
+ import { KubernetesObject } from "kubernetes-fluent-client";
2
+ import { AdmissionRequest } from "./k8s";
3
+ import { DeepPartial } from "./types";
4
+ /**
5
+ * The RequestWrapper class provides methods to modify Kubernetes objects in the context
6
+ * of a mutating webhook request.
7
+ */
8
+ export declare class PeprMutateRequest<T extends KubernetesObject> {
9
+ #private;
10
+ Raw: T;
11
+ get PermitSideEffects(): boolean;
12
+ /**
13
+ * Indicates whether the request is a dry run.
14
+ * @returns true if the request is a dry run, false otherwise.
15
+ */
16
+ get IsDryRun(): boolean | undefined;
17
+ /**
18
+ * Provides access to the old resource in the request if available.
19
+ * @returns The old Kubernetes resource object or null if not available.
20
+ */
21
+ get OldResource(): T | undefined;
22
+ /**
23
+ * Provides access to the request object.
24
+ * @returns The request object containing the Kubernetes resource.
25
+ */
26
+ get Request(): AdmissionRequest<T>;
27
+ /**
28
+ * Creates a new instance of the action class.
29
+ * @param input - The request object containing the Kubernetes resource to modify.
30
+ */
31
+ constructor(input: AdmissionRequest<T>);
32
+ /**
33
+ * Deep merges the provided object with the current resource.
34
+ *
35
+ * @param obj - The object to merge with the current resource.
36
+ */
37
+ Merge: (obj: DeepPartial<T>) => void;
38
+ /**
39
+ * Updates a label on the Kubernetes resource.
40
+ * @param key - The key of the label to update.
41
+ * @param value - The value of the label.
42
+ * @returns The current action instance for method chaining.
43
+ */
44
+ SetLabel: (key: string, value: string) => this;
45
+ /**
46
+ * Updates an annotation on the Kubernetes resource.
47
+ * @param key - The key of the annotation to update.
48
+ * @param value - The value of the annotation.
49
+ * @returns The current action instance for method chaining.
50
+ */
51
+ SetAnnotation: (key: string, value: string) => this;
52
+ /**
53
+ * Removes a label from the Kubernetes resource.
54
+ * @param key - The key of the label to remove.
55
+ * @returns The current Action instance for method chaining.
56
+ */
57
+ RemoveLabel: (key: string) => this;
58
+ /**
59
+ * Removes an annotation from the Kubernetes resource.
60
+ * @param key - The key of the annotation to remove.
61
+ * @returns The current Action instance for method chaining.
62
+ */
63
+ RemoveAnnotation: (key: string) => this;
64
+ /**
65
+ * Check if a label exists on the Kubernetes resource.
66
+ *
67
+ * @param key the label key to check
68
+ * @returns
69
+ */
70
+ HasLabel: (key: string) => boolean;
71
+ /**
72
+ * Check if an annotation exists on the Kubernetes resource.
73
+ *
74
+ * @param key the annotation key to check
75
+ * @returns
76
+ */
77
+ HasAnnotation: (key: string) => boolean;
78
+ }
79
+ //# sourceMappingURL=mutate-request.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { KubernetesObject } from "@kubernetes/client-node";
2
+ import { WatchPhase } from "kubernetes-fluent-client/dist/fluent/types";
3
+ /**
4
+ * Queue is a FIFO queue for reconciling
5
+ */
6
+ export declare class Queue<K extends KubernetesObject> {
7
+ #private;
8
+ constructor();
9
+ setReconcile(reconcile: (obj: KubernetesObject, type: WatchPhase) => Promise<void>): void;
10
+ /**
11
+ * Enqueue adds an item to the queue and returns a promise that resolves when the item is
12
+ * reconciled.
13
+ *
14
+ * @param item The object to reconcile
15
+ * @returns A promise that resolves when the object is reconciled
16
+ */
17
+ enqueue(item: K, type: WatchPhase): Promise<void>;
18
+ }
19
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1,76 @@
1
+ /// <reference types="node" />
2
+ import { PeprStore } from "./storage";
3
+ type Unit = "seconds" | "second" | "minute" | "minutes" | "hours" | "hour";
4
+ export interface Schedule {
5
+ /**
6
+ * * The name of the store
7
+ */
8
+ name: string;
9
+ /**
10
+ * The value associated with a unit of time
11
+ */
12
+ every: number;
13
+ /**
14
+ * The unit of time
15
+ */
16
+ unit: Unit;
17
+ /**
18
+ * The code to run
19
+ */
20
+ run: () => void;
21
+ /**
22
+ * The start time of the schedule
23
+ */
24
+ startTime?: Date | undefined;
25
+ /**
26
+ * The number of times the schedule has run
27
+ */
28
+ completions?: number | undefined;
29
+ /**
30
+ * Tje intervalID to clear the interval
31
+ */
32
+ intervalID?: NodeJS.Timeout;
33
+ }
34
+ export declare class OnSchedule implements Schedule {
35
+ intervalId: NodeJS.Timeout | null;
36
+ store: PeprStore | undefined;
37
+ name: string;
38
+ completions?: number | undefined;
39
+ every: number;
40
+ unit: Unit;
41
+ run: () => void;
42
+ startTime?: Date | undefined;
43
+ duration: number | undefined;
44
+ lastTimestamp: Date | undefined;
45
+ constructor(schedule: Schedule);
46
+ setStore(store: PeprStore): void;
47
+ startInterval(): void;
48
+ /**
49
+ * Checks the store for this schedule and sets the values if it exists
50
+ * @returns
51
+ */
52
+ checkStore(): void;
53
+ /**
54
+ * Saves the schedule to the store
55
+ * @returns
56
+ */
57
+ saveToStore(): void;
58
+ /**
59
+ * Gets the durations in milliseconds
60
+ */
61
+ getDuration(): void;
62
+ /**
63
+ * Sets up the interval
64
+ */
65
+ setupInterval(): void;
66
+ /**
67
+ * Starts the interval
68
+ */
69
+ start(): void;
70
+ /**
71
+ * Stops the interval
72
+ */
73
+ stop(): void;
74
+ }
75
+ export {};
76
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1,83 @@
1
+ export type DataOp = "add" | "remove";
2
+ export type DataStore = Record<string, string>;
3
+ export type DataSender = (op: DataOp, keys: string[], value?: string) => void;
4
+ export type DataReceiver = (data: DataStore) => void;
5
+ export type Unsubscribe = () => void;
6
+ export interface PeprStore {
7
+ /**
8
+ * Returns the current value associated with the given key, or null if the given key does not exist.
9
+ */
10
+ getItem(key: string): string | null;
11
+ /**
12
+ * Removes all key/value pairs, if there are any.
13
+ */
14
+ clear(): void;
15
+ /**
16
+ * Removes the key/value pair with the given key, if a key/value pair with the given key exists.
17
+ */
18
+ removeItem(key: string): void;
19
+ /**
20
+ * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
21
+ */
22
+ setItem(key: string, value: string): void;
23
+ /**
24
+ * Subscribe to changes in the store. This API behaves similarly to the [Svelte Store API](https://vercel.com/docs/beginner-sveltekit/svelte-stores#using-the-store).
25
+ *
26
+ * @param listener - The callback to be invoked when the store changes.
27
+ * @returns A function to unsubscribe from the listener.
28
+ */
29
+ subscribe(listener: DataReceiver): Unsubscribe;
30
+ /**
31
+ * Register a function to be called when the store is ready.
32
+ */
33
+ onReady(callback: DataReceiver): void;
34
+ /**
35
+ * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
36
+ * Resolves when the key/value show up in the store.
37
+ */
38
+ setItemAndWait(key: string, value: string): Promise<void>;
39
+ /**
40
+ * Remove the value of the key.
41
+ * Resolves when the key does not show up in the store.
42
+ */
43
+ removeItemAndWait(key: string): Promise<void>;
44
+ }
45
+ /**
46
+ * A key-value data store that can be used to persist data that should be shared across Pepr controllers and capabilities.
47
+ *
48
+ * The API is similar to the [Storage API](https://developer.mozilla.org/docs/Web/API/Storage)
49
+ */
50
+ export declare class Storage implements PeprStore {
51
+ #private;
52
+ registerSender: (send: DataSender) => void;
53
+ receive: (data: DataStore) => void;
54
+ getItem: (key: string) => string | null;
55
+ clear: () => void;
56
+ removeItem: (key: string) => void;
57
+ setItem: (key: string, value: string) => void;
58
+ /**
59
+ * Creates a promise and subscribes to the store, the promise resolves when
60
+ * the key and value are seen in the store.
61
+ *
62
+ * @param key - The key to add into the store
63
+ * @param value - The value of the key
64
+ * @returns
65
+ */
66
+ setItemAndWait: (key: string, value: string) => Promise<void>;
67
+ /**
68
+ * Creates a promise and subscribes to the store, the promise resolves when
69
+ * the key is removed from the store.
70
+ *
71
+ * @param key - The key to add into the store
72
+ * @returns
73
+ */
74
+ removeItemAndWait: (key: string) => Promise<void>;
75
+ subscribe: (subscriber: DataReceiver) => () => void;
76
+ onReady: (callback: DataReceiver) => void;
77
+ /**
78
+ * Remove a subscriber from the list of subscribers.
79
+ * @param idx - The index of the subscriber to remove.
80
+ */
81
+ unsubscribe: (idx: number) => void;
82
+ }
83
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1,18 @@
1
+ export interface TLSOut {
2
+ ca: string;
3
+ crt: string;
4
+ key: string;
5
+ pem: {
6
+ ca: string;
7
+ crt: string;
8
+ key: string;
9
+ };
10
+ }
11
+ /**
12
+ * Generates a self-signed CA and server certificate with Subject Alternative Names (SANs) for the K8s webhook.
13
+ *
14
+ * @param {string} name - The name to use for the server certificate's Common Name and SAN DNS entry.
15
+ * @returns {TLSOut} - An object containing the Base64-encoded CA, server certificate, and server private key.
16
+ */
17
+ export declare function genTLS(name: string): TLSOut;
18
+ //# sourceMappingURL=tls.d.ts.map
@@ -0,0 +1,192 @@
1
+ import { GenericClass, GroupVersionKind, KubernetesObject } from "kubernetes-fluent-client";
2
+ import { WatchAction } from "kubernetes-fluent-client/dist/fluent/types";
3
+ import { PeprMutateRequest } from "./mutate-request";
4
+ import { PeprValidateRequest } from "./validate-request";
5
+ /**
6
+ * Specifically for parsing logs in monitor mode
7
+ */
8
+ export interface ResponseItem {
9
+ uid?: string;
10
+ allowed: boolean;
11
+ status: {
12
+ message: string;
13
+ };
14
+ }
15
+ /**
16
+ * Recursively make all properties in T optional.
17
+ */
18
+ export type DeepPartial<T> = {
19
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
20
+ };
21
+ /**
22
+ * The type of Kubernetes mutating webhook event that the action is registered for.
23
+ */
24
+ export declare enum Event {
25
+ Create = "CREATE",
26
+ Update = "UPDATE",
27
+ Delete = "DELETE",
28
+ CreateOrUpdate = "CREATEORUPDATE",
29
+ Any = "*"
30
+ }
31
+ export interface CapabilityCfg {
32
+ /**
33
+ * The name of the capability. This should be unique.
34
+ */
35
+ name: string;
36
+ /**
37
+ * A description of the capability and what it does.
38
+ */
39
+ description: string;
40
+ /**
41
+ * List of namespaces that this capability applies to, if empty, applies to all namespaces (cluster-wide).
42
+ * This does not supersede the `alwaysIgnore` global configuration.
43
+ */
44
+ namespaces?: string[];
45
+ }
46
+ export interface CapabilityExport extends CapabilityCfg {
47
+ bindings: Binding[];
48
+ hasSchedule: boolean;
49
+ }
50
+ export type WhenSelector<T extends GenericClass> = {
51
+ /** Register an action to be executed when a Kubernetes resource is created or updated. */
52
+ IsCreatedOrUpdated: () => BindingAll<T>;
53
+ /** Register an action to be executed when a Kubernetes resource is created. */
54
+ IsCreated: () => BindingAll<T>;
55
+ /** Register ann action to be executed when a Kubernetes resource is updated. */
56
+ IsUpdated: () => BindingAll<T>;
57
+ /** Register an action to be executed when a Kubernetes resource is deleted. */
58
+ IsDeleted: () => BindingAll<T>;
59
+ };
60
+ export type Binding = {
61
+ event: Event;
62
+ isMutate?: boolean;
63
+ isValidate?: boolean;
64
+ isWatch?: boolean;
65
+ isQueue?: boolean;
66
+ readonly model: GenericClass;
67
+ readonly kind: GroupVersionKind;
68
+ readonly filters: {
69
+ name: string;
70
+ namespaces: string[];
71
+ labels: Record<string, string>;
72
+ annotations: Record<string, string>;
73
+ };
74
+ readonly mutateCallback?: MutateAction<GenericClass, InstanceType<GenericClass>>;
75
+ readonly validateCallback?: ValidateAction<GenericClass, InstanceType<GenericClass>>;
76
+ readonly watchCallback?: WatchAction<GenericClass, InstanceType<GenericClass>>;
77
+ };
78
+ export type BindingFilter<T extends GenericClass> = CommonActionChain<T> & {
79
+ /**
80
+ * Only apply the action if the resource has the specified label. If no value is specified, the label must exist.
81
+ * Note multiple calls to this method will result in an AND condition. e.g.
82
+ *
83
+ * ```ts
84
+ * When(a.Deployment)
85
+ * .IsCreated()
86
+ * .WithLabel("foo", "bar")
87
+ * .WithLabel("baz", "qux")
88
+ * .Mutate(...)
89
+ * ```
90
+ *
91
+ * Will only apply the action if the resource has both the `foo=bar` and `baz=qux` labels.
92
+ *
93
+ * @param key
94
+ * @param value
95
+ */
96
+ WithLabel: (key: string, value?: string) => BindingFilter<T>;
97
+ /**
98
+ * Only apply the action if the resource has the specified annotation. If no value is specified, the annotation must exist.
99
+ * Note multiple calls to this method will result in an AND condition. e.g.
100
+ *
101
+ * ```ts
102
+ * When(a.Deployment)
103
+ * .IsCreated()
104
+ * .WithAnnotation("foo", "bar")
105
+ * .WithAnnotation("baz", "qux")
106
+ * .Mutate(...)
107
+ * ```
108
+ *
109
+ * Will only apply the action if the resource has both the `foo=bar` and `baz=qux` annotations.
110
+ *
111
+ * @param key
112
+ * @param value
113
+ */
114
+ WithAnnotation: (key: string, value?: string) => BindingFilter<T>;
115
+ };
116
+ export type BindingWithName<T extends GenericClass> = BindingFilter<T> & {
117
+ /** Only apply the action if the resource name matches the specified name. */
118
+ WithName: (name: string) => BindingFilter<T>;
119
+ };
120
+ export type BindingAll<T extends GenericClass> = BindingWithName<T> & {
121
+ /** Only apply the action if the resource is in one of the specified namespaces.*/
122
+ InNamespace: (...namespaces: string[]) => BindingWithName<T>;
123
+ };
124
+ export type CommonActionChain<T extends GenericClass> = MutateActionChain<T> & {
125
+ /**
126
+ * Create a new MUTATE action with the specified callback function and previously specified
127
+ * filters.
128
+ *
129
+ * @since 0.13.0
130
+ *
131
+ * @param action The action to be executed when the Kubernetes resource is processed by the AdmissionController.
132
+ */
133
+ Mutate: (action: MutateAction<T, InstanceType<T>>) => MutateActionChain<T>;
134
+ };
135
+ export type ValidateActionChain<T extends GenericClass> = {
136
+ /**
137
+ * Establish a watcher for the specified resource. The callback function will be executed after the admission controller has
138
+ * processed the resource and the request has been persisted to the cluster.
139
+ *
140
+ * **Beta Function**: This method is still in early testing and edge cases may still exist.
141
+ *
142
+ * @since 0.14.0
143
+ *
144
+ * @param action
145
+ * @returns
146
+ */
147
+ Watch: (action: WatchAction<T, InstanceType<T>>) => void;
148
+ /**
149
+ * Establish a reconcile for the specified resource. The callback function will be executed after the admission controller has
150
+ * processed the resource and the request has been persisted to the cluster.
151
+ *
152
+ * **Beta Function**: This method is still in early testing and edge cases may still exist.
153
+ *
154
+ * @since 0.14.0
155
+ *
156
+ * @param action
157
+ * @returns
158
+ */
159
+ Reconcile: (action: WatchAction<T, InstanceType<T>>) => void;
160
+ };
161
+ export type MutateActionChain<T extends GenericClass> = ValidateActionChain<T> & {
162
+ /**
163
+ * Create a new VALIDATE action with the specified callback function and previously specified
164
+ * filters. Return the `request.Approve()` or `Request.Deny()` methods to approve or deny the request:
165
+ *
166
+ * @since 0.13.0
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * When(a.Deployment)
171
+ * .IsCreated()
172
+ * .Validate(request => {
173
+ * if (request.HasLabel("foo")) {
174
+ * return request.Approve();
175
+ * }
176
+ *
177
+ * return request.Deny("Deployment must have label foo");
178
+ * });
179
+ * ```
180
+ *
181
+ * @param action The action to be executed when the Kubernetes resource is processed by the AdmissionController.
182
+ */
183
+ Validate: (action: ValidateAction<T, InstanceType<T>>) => ValidateActionChain<T>;
184
+ };
185
+ export type MutateAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (req: PeprMutateRequest<K>) => Promise<void> | void | Promise<PeprMutateRequest<K>> | PeprMutateRequest<K>;
186
+ export type ValidateAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (req: PeprValidateRequest<K>) => Promise<ValidateActionResponse> | ValidateActionResponse;
187
+ export type ValidateActionResponse = {
188
+ allowed: boolean;
189
+ statusCode?: number;
190
+ statusMessage?: string;
191
+ };
192
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,23 @@
1
+ /** Test if a string is ascii or not */
2
+ export declare const isAscii: RegExp;
3
+ /**
4
+ * Encode all ascii values in a map to base64
5
+ * @param obj The object to encode
6
+ * @param skip A list of keys to skip encoding
7
+ */
8
+ export declare function convertToBase64Map(obj: {
9
+ data?: Record<string, string>;
10
+ }, skip: string[]): void;
11
+ /**
12
+ * Decode all ascii values in a map from base64 to utf-8
13
+ * @param obj The object to decode
14
+ * @returns A list of keys that were skipped
15
+ */
16
+ export declare function convertFromBase64Map(obj: {
17
+ data?: Record<string, string>;
18
+ }): string[];
19
+ /** Decode a base64 string */
20
+ export declare function base64Decode(data: string): string;
21
+ /** Encode a string to base64 */
22
+ export declare function base64Encode(data: string): string;
23
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { Capability } from "./capability";
2
+ import { AdmissionRequest, ValidateResponse } from "./k8s";
3
+ export declare function validateProcessor(capabilities: Capability[], req: AdmissionRequest, reqMetadata: Record<string, string>): Promise<ValidateResponse[]>;
4
+ //# sourceMappingURL=validate-processor.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { KubernetesObject } from "kubernetes-fluent-client";
2
+ import { AdmissionRequest } from "./k8s";
3
+ import { ValidateActionResponse } from "./types";
4
+ /**
5
+ * The RequestWrapper class provides methods to modify Kubernetes objects in the context
6
+ * of a mutating webhook request.
7
+ */
8
+ export declare class PeprValidateRequest<T extends KubernetesObject> {
9
+ #private;
10
+ Raw: T;
11
+ /**
12
+ * Provides access to the old resource in the request if available.
13
+ * @returns The old Kubernetes resource object or null if not available.
14
+ */
15
+ get OldResource(): T | undefined;
16
+ /**
17
+ * Provides access to the request object.
18
+ * @returns The request object containing the Kubernetes resource.
19
+ */
20
+ get Request(): AdmissionRequest<T>;
21
+ /**
22
+ * Creates a new instance of the Action class.
23
+ * @param input - The request object containing the Kubernetes resource to modify.
24
+ */
25
+ constructor(input: AdmissionRequest<T>);
26
+ /**
27
+ * Check if a label exists on the Kubernetes resource.
28
+ *
29
+ * @param key the label key to check
30
+ * @returns
31
+ */
32
+ HasLabel: (key: string) => boolean;
33
+ /**
34
+ * Check if an annotation exists on the Kubernetes resource.
35
+ *
36
+ * @param key the annotation key to check
37
+ * @returns
38
+ */
39
+ HasAnnotation: (key: string) => boolean;
40
+ /**
41
+ * Create a validation response that allows the request.
42
+ *
43
+ * @returns The validation response.
44
+ */
45
+ Approve: () => ValidateActionResponse;
46
+ /**
47
+ * Create a validation response that denies the request.
48
+ *
49
+ * @param statusMessage Optional status message to return to the user.
50
+ * @param statusCode Optional status code to return to the user.
51
+ * @returns The validation response.
52
+ */
53
+ Deny: (statusMessage?: string, statusCode?: number) => ValidateActionResponse;
54
+ }
55
+ //# sourceMappingURL=validate-request.d.ts.map
@@ -0,0 +1,10 @@
1
+ import { KubernetesObject, WatchEvent } from "kubernetes-fluent-client";
2
+ import { Capability } from "./capability";
3
+ /**
4
+ * Entrypoint for setting up watches for all capabilities
5
+ *
6
+ * @param capabilities The capabilities to load watches for
7
+ */
8
+ export declare function setupWatch(capabilities: Capability[]): void;
9
+ export declare function logEvent(type: WatchEvent, message?: string, obj?: KubernetesObject): void;
10
+ //# sourceMappingURL=watch-processor.d.ts.map