pepr 0.12.2 → 0.13.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.
Files changed (88) hide show
  1. package/CODE_OF_CONDUCT.md +83 -0
  2. package/CONTRIBUTING.md +70 -0
  3. package/README.md +28 -30
  4. package/dist/cli.js +644 -679
  5. package/dist/controller.js +13 -81
  6. package/dist/lib/assets/deploy.d.ts +3 -0
  7. package/dist/lib/assets/deploy.d.ts.map +1 -0
  8. package/dist/lib/assets/index.d.ts +18 -0
  9. package/dist/lib/assets/index.d.ts.map +1 -0
  10. package/dist/lib/assets/loader.d.ts +14 -0
  11. package/dist/lib/assets/loader.d.ts.map +1 -0
  12. package/dist/lib/assets/networking.d.ts +6 -0
  13. package/dist/lib/assets/networking.d.ts.map +1 -0
  14. package/dist/lib/assets/pods.d.ts +8 -0
  15. package/dist/lib/assets/pods.d.ts.map +1 -0
  16. package/dist/lib/assets/rbac.d.ts +11 -0
  17. package/dist/lib/assets/rbac.d.ts.map +1 -0
  18. package/dist/lib/assets/webhooks.d.ts +6 -0
  19. package/dist/lib/assets/webhooks.d.ts.map +1 -0
  20. package/dist/lib/assets/yaml.d.ts +4 -0
  21. package/dist/lib/assets/yaml.d.ts.map +1 -0
  22. package/dist/lib/capability.d.ts +1 -3
  23. package/dist/lib/capability.d.ts.map +1 -1
  24. package/dist/lib/controller.d.ts +45 -10
  25. package/dist/lib/controller.d.ts.map +1 -1
  26. package/dist/lib/filter.d.ts +1 -1
  27. package/dist/lib/filter.d.ts.map +1 -1
  28. package/dist/lib/k8s/index.d.ts +2 -1
  29. package/dist/lib/k8s/index.d.ts.map +1 -1
  30. package/dist/lib/k8s/kinds.d.ts.map +1 -1
  31. package/dist/lib/k8s/types.d.ts +13 -13
  32. package/dist/lib/k8s/types.d.ts.map +1 -1
  33. package/dist/lib/k8s/upstream.d.ts +2 -2
  34. package/dist/lib/k8s/upstream.d.ts.map +1 -1
  35. package/dist/lib/logger.d.ts +8 -54
  36. package/dist/lib/logger.d.ts.map +1 -1
  37. package/dist/lib/metrics.d.ts +11 -4
  38. package/dist/lib/metrics.d.ts.map +1 -1
  39. package/dist/lib/module.d.ts +2 -2
  40. package/dist/lib/module.d.ts.map +1 -1
  41. package/dist/lib/mutate-processor.d.ts +5 -0
  42. package/dist/lib/mutate-processor.d.ts.map +1 -0
  43. package/dist/lib/{request.d.ts → mutate-request.d.ts} +5 -5
  44. package/dist/lib/mutate-request.d.ts.map +1 -0
  45. package/dist/lib/types.d.ts +45 -46
  46. package/dist/lib/types.d.ts.map +1 -1
  47. package/dist/lib/validate-processor.d.ts +4 -0
  48. package/dist/lib/validate-processor.d.ts.map +1 -0
  49. package/dist/lib/validate-request.d.ts +54 -0
  50. package/dist/lib/validate-request.d.ts.map +1 -0
  51. package/dist/lib.d.ts +3 -2
  52. package/dist/lib.d.ts.map +1 -1
  53. package/dist/lib.js +502 -302
  54. package/dist/lib.js.map +4 -4
  55. package/package.json +15 -12
  56. package/src/cli.ts +2 -11
  57. package/src/lib/assets/deploy.ts +179 -0
  58. package/src/lib/assets/index.ts +46 -0
  59. package/src/lib/assets/loader.ts +49 -0
  60. package/src/lib/assets/networking.ts +58 -0
  61. package/src/lib/assets/pods.ts +148 -0
  62. package/src/lib/assets/rbac.ts +57 -0
  63. package/src/lib/assets/webhooks.ts +139 -0
  64. package/src/lib/assets/yaml.ts +75 -0
  65. package/src/lib/capability.ts +54 -44
  66. package/src/lib/controller.ts +171 -89
  67. package/src/lib/fetch.ts +1 -1
  68. package/src/lib/filter.ts +1 -3
  69. package/src/lib/k8s/index.ts +4 -1
  70. package/src/lib/k8s/kinds.ts +40 -0
  71. package/src/lib/k8s/types.ts +16 -14
  72. package/src/lib/k8s/upstream.ts +5 -1
  73. package/src/lib/logger.ts +14 -125
  74. package/src/lib/metrics.ts +67 -23
  75. package/src/lib/module.ts +13 -11
  76. package/src/lib/{processor.ts → mutate-processor.ts} +37 -28
  77. package/src/lib/{request.ts → mutate-request.ts} +4 -4
  78. package/src/lib/types.ts +51 -51
  79. package/src/lib/validate-processor.ts +68 -0
  80. package/src/lib/validate-request.ts +94 -0
  81. package/src/lib.ts +4 -2
  82. package/src/runtime/controller.ts +1 -1
  83. package/dist/lib/k8s/webhook.d.ts +0 -37
  84. package/dist/lib/k8s/webhook.d.ts.map +0 -1
  85. package/dist/lib/processor.d.ts +0 -5
  86. package/dist/lib/processor.d.ts.map +0 -1
  87. package/dist/lib/request.d.ts.map +0 -1
  88. package/src/lib/k8s/webhook.ts +0 -643
@@ -4,7 +4,7 @@ import { DeepPartial } from "./types";
4
4
  * The RequestWrapper class provides methods to modify Kubernetes objects in the context
5
5
  * of a mutating webhook request.
6
6
  */
7
- export declare class PeprRequest<T extends KubernetesObject> {
7
+ export declare class PeprMutateRequest<T extends KubernetesObject> {
8
8
  private _input;
9
9
  Raw: T;
10
10
  get PermitSideEffects(): boolean;
@@ -24,7 +24,7 @@ export declare class PeprRequest<T extends KubernetesObject> {
24
24
  */
25
25
  get Request(): Request<T>;
26
26
  /**
27
- * Creates a new instance of the Action class.
27
+ * Creates a new instance of the action class.
28
28
  * @param input - The request object containing the Kubernetes resource to modify.
29
29
  */
30
30
  constructor(_input: Request<T>);
@@ -38,14 +38,14 @@ export declare class PeprRequest<T extends KubernetesObject> {
38
38
  * Updates a label on the Kubernetes resource.
39
39
  * @param key - The key of the label to update.
40
40
  * @param value - The value of the label.
41
- * @returns The current Action instance for method chaining.
41
+ * @returns The current action instance for method chaining.
42
42
  */
43
43
  SetLabel(key: string, value: string): this;
44
44
  /**
45
45
  * Updates an annotation on the Kubernetes resource.
46
46
  * @param key - The key of the annotation to update.
47
47
  * @param value - The value of the annotation.
48
- * @returns The current Action instance for method chaining.
48
+ * @returns The current action instance for method chaining.
49
49
  */
50
50
  SetAnnotation(key: string, value: string): this;
51
51
  /**
@@ -75,4 +75,4 @@ export declare class PeprRequest<T extends KubernetesObject> {
75
75
  */
76
76
  HasAnnotation(key: string): boolean;
77
77
  }
78
- //# sourceMappingURL=request.d.ts.map
78
+ //# sourceMappingURL=mutate-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutate-request.d.ts","sourceRoot":"","sources":["../../src/lib/mutate-request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAa,OAAO,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;GAGG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,gBAAgB;IAmC3C,OAAO,CAAC,MAAM;IAlCnB,GAAG,EAAE,CAAC,CAAC;IAEd,IAAI,iBAAiB,YAEpB;IAED;;;OAGG;IACH,IAAI,QAAQ,wBAEX;IAED;;;OAGG;IACH,IAAI,WAAW,kBAEd;IAED;;;OAGG;IACH,IAAI,OAAO,eAEV;IAED;;;OAGG;gBACiB,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IActC;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;IAIzB;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAUnC;;;;;OAKG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAUxC;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM;IAQvB;;;;OAIG;IACH,gBAAgB,CAAC,GAAG,EAAE,MAAM;IAQ5B;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM;IAIpB;;;;;OAKG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM;CAG1B"}
@@ -1,17 +1,10 @@
1
1
  import { GroupVersionKind, KubernetesObject, WebhookIgnore } from "./k8s/types";
2
- import { PeprRequest } from "./request";
2
+ import { PeprMutateRequest } from "./mutate-request";
3
+ import { PeprValidateRequest } from "./validate-request";
3
4
  export type PackageJSON = {
4
5
  description: string;
5
6
  pepr: ModuleConfig;
6
7
  };
7
- /**
8
- * The behavior of this module when an error occurs.
9
- */
10
- export declare enum ErrorBehavior {
11
- ignore = "ignore",
12
- audit = "audit",
13
- reject = "reject"
14
- }
15
8
  /**
16
9
  * The phase of the Kubernetes admission webhook that the capability is registered for.
17
10
  *
@@ -28,7 +21,7 @@ export type DeepPartial<T> = {
28
21
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
29
22
  };
30
23
  /**
31
- * The type of Kubernetes mutating webhook event that the capability action is registered for.
24
+ * The type of Kubernetes mutating webhook event that the action is registered for.
32
25
  */
33
26
  export declare enum Event {
34
27
  Create = "CREATE",
@@ -51,13 +44,6 @@ export interface CapabilityCfg {
51
44
  * This does not supersede the `alwaysIgnore` global configuration.
52
45
  */
53
46
  namespaces?: string[];
54
- /**
55
- * FUTURE USE.
56
- *
57
- * Declare if this capability should be used for mutation or validation. Currently this is not used
58
- * and everything is considered a mutation.
59
- */
60
- mutateOrValidate?: HookPhase;
61
47
  }
62
48
  export type ModuleSigning = {
63
49
  /**
@@ -86,7 +72,7 @@ export type ModuleConfig = {
86
72
  /** A description of the Pepr module and what it does. */
87
73
  description?: string;
88
74
  /** Reject K8s resource AdmissionRequests on error. */
89
- onError: ErrorBehavior | string;
75
+ onError?: string;
90
76
  /** Configure global exclusions that will never be processed by Pepr. */
91
77
  alwaysIgnore: WebhookIgnore;
92
78
  /**
@@ -99,17 +85,19 @@ export type ModuleConfig = {
99
85
  };
100
86
  export type GenericClass = abstract new () => any;
101
87
  export type WhenSelector<T extends GenericClass> = {
102
- /** Register a capability action to be executed when a Kubernetes resource is created or updated. */
88
+ /** Register an action to be executed when a Kubernetes resource is created or updated. */
103
89
  IsCreatedOrUpdated: () => BindingAll<T>;
104
- /** Register a capability action to be executed when a Kubernetes resource is created. */
90
+ /** Register an action to be executed when a Kubernetes resource is created. */
105
91
  IsCreated: () => BindingAll<T>;
106
- /** Register a capability action to be executed when a Kubernetes resource is updated. */
92
+ /** Register ann action to be executed when a Kubernetes resource is updated. */
107
93
  IsUpdated: () => BindingAll<T>;
108
- /** Register a capability action to be executed when a Kubernetes resource is deleted. */
94
+ /** Register an action to be executed when a Kubernetes resource is deleted. */
109
95
  IsDeleted: () => BindingAll<T>;
110
96
  };
111
97
  export type Binding = {
112
98
  event: Event;
99
+ isMutate?: boolean;
100
+ isValidate?: boolean;
113
101
  readonly kind: GroupVersionKind;
114
102
  readonly filters: {
115
103
  name: string;
@@ -117,11 +105,12 @@ export type Binding = {
117
105
  labels: Record<string, string>;
118
106
  annotations: Record<string, string>;
119
107
  };
120
- readonly callback: CapabilityAction<GenericClass, InstanceType<GenericClass>>;
108
+ readonly mutateCallback?: MutateAction<GenericClass, InstanceType<GenericClass>>;
109
+ readonly validateCallback?: ValidateAction<GenericClass, InstanceType<GenericClass>>;
121
110
  };
122
- export type BindingFilter<T extends GenericClass> = BindToActionOrSet<T> & {
111
+ export type BindingFilter<T extends GenericClass> = CommonActionChain<T> & {
123
112
  /**
124
- * Only apply the capability action if the resource has the specified label. If no value is specified, the label must exist.
113
+ * Only apply the action if the resource has the specified label. If no value is specified, the label must exist.
125
114
  * Note multiple calls to this method will result in an AND condition. e.g.
126
115
  *
127
116
  * ```ts
@@ -129,17 +118,17 @@ export type BindingFilter<T extends GenericClass> = BindToActionOrSet<T> & {
129
118
  * .IsCreated()
130
119
  * .WithLabel("foo", "bar")
131
120
  * .WithLabel("baz", "qux")
132
- * .Then(...)
121
+ * .Mutate(...)
133
122
  * ```
134
123
  *
135
- * Will only apply the capability action if the resource has both the `foo=bar` and `baz=qux` labels.
124
+ * Will only apply the action if the resource has both the `foo=bar` and `baz=qux` labels.
136
125
  *
137
126
  * @param key
138
127
  * @param value
139
128
  */
140
129
  WithLabel: (key: string, value?: string) => BindingFilter<T>;
141
130
  /**
142
- * Only apply the capability action if the resource has the specified annotation. If no value is specified, the annotation must exist.
131
+ * Only apply the action if the resource has the specified annotation. If no value is specified, the annotation must exist.
143
132
  * Note multiple calls to this method will result in an AND condition. e.g.
144
133
  *
145
134
  * ```ts
@@ -147,10 +136,10 @@ export type BindingFilter<T extends GenericClass> = BindToActionOrSet<T> & {
147
136
  * .IsCreated()
148
137
  * .WithAnnotation("foo", "bar")
149
138
  * .WithAnnotation("baz", "qux")
150
- * .Then(...)
139
+ * .Mutate(...)
151
140
  * ```
152
141
  *
153
- * Will only apply the capability action if the resource has both the `foo=bar` and `baz=qux` annotations.
142
+ * Will only apply the action if the resource has both the `foo=bar` and `baz=qux` annotations.
154
143
  *
155
144
  * @param key
156
145
  * @param value
@@ -158,38 +147,48 @@ export type BindingFilter<T extends GenericClass> = BindToActionOrSet<T> & {
158
147
  WithAnnotation: (key: string, value?: string) => BindingFilter<T>;
159
148
  };
160
149
  export type BindingWithName<T extends GenericClass> = BindingFilter<T> & {
161
- /** Only apply the capability action if the resource name matches the specified name. */
150
+ /** Only apply the action if the resource name matches the specified name. */
162
151
  WithName: (name: string) => BindingFilter<T>;
163
152
  };
164
153
  export type BindingAll<T extends GenericClass> = BindingWithName<T> & {
165
- /** Only apply the capability action if the resource is in one of the specified namespaces.*/
154
+ /** Only apply the action if the resource is in one of the specified namespaces.*/
166
155
  InNamespace: (...namespaces: string[]) => BindingWithName<T>;
167
156
  };
168
- export type BindToAction<T extends GenericClass> = {
157
+ export type CommonActionChain<T extends GenericClass> = MutateActionChain<T> & {
169
158
  /**
170
- * Create a new capability action with the specified callback function and previously specified
159
+ * Create a new MUTATE action with the specified callback function and previously specified
171
160
  * filters.
172
- * @param action The capability action to be executed when the Kubernetes resource is processed by the AdmissionController.
161
+ * @param action The action to be executed when the Kubernetes resource is processed by the AdmissionController.
173
162
  */
174
- Then: (action: CapabilityAction<T, InstanceType<T>>) => BindToAction<T>;
163
+ Mutate: (action: MutateAction<T, InstanceType<T>>) => MutateActionChain<T>;
175
164
  };
176
- export type BindToActionOrSet<T extends GenericClass> = BindToAction<T> & {
165
+ export type MutateActionChain<T extends GenericClass> = {
177
166
  /**
178
- * Merge the specified updates into the resource, this can only be used once per binding.
179
- * Note this is just a convenience method for `request.Merge(values)`.
180
- *
181
- * Example change the `minReadySeconds` to 3 of a deployment when it is created:
167
+ * Create a new VALIDATE action with the specified callback function and previously specified
168
+ * filters. Return the `request.Approve()` or `Request.Deny()` methods to approve or deny the request:
182
169
  *
170
+ * @example
183
171
  * ```ts
184
172
  * When(a.Deployment)
185
173
  * .IsCreated()
186
- * .ThenSet({ spec: { minReadySeconds: 3 } });
174
+ * .Validate(request => {
175
+ * if (request.HasLabel("foo")) {
176
+ * return request.Approve();
177
+ * }
178
+ *
179
+ * return request.Deny("Deployment must have label foo");
180
+ * });
187
181
  * ```
188
182
  *
189
- * @param merge
190
- * @returns
183
+ * @param action The action to be executed when the Kubernetes resource is processed by the AdmissionController.
191
184
  */
192
- ThenSet: (val: DeepPartial<InstanceType<T>>) => BindToAction<T>;
185
+ Validate: (action: ValidateAction<T, InstanceType<T>>) => void;
186
+ };
187
+ export type MutateAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (req: PeprMutateRequest<K>) => Promise<void> | void | Promise<PeprMutateRequest<K>> | PeprMutateRequest<K>;
188
+ export type ValidateAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (req: PeprValidateRequest<K>) => Promise<ValidateResponse> | ValidateResponse;
189
+ export type ValidateResponse = {
190
+ allowed: boolean;
191
+ statusCode?: number;
192
+ statusMessage?: string;
193
193
  };
194
- export type CapabilityAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (req: PeprRequest<K>) => Promise<void> | void | Promise<PeprRequest<K>> | PeprRequest<K>;
195
194
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AA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K,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAC5E,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,YAAY,IAAI;IACtD;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAChE,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,IAAI,CAC/F,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,KACtB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAEjF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,IAAI,CACjG,GAAG,EAAE,mBAAmB,CAAC,CAAC,CAAC,KACxB,OAAO,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAAC;AAElD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Capability } from "./capability";
2
+ import { Request, ValidateResponse } from "./k8s/types";
3
+ export declare function validateProcessor(capabilities: Capability[], req: Request, reqMetadata: Record<string, string>): Promise<ValidateResponse>;
4
+ //# sourceMappingURL=validate-processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-processor.d.ts","sourceRoot":"","sources":["../../src/lib/validate-processor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAIxD,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,UAAU,EAAE,EAC1B,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,gBAAgB,CAAC,CAsD3B"}
@@ -0,0 +1,54 @@
1
+ import { KubernetesObject, Request } from "./k8s/types";
2
+ import { ValidateResponse } from "./types";
3
+ /**
4
+ * The RequestWrapper class provides methods to modify Kubernetes objects in the context
5
+ * of a mutating webhook request.
6
+ */
7
+ export declare class PeprValidateRequest<T extends KubernetesObject> {
8
+ protected _input: Request<T>;
9
+ Raw: T;
10
+ /**
11
+ * Provides access to the old resource in the request if available.
12
+ * @returns The old Kubernetes resource object or null if not available.
13
+ */
14
+ get OldResource(): T | undefined;
15
+ /**
16
+ * Provides access to the request object.
17
+ * @returns The request object containing the Kubernetes resource.
18
+ */
19
+ get Request(): Request<T>;
20
+ /**
21
+ * Creates a new instance of the Action class.
22
+ * @param input - The request object containing the Kubernetes resource to modify.
23
+ */
24
+ constructor(_input: Request<T>);
25
+ /**
26
+ * Check if a label exists on the Kubernetes resource.
27
+ *
28
+ * @param key the label key to check
29
+ * @returns
30
+ */
31
+ HasLabel(key: string): boolean;
32
+ /**
33
+ * Check if an annotation exists on the Kubernetes resource.
34
+ *
35
+ * @param key the annotation key to check
36
+ * @returns
37
+ */
38
+ HasAnnotation(key: string): boolean;
39
+ /**
40
+ * Create a validation response that allows the request.
41
+ *
42
+ * @returns The validation response.
43
+ */
44
+ Approve(): ValidateResponse;
45
+ /**
46
+ * Create a validation response that denies the request.
47
+ *
48
+ * @param statusMessage Optional status message to return to the user.
49
+ * @param statusCode Optional status code to return to the user.
50
+ * @returns The validation response.
51
+ */
52
+ Deny(statusMessage?: string, statusCode?: number): ValidateResponse;
53
+ }
54
+ //# sourceMappingURL=validate-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-request.d.ts","sourceRoot":"","sources":["../../src/lib/validate-request.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAa,OAAO,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C;;;GAGG;AACH,qBAAa,mBAAmB,CAAC,CAAC,SAAS,gBAAgB;IAuB7C,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAtBjC,GAAG,EAAE,CAAC,CAAC;IAEd;;;OAGG;IACH,IAAI,WAAW,kBAEd;IAED;;;OAGG;IACH,IAAI,OAAO,eAEV;IAED;;;OAGG;gBACmB,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAcxC;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM;IAIpB;;;;;OAKG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM;IAIzB;;;;OAIG;IACH,OAAO,IAAI,gBAAgB;IAM3B;;;;;;OAMG;IACH,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,gBAAgB;CAOpE"}
package/dist/lib.d.ts CHANGED
@@ -6,11 +6,12 @@ import { fetch, fetchRaw } from "./lib/fetch";
6
6
  import { RegisterKind, a } from "./lib/k8s/index";
7
7
  import Log from "./lib/logger";
8
8
  import { PeprModule } from "./lib/module";
9
- import { PeprRequest } from "./lib/request";
9
+ import { PeprMutateRequest } from "./lib/mutate-request";
10
+ import { PeprValidateRequest } from "./lib/validate-request";
10
11
  import * as PeprUtils from "./lib/utils";
11
12
  import type * as K8sTypes from "@kubernetes/client-node";
12
13
  import type * as RTypes from "ramda";
13
14
  export { a,
14
15
  /** PeprModule is used to setup a complete Pepr Module: `new PeprModule(cfg, {...capabilities})` */
15
- PeprModule, PeprRequest, PeprUtils, RegisterKind, Capability, Log, R, fetch, fetchRaw, fetchStatus, k8s, RTypes, K8sTypes, };
16
+ PeprModule, PeprMutateRequest, PeprValidateRequest, PeprUtils, RegisterKind, Capability, Log, R, fetch, fetchRaw, fetchStatus, k8s, RTypes, K8sTypes, };
16
17
  //# sourceMappingURL=lib.d.ts.map
package/dist/lib.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,KAAK,MAAM,MAAM,OAAO,CAAC;AAErC,OAAO,EACL,CAAC;AACD,mGAAmG;AACnG,UAAU,EACV,WAAW,EACX,SAAS,EACT,YAAY,EACZ,UAAU,EACV,GAAG,EACH,CAAC,EACD,KAAK,EACL,QAAQ,EACR,WAAW,EACX,GAAG,EAGH,MAAM,EACN,QAAQ,GACT,CAAC"}
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC/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