pepr 0.2.9 → 0.3.0-rc0

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 (82) hide show
  1. package/README.md +10 -3
  2. package/dist/fixtures/data/cm1.json +75 -0
  3. package/dist/fixtures/data/deployment1.json +170 -0
  4. package/dist/fixtures/data/ns1.json +72 -0
  5. package/dist/fixtures/data/pod1.json +271 -0
  6. package/dist/fixtures/data/pod2.json +257 -0
  7. package/dist/fixtures/data/svc1.json +100 -0
  8. package/dist/fixtures/loader.js +60 -0
  9. package/dist/package.json +23 -41
  10. package/dist/src/cli/build.js +3 -1
  11. package/dist/src/cli/dev.js +31 -19
  12. package/dist/src/cli/index.js +1 -0
  13. package/dist/src/cli/init/index.js +3 -1
  14. package/dist/src/cli/init/templates.js +3 -2
  15. package/dist/src/cli/init/utils.js +1 -1
  16. package/dist/src/cli/init/utils.test.js +29 -0
  17. package/dist/src/cli/init/walkthrough.js +1 -1
  18. package/dist/src/cli/init/walkthrough.test.js +21 -0
  19. package/dist/src/cli/run.js +17 -17
  20. package/dist/src/cli/update.js +3 -1
  21. package/dist/src/lib/capability.js +1 -1
  22. package/dist/src/lib/controller.js +9 -1
  23. package/dist/src/lib/fetch.js +39 -6
  24. package/dist/src/lib/fetch.test.js +98 -0
  25. package/dist/src/lib/filter.test.js +208 -0
  26. package/dist/src/lib/k8s/kinds.test.js +296 -0
  27. package/dist/src/lib/k8s/webhook.js +22 -22
  28. package/dist/src/lib/logger.test.js +64 -0
  29. package/dist/src/lib/processor.js +4 -1
  30. package/{dist/index.d.ts → index.ts} +21 -3
  31. package/package.json +23 -41
  32. package/src/lib/capability.ts +158 -0
  33. package/src/lib/controller.ts +127 -0
  34. package/src/lib/fetch.test.ts +115 -0
  35. package/src/lib/fetch.ts +75 -0
  36. package/src/lib/filter.test.ts +231 -0
  37. package/src/lib/filter.ts +87 -0
  38. package/{dist/src/lib/k8s/index.d.ts → src/lib/k8s/index.ts} +6 -0
  39. package/src/lib/k8s/kinds.test.ts +333 -0
  40. package/src/lib/k8s/kinds.ts +489 -0
  41. package/src/lib/k8s/tls.ts +90 -0
  42. package/src/lib/k8s/types.ts +183 -0
  43. package/src/lib/k8s/upstream.ts +49 -0
  44. package/src/lib/k8s/webhook.ts +547 -0
  45. package/src/lib/logger.test.ts +80 -0
  46. package/src/lib/logger.ts +136 -0
  47. package/src/lib/module.ts +63 -0
  48. package/src/lib/processor.ts +98 -0
  49. package/src/lib/request.ts +140 -0
  50. package/src/lib/types.ts +211 -0
  51. package/dist/cli.d.ts +0 -2
  52. package/dist/cli.js +0 -4
  53. package/dist/run.d.ts +0 -2
  54. package/dist/run.js +0 -4
  55. package/dist/src/cli/banner.d.ts +0 -1
  56. package/dist/src/cli/build.d.ts +0 -7
  57. package/dist/src/cli/capability.d.ts +0 -2
  58. package/dist/src/cli/deploy.d.ts +0 -2
  59. package/dist/src/cli/dev.d.ts +0 -2
  60. package/dist/src/cli/index.d.ts +0 -1
  61. package/dist/src/cli/init/index.d.ts +0 -2
  62. package/dist/src/cli/init/templates.d.ts +0 -94
  63. package/dist/src/cli/init/utils.d.ts +0 -20
  64. package/dist/src/cli/init/walkthrough.d.ts +0 -7
  65. package/dist/src/cli/root.d.ts +0 -4
  66. package/dist/src/cli/run.d.ts +0 -1
  67. package/dist/src/cli/test.d.ts +0 -2
  68. package/dist/src/cli/update.d.ts +0 -2
  69. package/dist/src/lib/capability.d.ts +0 -28
  70. package/dist/src/lib/controller.d.ts +0 -17
  71. package/dist/src/lib/fetch.d.ts +0 -23
  72. package/dist/src/lib/filter.d.ts +0 -10
  73. package/dist/src/lib/k8s/kinds.d.ts +0 -11
  74. package/dist/src/lib/k8s/tls.d.ts +0 -17
  75. package/dist/src/lib/k8s/types.d.ts +0 -147
  76. package/dist/src/lib/k8s/upstream.d.ts +0 -3
  77. package/dist/src/lib/k8s/webhook.d.ts +0 -34
  78. package/dist/src/lib/logger.d.ts +0 -55
  79. package/dist/src/lib/module.d.ts +0 -32
  80. package/dist/src/lib/processor.d.ts +0 -4
  81. package/dist/src/lib/request.d.ts +0 -77
  82. package/dist/src/lib/types.d.ts +0 -187
@@ -1,11 +0,0 @@
1
- import { GenericClass } from "../types";
2
- import { GroupVersionKind } from "./types";
3
- export declare const gvkMap: Record<string, GroupVersionKind>;
4
- export declare function modelToGroupVersionKind(key: string): GroupVersionKind;
5
- /**
6
- * Registers a new model and GroupVersionKind with Pepr for use with `When(a.<Kind>)`
7
- *
8
- * @param model Used to match the GroupVersionKind and define the type-data for the request
9
- * @param groupVersionKind Contains the match parameters to determine the request should be handled
10
- */
11
- export declare const RegisterKind: (model: GenericClass, groupVersionKind: GroupVersionKind) => void;
@@ -1,17 +0,0 @@
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;
@@ -1,147 +0,0 @@
1
- import { V1ListMeta, V1ObjectMeta } from "@kubernetes/client-node";
2
- export declare enum Operation {
3
- CREATE = "CREATE",
4
- UPDATE = "UPDATE",
5
- DELETE = "DELETE",
6
- CONNECT = "CONNECT"
7
- }
8
- export interface KubernetesObject {
9
- apiVersion?: string;
10
- kind?: string;
11
- metadata?: V1ObjectMeta;
12
- }
13
- export interface KubernetesListObject<T extends KubernetesObject> {
14
- apiVersion?: string;
15
- kind?: string;
16
- metadata?: V1ListMeta;
17
- items: T[];
18
- }
19
- /**
20
- * GenericKind is a generic Kubernetes object that can be used to represent any Kubernetes object
21
- * that is not explicitly supported by Pepr. This can be used on its own or as a base class for
22
- * other types. See the examples in `HelloPepr.ts` for more information.
23
- */
24
- export declare class GenericKind {
25
- apiVersion?: string;
26
- kind?: string;
27
- metadata?: V1ObjectMeta;
28
- [key: string]: any;
29
- }
30
- /**
31
- * GroupVersionKind unambiguously identifies a kind. It doesn't anonymously include GroupVersion
32
- * to avoid automatic coercion. It doesn't use a GroupVersion to avoid custom marshalling
33
- **/
34
- export interface GroupVersionKind {
35
- /** The K8s resource kind, e..g "Pod". */
36
- readonly kind: string;
37
- readonly group: string;
38
- readonly version?: string;
39
- }
40
- /**
41
- * GroupVersionResource unambiguously identifies a resource. It doesn't anonymously include GroupVersion
42
- * to avoid automatic coercion. It doesn't use a GroupVersion to avoid custom marshalling
43
- */
44
- export interface GroupVersionResource {
45
- readonly group: string;
46
- readonly version: string;
47
- readonly resource: string;
48
- }
49
- /**
50
- * A Kubernetes admission request to be processed by a capability.
51
- */
52
- export interface Request<T = KubernetesObject> {
53
- /** UID is an identifier for the individual request/response. */
54
- readonly uid: string;
55
- /** Kind is the fully-qualified type of object being submitted (for example, v1.Pod or autoscaling.v1.Scale) */
56
- readonly kind: GroupVersionKind;
57
- /** Resource is the fully-qualified resource being requested (for example, v1.pods) */
58
- readonly resource: GroupVersionResource;
59
- /** SubResource is the sub-resource being requested, if any (for example, "status" or "scale") */
60
- readonly subResource?: string;
61
- /** RequestKind is the fully-qualified type of the original API request (for example, v1.Pod or autoscaling.v1.Scale). */
62
- readonly requestKind?: GroupVersionKind;
63
- /** RequestResource is the fully-qualified resource of the original API request (for example, v1.pods). */
64
- readonly requestResource?: GroupVersionResource;
65
- /** RequestSubResource is the sub-resource of the original API request, if any (for example, "status" or "scale"). */
66
- readonly requestSubResource?: string;
67
- /**
68
- * Name is the name of the object as presented in the request. On a CREATE operation, the client may omit name and
69
- * rely on the server to generate the name. If that is the case, this method will return the empty string.
70
- */
71
- readonly name: string;
72
- /** Namespace is the namespace associated with the request (if any). */
73
- readonly namespace?: string;
74
- /**
75
- * Operation is the operation being performed. This may be different than the operation
76
- * requested. e.g. a patch can result in either a CREATE or UPDATE Operation.
77
- */
78
- readonly operation: Operation;
79
- /** UserInfo is information about the requesting user */
80
- readonly userInfo: {
81
- /** The name that uniquely identifies this user among all active users. */
82
- username?: string;
83
- /**
84
- * A unique value that identifies this user across time. If this user is deleted
85
- * and another user by the same name is added, they will have different UIDs.
86
- */
87
- uid?: string;
88
- /** The names of groups this user is a part of. */
89
- groups?: string[];
90
- /** Any additional information provided by the authenticator. */
91
- extra?: {
92
- [key: string]: string[];
93
- };
94
- };
95
- /** Object is the object from the incoming request prior to default values being applied */
96
- readonly object: T;
97
- /** OldObject is the existing object. Only populated for UPDATE requests. */
98
- readonly oldObject?: T;
99
- /** DryRun indicates that modifications will definitely not be persisted for this request. Defaults to false. */
100
- readonly dryRun?: boolean;
101
- /**
102
- * Options contains the options for the operation being performed.
103
- * e.g. `meta.k8s.io/v1.DeleteOptions` or `meta.k8s.io/v1.CreateOptions`. This may be
104
- * different than the options the caller provided. e.g. for a patch request the performed
105
- * Operation might be a CREATE, in which case the Options will a
106
- * `meta.k8s.io/v1.CreateOptions` even though the caller provided `meta.k8s.io/v1.PatchOptions`.
107
- */
108
- readonly options?: any;
109
- }
110
- export interface Response {
111
- /** UID is an identifier for the individual request/response. This must be copied over from the corresponding AdmissionRequest. */
112
- uid: string;
113
- /** Allowed indicates whether or not the admission request was permitted. */
114
- allowed: boolean;
115
- /** Result contains extra details into why an admission request was denied. This field IS NOT consulted in any way if "Allowed" is "true". */
116
- result?: string;
117
- /** The patch body. Currently we only support "JSONPatch" which implements RFC 6902. */
118
- patch?: string;
119
- /** The type of Patch. Currently we only allow "JSONPatch". */
120
- patchType?: "JSONPatch";
121
- /** AuditAnnotations is an unstructured key value map set by remote admission controller (e.g. error=image-blacklisted). */
122
- auditAnnotations?: {
123
- [key: string]: string;
124
- };
125
- /** warnings is a list of warning messages to return to the requesting API client. */
126
- warnings?: string[];
127
- }
128
- export type WebhookIgnore = {
129
- /**
130
- * List of Kubernetes namespaces to always ignore.
131
- * Any resources in these namespaces will be ignored by Pepr.
132
- *
133
- * Note: `kube-system` and `pepr-system` are always ignored.
134
- */
135
- namespaces?: string[];
136
- /**
137
- * List of Kubernetes labels to always ignore.
138
- * Any resources with these labels will be ignored by Pepr.
139
- *
140
- * The example below will ignore any resources with the label `my-label=ulta-secret`:
141
- * ```
142
- * alwaysIgnore:
143
- * labels: [{ "my-label": "ultra-secret" }]
144
- * ```
145
- */
146
- labels?: Record<string, string>[];
147
- };
@@ -1,3 +0,0 @@
1
- /** a is a colleciton of K8s types to be used within a CapabilityAction: `When(a.Configmap)` */
2
- export { V1APIService as APIService, V1CertificateSigningRequest as CertificateSigningRequest, V1ConfigMap as ConfigMap, V1ControllerRevision as ControllerRevision, V1CronJob as CronJob, V1CSIDriver as CSIDriver, V1CSIStorageCapacity as CSIStorageCapacity, V1CustomResourceDefinition as CustomResourceDefinition, V1DaemonSet as DaemonSet, V1Deployment as Deployment, V1EndpointSlice as EndpointSlice, V1HorizontalPodAutoscaler as HorizontalPodAutoscaler, V1Ingress as Ingress, V1IngressClass as IngressClass, V1Job as Job, V1LimitRange as LimitRange, V1LocalSubjectAccessReview as LocalSubjectAccessReview, V1MutatingWebhookConfiguration as MutatingWebhookConfiguration, V1Namespace as Namespace, V1NetworkPolicy as NetworkPolicy, V1Node as Node, V1PersistentVolume as PersistentVolume, V1PersistentVolumeClaim as PersistentVolumeClaim, V1Pod as Pod, V1PodDisruptionBudget as PodDisruptionBudget, V1PodTemplate as PodTemplate, V1ReplicaSet as ReplicaSet, V1ReplicationController as ReplicationController, V1ResourceQuota as ResourceQuota, V1RuntimeClass as RuntimeClass, V1Secret as Secret, V1SelfSubjectAccessReview as SelfSubjectAccessReview, V1SelfSubjectRulesReview as SelfSubjectRulesReview, V1Service as Service, V1ServiceAccount as ServiceAccount, V1StatefulSet as StatefulSet, V1StorageClass as StorageClass, V1SubjectAccessReview as SubjectAccessReview, V1TokenReview as TokenReview, V1ValidatingWebhookConfiguration as ValidatingWebhookConfiguration, V1VolumeAttachment as VolumeAttachment, } from "@kubernetes/client-node/dist";
3
- export { GenericKind } from "./types";
@@ -1,34 +0,0 @@
1
- /// <reference types="node" />
2
- import { V1ClusterRole, V1ClusterRoleBinding, V1Deployment, V1MutatingWebhookConfiguration, V1Namespace, V1NetworkPolicy, V1Secret, V1Service, V1ServiceAccount } from "@kubernetes/client-node";
3
- import { ModuleConfig } from "../types";
4
- import { TLSOut } from "./tls";
5
- export declare class Webhook {
6
- private readonly config;
7
- private readonly host?;
8
- private name;
9
- private _tls;
10
- image: string;
11
- get tls(): TLSOut;
12
- constructor(config: ModuleConfig, host?: string);
13
- /** Generate the pepr-system namespace */
14
- namespace(): V1Namespace;
15
- /**
16
- * Grants the controller access to cluster resources beyond the mutating webhook.
17
- *
18
- * @todo: should dynamically generate this based on resources used by the module. will also need to explore how this should work for multiple modules.
19
- * @returns
20
- */
21
- clusterRole(): V1ClusterRole;
22
- clusterRoleBinding(): V1ClusterRoleBinding;
23
- serviceAccount(): V1ServiceAccount;
24
- tlsSecret(): V1Secret;
25
- mutatingWebhook(): V1MutatingWebhookConfiguration;
26
- deployment(hash: string): V1Deployment;
27
- /** Only permit the kube-system ns ingress access to the controller */
28
- networkPolicy(): V1NetworkPolicy;
29
- service(): V1Service;
30
- moduleSecret(data: Buffer, hash: string): V1Secret;
31
- zarfYaml(path: string): string;
32
- allYaml(code: Buffer): string;
33
- deploy(code: Buffer): Promise<void>;
34
- }
@@ -1,55 +0,0 @@
1
- /**
2
- * Enumeration representing different logging levels.
3
- */
4
- export declare enum LogLevel {
5
- debug = 0,
6
- info = 1,
7
- warn = 2,
8
- error = 3
9
- }
10
- /**
11
- * Simple logger class that logs messages at different log levels.
12
- */
13
- export declare class Logger {
14
- private _logLevel;
15
- /**
16
- * Create a new logger instance.
17
- * @param logLevel - The minimum log level to log messages for.
18
- */
19
- constructor(logLevel: LogLevel);
20
- /**
21
- * Change the log level of the logger.
22
- * @param logLevel - The log level to log the message at.
23
- */
24
- SetLogLevel(logLevel: string): void;
25
- /**
26
- * Log a debug message.
27
- * @param message - The message to log.
28
- */
29
- debug<T>(message: T, prefix?: string): void;
30
- /**
31
- * Log an info message.
32
- * @param message - The message to log.
33
- */
34
- info<T>(message: T, prefix?: string): void;
35
- /**
36
- * Log a warning message.
37
- * @param message - The message to log.
38
- */
39
- warn<T>(message: T, prefix?: string): void;
40
- /**
41
- * Log an error message.
42
- * @param message - The message to log.
43
- */
44
- error<T>(message: T, prefix?: string): void;
45
- /**
46
- * Log a message at the specified log level.
47
- * @param logLevel - The log level of the message.
48
- * @param message - The message to log.
49
- */
50
- private log;
51
- private colorize;
52
- }
53
- /** Log is an instance of Logger used to generate log entries. */
54
- declare const Log: Logger;
55
- export default Log;
@@ -1,32 +0,0 @@
1
- import { Capability } from "./capability";
2
- import { Request, Response } from "./k8s/types";
3
- import { ModuleConfig } from "./types";
4
- export type PackageJSON = {
5
- description: string;
6
- pepr: ModuleConfig;
7
- };
8
- export type PeprModuleOptions = {
9
- deferStart?: boolean;
10
- /** A user-defined callback to pre-process or intercept a Pepr request from K8s immediately before it is processed */
11
- beforeHook?: (req: Request) => void;
12
- /** A user-defined callback to post-process or intercept a Pepr response just before it is returned to K8s */
13
- afterHook?: (res: Response) => void;
14
- };
15
- export declare class PeprModule {
16
- private _controller;
17
- /**
18
- * Create a new Pepr runtime
19
- *
20
- * @param config The configuration for the Pepr runtime
21
- * @param capabilities The capabilities to be loaded into the Pepr runtime
22
- * @param _deferStart (optional) If set to `true`, the Pepr runtime will not be started automatically. This can be used to start the Pepr runtime manually with `start()`.
23
- */
24
- constructor({ description, pepr }: PackageJSON, capabilities?: Capability[], opts?: PeprModuleOptions);
25
- /**
26
- * Start the Pepr runtime manually.
27
- * 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.
28
- *
29
- * @param port
30
- */
31
- start(port?: number): void;
32
- }
@@ -1,4 +0,0 @@
1
- import { Capability } from "./capability";
2
- import { Request, Response } from "./k8s/types";
3
- import { ModuleConfig } from "./types";
4
- export declare function processor(config: ModuleConfig, capabilities: Capability[], req: Request): Promise<Response>;
@@ -1,77 +0,0 @@
1
- import { KubernetesObject, Request } from "./k8s";
2
- import { DeepPartial } 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 PeprRequest<T extends KubernetesObject> {
8
- private _input;
9
- Raw: T;
10
- get PermitSideEffects(): boolean;
11
- /**
12
- * Indicates whether the request is a dry run.
13
- * @returns true if the request is a dry run, false otherwise.
14
- */
15
- get IsDryRun(): boolean;
16
- /**
17
- * Provides access to the old resource in the request if available.
18
- * @returns The old Kubernetes resource object or null if not available.
19
- */
20
- get OldResource(): T;
21
- /**
22
- * Provides access to the request object.
23
- * @returns The request object containing the Kubernetes resource.
24
- */
25
- get Request(): Request<T>;
26
- /**
27
- * Creates a new instance of the Action class.
28
- * @param input - The request object containing the Kubernetes resource to modify.
29
- */
30
- constructor(input: Request<T>);
31
- /**
32
- * Deep merges the provided object with the current resource.
33
- *
34
- * @param obj - The object to merge with the current resource.
35
- */
36
- Merge(obj: DeepPartial<T>): void;
37
- /**
38
- * Updates a label on the Kubernetes resource.
39
- * @param key - The key of the label to update.
40
- * @param value - The value of the label.
41
- * @returns The current Action instance for method chaining.
42
- */
43
- SetLabel(key: string, value: string): this;
44
- /**
45
- * Updates an annotation on the Kubernetes resource.
46
- * @param key - The key of the annotation to update.
47
- * @param value - The value of the annotation.
48
- * @returns The current Action instance for method chaining.
49
- */
50
- SetAnnotation(key: string, value: string): this;
51
- /**
52
- * Removes a label from the Kubernetes resource.
53
- * @param key - The key of the label to remove.
54
- * @returns The current Action instance for method chaining.
55
- */
56
- RemoveLabel(key: string): this;
57
- /**
58
- * Removes an annotation from the Kubernetes resource.
59
- * @param key - The key of the annotation to remove.
60
- * @returns The current Action instance for method chaining.
61
- */
62
- RemoveAnnotation(key: string): this;
63
- /**
64
- * Check if a label exists on the Kubernetes resource.
65
- *
66
- * @param key the label key to check
67
- * @returns
68
- */
69
- HasLabel(key: string): boolean;
70
- /**
71
- * Check if an annotation exists on the Kubernetes resource.
72
- *
73
- * @param key the annotation key to check
74
- * @returns
75
- */
76
- HasAnnotation(key: string): boolean;
77
- }
@@ -1,187 +0,0 @@
1
- import { GroupVersionKind, KubernetesObject, WebhookIgnore } from "./k8s";
2
- import { PeprRequest } from "./request";
3
- /**
4
- * The behavior of this module when an error occurs.
5
- */
6
- export declare enum ErrorBehavior {
7
- ignore = "ignore",
8
- audit = "audit",
9
- reject = "reject"
10
- }
11
- /**
12
- * The phase of the Kubernetes admission webhook that the capability is registered for.
13
- *
14
- * Currently only `mutate` is supported.
15
- */
16
- export declare enum HookPhase {
17
- mutate = "mutate",
18
- validate = "validate"
19
- }
20
- /**
21
- * Recursively make all properties in T optional.
22
- */
23
- export type DeepPartial<T> = {
24
- [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
25
- };
26
- /**
27
- * The type of Kubernetes mutating webhook event that the capability action is registered for.
28
- */
29
- export declare enum Event {
30
- Create = "CREATE",
31
- Update = "UPDATE",
32
- Delete = "DELETE",
33
- CreateOrUpdate = "CREATEORUPDATE"
34
- }
35
- export interface CapabilityCfg {
36
- /**
37
- * The name of the capability. This should be unique.
38
- */
39
- name: string;
40
- /**
41
- * A description of the capability and what it does.
42
- */
43
- description: string;
44
- /**
45
- * List of namespaces that this capability applies to, if empty, applies to all namespaces (cluster-wide).
46
- * This does not supersede the `alwaysIgnore` global configuration.
47
- */
48
- namespaces?: string[];
49
- /**
50
- * FUTURE USE.
51
- *
52
- * Declare if this capability should be used for mutation or validation. Currently this is not used
53
- * and everything is considered a mutation.
54
- */
55
- mutateOrValidate?: HookPhase;
56
- }
57
- export type ModuleSigning = {
58
- /**
59
- * Specifies the signing policy.
60
- * "requireAuthorizedKey" - only authorized keys are accepted.
61
- * "requireAnyKey" - any key is accepted, as long as it's valid.
62
- * "none" - no signing required.
63
- */
64
- signingPolicy?: "requireAuthorizedKey" | "requireAnyKey" | "none";
65
- /**
66
- * List of authorized keys for the "requireAuthorizedKey" policy.
67
- * These keys are allowed to sign Pepr capabilities.
68
- */
69
- authorizedKeys?: string[];
70
- };
71
- /** Global configuration for the Pepr runtime. */
72
- export type ModuleConfig = {
73
- /** The user-defined name for the module */
74
- name: string;
75
- /** The version of Pepr that the module was originally generated with */
76
- version?: string;
77
- /** A unique identifier for this Pepr module. This is automatically generated by Pepr. */
78
- uuid: string;
79
- /** A description of the Pepr module and what it does. */
80
- description?: string;
81
- /** Reject K8s resource AdmissionRequests on error. */
82
- onError: ErrorBehavior | string;
83
- /** Configure global exclusions that will never be processed by Pepr. */
84
- alwaysIgnore: WebhookIgnore;
85
- /**
86
- * FUTURE USE.
87
- *
88
- * Configure the signing policy for Pepr capabilities.
89
- * This setting determines the requirements for signing keys in Pepr.
90
- */
91
- signing?: ModuleSigning;
92
- };
93
- export type GenericClass = abstract new () => any;
94
- export type WhenSelector<T extends GenericClass> = {
95
- /** Register a capability action to be executed when a Kubernetes resource is created or updated. */
96
- IsCreatedOrUpdated: () => BindingAll<T>;
97
- /** Register a capability action to be executed when a Kubernetes resource is created. */
98
- IsCreated: () => BindingAll<T>;
99
- /** Register a capability action to be executed when a Kubernetes resource is updated. */
100
- IsUpdated: () => BindingAll<T>;
101
- /** Register a capability action to be executed when a Kubernetes resource is deleted. */
102
- IsDeleted: () => BindingAll<T>;
103
- };
104
- export type Binding = {
105
- event?: Event;
106
- readonly kind: GroupVersionKind;
107
- readonly filters: {
108
- name: string;
109
- namespaces: string[];
110
- labels: Record<string, string>;
111
- annotations: Record<string, string>;
112
- };
113
- readonly callback: CapabilityAction<GenericClass, InstanceType<GenericClass>>;
114
- };
115
- export type BindingFilter<T extends GenericClass> = BindToActionOrSet<T> & {
116
- /**
117
- * Only apply the capability action if the resource has the specified label. If no value is specified, the label must exist.
118
- * Note multiple calls to this method will result in an AND condition. e.g.
119
- *
120
- * ```ts
121
- * When(a.Deployment)
122
- * .IsCreated()
123
- * .WithLabel("foo", "bar")
124
- * .WithLabel("baz", "qux")
125
- * .Then(...)
126
- * ```
127
- *
128
- * Will only apply the capability action if the resource has both the `foo=bar` and `baz=qux` labels.
129
- *
130
- * @param key
131
- * @param value
132
- */
133
- WithLabel: (key: string, value?: string) => BindingFilter<T>;
134
- /**
135
- * Only apply the capability action if the resource has the specified annotation. If no value is specified, the annotation must exist.
136
- * Note multiple calls to this method will result in an AND condition. e.g.
137
- *
138
- * ```ts
139
- * When(a.Deployment)
140
- * .IsCreated()
141
- * .WithAnnotation("foo", "bar")
142
- * .WithAnnotation("baz", "qux")
143
- * .Then(...)
144
- * ```
145
- *
146
- * Will only apply the capability action if the resource has both the `foo=bar` and `baz=qux` annotations.
147
- *
148
- * @param key
149
- * @param value
150
- */
151
- WithAnnotation: (key: string, value?: string) => BindingFilter<T>;
152
- };
153
- export type BindingWithName<T extends GenericClass> = BindingFilter<T> & {
154
- /** Only apply the capability action if the resource name matches the specified name. */
155
- WithName: (name: string) => BindingFilter<T>;
156
- };
157
- export type BindingAll<T extends GenericClass> = BindingWithName<T> & {
158
- /** Only apply the capability action if the resource is in one of the specified namespaces.*/
159
- InNamespace: (...namespaces: string[]) => BindingFilter<T>;
160
- };
161
- export type BindToAction<T extends GenericClass> = {
162
- /**
163
- * Create a new capability action with the specified callback function and previously specified
164
- * filters.
165
- * @param action The capability action to be executed when the Kubernetes resource is processed by the AdmissionController.
166
- */
167
- Then: (action: CapabilityAction<T, InstanceType<T>>) => BindToAction<T>;
168
- };
169
- export type BindToActionOrSet<T extends GenericClass> = BindToAction<T> & {
170
- /**
171
- * Merge the specified updates into the resource, this can only be used once per binding.
172
- * Note this is just a convenience method for `request.Merge(values)`.
173
- *
174
- * Example change the `minReadySeconds` to 3 of a deployment when it is created:
175
- *
176
- * ```ts
177
- * When(a.Deployment)
178
- * .IsCreated()
179
- * .ThenSet({ spec: { minReadySeconds: 3 } });
180
- * ```
181
- *
182
- * @param merge
183
- * @returns
184
- */
185
- ThenSet: (val: DeepPartial<InstanceType<T>>) => BindToAction<T>;
186
- };
187
- export type CapabilityAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (req: PeprRequest<K>) => Promise<void> | void | Promise<PeprRequest<K>> | PeprRequest<K>;