pepr 0.46.3-nightly.9 → 0.47.0-nightly.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.
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "!src/fixtures/**",
17
17
  "!dist/**/*.test.d.ts*"
18
18
  ],
19
- "version": "0.46.3-nightly.9",
19
+ "version": "0.47.0-nightly.0",
20
20
  "main": "dist/lib.js",
21
21
  "types": "dist/lib.d.ts",
22
22
  "scripts": {
@@ -49,12 +49,12 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@types/ramda": "0.30.2",
52
- "express": "4.21.2",
52
+ "express": "5.1.0",
53
53
  "fast-json-patch": "3.1.1",
54
54
  "heredoc": "^1.3.1",
55
55
  "http-status-codes": "^2.3.0",
56
56
  "json-pointer": "^0.6.2",
57
- "kubernetes-fluent-client": "3.4.5",
57
+ "kubernetes-fluent-client": "3.4.6",
58
58
  "pino": "9.6.0",
59
59
  "pino-pretty": "13.0.0",
60
60
  "prom-client": "15.1.3",
@@ -78,7 +78,7 @@
78
78
  "jest": "29.7.0",
79
79
  "js-yaml": "^4.1.0",
80
80
  "shellcheck": "^3.0.0",
81
- "ts-jest": "29.3.0",
81
+ "ts-jest": "29.3.1",
82
82
  "undici": "^7.0.1"
83
83
  },
84
84
  "overrides": {
@@ -7,3 +7,5 @@ export enum OnError {
7
7
  IGNORE = "ignore",
8
8
  REJECT = "reject",
9
9
  }
10
+
11
+ export const UUID_LENGTH_LIMIT = 36;
@@ -23,6 +23,7 @@ import {
23
23
  import { createDir, sanitizeName, write } from "./utils";
24
24
  import { confirm, PromptOptions, walkthrough } from "./walkthrough";
25
25
  import { ErrorList } from "../../lib/errors";
26
+ import { UUID_LENGTH_LIMIT } from "./enums";
26
27
 
27
28
  export default function (program: RootCmd): void {
28
29
  let response = {} as PromptOptions;
@@ -37,11 +38,9 @@ export default function (program: RootCmd): void {
37
38
  .option(`--errorBehavior <${ErrorList.join("|")}>`, "Set an errorBehavior.")
38
39
  .option(
39
40
  "--uuid [string]",
40
- "Unique identifier for your module with a max length of 32 characters.",
41
+ "Unique identifier for your module with a max length of 36 characters.",
41
42
  (uuid: string): string => {
42
- const uuidLengthLimit = 36;
43
- // length of generated uuid
44
- if (uuid.length > uuidLengthLimit) {
43
+ if (uuid.length > UUID_LENGTH_LIMIT) {
45
44
  throw new Error("The UUID must be 36 characters or fewer.");
46
45
  }
47
46
  return uuid.toLocaleLowerCase();
@@ -6,7 +6,7 @@ import prompt, { Answers, PromptObject } from "prompts";
6
6
 
7
7
  import { eslint, gitignore, prettier, readme, tsConfig } from "./templates";
8
8
  import { sanitizeName } from "./utils";
9
- import { OnError } from "./enums";
9
+ import { OnError, UUID_LENGTH_LIMIT } from "./enums";
10
10
  import { ErrorList } from "../../lib/errors";
11
11
 
12
12
  export type PromptOptions = {
@@ -33,9 +33,9 @@ async function setUUID(uuid?: string): Promise<Answers<string>> {
33
33
  name: "uuid",
34
34
  message: "Enter a unique identifier for the new Pepr module.\n",
35
35
  validate: (val: string) => {
36
- const uuidLengthLimit = 36;
37
36
  return (
38
- val.length <= uuidLengthLimit || `The UUID must be ${uuidLengthLimit} characters or fewer.`
37
+ val.length <= UUID_LENGTH_LIMIT ||
38
+ `The UUID must be ${UUID_LENGTH_LIMIT} characters or fewer.`
39
39
  );
40
40
  },
41
41
  };
@@ -95,6 +95,7 @@ export type ValidateActionResponse = {
95
95
  allowed: boolean;
96
96
  statusCode?: number;
97
97
  statusMessage?: string;
98
+ warnings?: string[];
98
99
  };
99
100
 
100
101
  // DeepPartial utility type for deep optional properties
@@ -22,12 +22,21 @@ export function karForMutate(mr: MutateResponse): KubeAdmissionReview {
22
22
  export function karForValidate(ar: AdmissionRequest, vr: ValidateResponse[]): KubeAdmissionReview {
23
23
  const isAllowed = vr.filter(r => !r.allowed).length === 0;
24
24
 
25
+ // Collect all warnings from the ValidateResponse array
26
+ const warnings = vr.reduce<string[]>((acc, curr) => {
27
+ if (curr.warnings && curr.warnings.length > 0) {
28
+ return [...acc, ...curr.warnings];
29
+ }
30
+ return acc;
31
+ }, []);
32
+
25
33
  const resp: ValidateResponse =
26
34
  vr.length === 0
27
35
  ? {
28
36
  uid: ar.uid,
29
37
  allowed: true,
30
38
  status: { code: 200, message: "no in-scope validations -- allowed!" },
39
+ warnings: warnings.length > 0 ? warnings : undefined,
31
40
  }
32
41
  : {
33
42
  uid: vr[0].uid,
@@ -39,6 +48,7 @@ export function karForValidate(ar: AdmissionRequest, vr: ValidateResponse[]): Ku
39
48
  .map(curr => curr.status?.message)
40
49
  .join("; "),
41
50
  },
51
+ warnings: warnings.length > 0 ? warnings : undefined,
42
52
  };
43
53
  return {
44
54
  apiVersion: "admission.k8s.io/v1",
@@ -41,6 +41,11 @@ export async function processRequest(
41
41
  };
42
42
  }
43
43
 
44
+ // Transfer any warnings from the callback response to the validation response
45
+ if (callbackResp.warnings && callbackResp.warnings.length > 0) {
46
+ valResp.warnings = callbackResp.warnings;
47
+ }
48
+
44
49
  Log.info(
45
50
  actionMetadata,
46
51
  `Validation action complete (${label}): ${callbackResp.allowed ? "allowed" : "denied"}`,
@@ -6,8 +6,8 @@
6
6
  import { KubernetesObject } from "kubernetes-fluent-client";
7
7
 
8
8
  import { clone } from "ramda";
9
- import { Operation } from "./enums";
10
9
  import { AdmissionRequest, ValidateActionResponse } from "./common-types";
10
+ import { Operation } from "./enums";
11
11
 
12
12
  /**
13
13
  * The RequestWrapper class provides methods to modify Kubernetes objects in the context
@@ -79,9 +79,10 @@ export class PeprValidateRequest<T extends KubernetesObject> {
79
79
  *
80
80
  * @returns The validation response.
81
81
  */
82
- Approve = (): ValidateActionResponse => {
82
+ Approve = (warnings?: string[]): ValidateActionResponse => {
83
83
  return {
84
84
  allowed: true,
85
+ warnings,
85
86
  };
86
87
  };
87
88
 
@@ -92,11 +93,16 @@ export class PeprValidateRequest<T extends KubernetesObject> {
92
93
  * @param statusCode Optional status code to return to the user.
93
94
  * @returns The validation response.
94
95
  */
95
- Deny = (statusMessage?: string, statusCode?: number): ValidateActionResponse => {
96
+ Deny = (
97
+ statusMessage?: string,
98
+ statusCode?: number,
99
+ warnings?: string[],
100
+ ): ValidateActionResponse => {
96
101
  return {
97
102
  allowed: false,
98
103
  statusCode,
99
104
  statusMessage,
105
+ warnings,
100
106
  };
101
107
  };
102
108
  }