pepr 0.42.1 → 0.42.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 (126) hide show
  1. package/dist/cli/deploy.d.ts +15 -0
  2. package/dist/cli/deploy.d.ts.map +1 -1
  3. package/dist/cli/dev.d.ts.map +1 -1
  4. package/dist/cli/format.d.ts.map +1 -1
  5. package/dist/cli/format.helpers.d.ts +3 -0
  6. package/dist/cli/format.helpers.d.ts.map +1 -0
  7. package/dist/cli/init/enums.d.ts +10 -0
  8. package/dist/cli/init/enums.d.ts.map +1 -0
  9. package/dist/cli/init/index.d.ts.map +1 -1
  10. package/dist/cli/init/templates.d.ts +15 -11
  11. package/dist/cli/init/templates.d.ts.map +1 -1
  12. package/dist/cli/init/utils.d.ts.map +1 -1
  13. package/dist/cli/init/walkthrough.d.ts +3 -2
  14. package/dist/cli/init/walkthrough.d.ts.map +1 -1
  15. package/dist/cli/kfc.d.ts.map +1 -1
  16. package/dist/cli/root.d.ts.map +1 -1
  17. package/dist/cli/update.d.ts.map +1 -1
  18. package/dist/cli/uuid.d.ts.map +1 -1
  19. package/dist/cli.js +145 -306
  20. package/dist/controller.js +1 -195
  21. package/dist/fixtures/loader.d.ts.map +1 -1
  22. package/dist/lib/assets/deploy.d.ts.map +1 -1
  23. package/dist/lib/assets/index.d.ts +1 -1
  24. package/dist/lib/assets/index.d.ts.map +1 -1
  25. package/dist/lib/assets/pods.d.ts +1 -3
  26. package/dist/lib/assets/pods.d.ts.map +1 -1
  27. package/dist/lib/assets/rbac.d.ts.map +1 -1
  28. package/dist/lib/assets/webhooks.d.ts.map +1 -1
  29. package/dist/lib/controller/index.d.ts +2 -2
  30. package/dist/lib/controller/index.d.ts.map +1 -1
  31. package/dist/lib/controller/store.d.ts +1 -1
  32. package/dist/lib/controller/store.d.ts.map +1 -1
  33. package/dist/lib/controller/storeCache.d.ts +1 -1
  34. package/dist/lib/controller/storeCache.d.ts.map +1 -1
  35. package/dist/lib/{capability.d.ts → core/capability.d.ts} +1 -1
  36. package/dist/lib/core/capability.d.ts.map +1 -0
  37. package/dist/lib/{module.d.ts → core/module.d.ts} +2 -2
  38. package/dist/lib/core/module.d.ts.map +1 -0
  39. package/dist/lib/core/queue.d.ts.map +1 -0
  40. package/dist/lib/{schedule.d.ts → core/schedule.d.ts} +0 -1
  41. package/dist/lib/core/schedule.d.ts.map +1 -0
  42. package/dist/lib/core/storage.d.ts.map +1 -0
  43. package/dist/lib/deploymentChecks.d.ts.map +1 -1
  44. package/dist/lib/errors.d.ts +0 -5
  45. package/dist/lib/errors.d.ts.map +1 -1
  46. package/dist/lib/filesystemService.d.ts.map +1 -1
  47. package/dist/lib/filter/adjudicators/adjudicators.d.ts +5 -4
  48. package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -1
  49. package/dist/lib/filter/filter.d.ts +33 -1
  50. package/dist/lib/filter/filter.d.ts.map +1 -1
  51. package/dist/lib/finalizer.d.ts.map +1 -1
  52. package/dist/lib/helpers.d.ts +4 -9
  53. package/dist/lib/helpers.d.ts.map +1 -1
  54. package/dist/lib/included-files.d.ts.map +1 -1
  55. package/dist/lib/mutate-request.d.ts.map +1 -1
  56. package/dist/lib/processors/mutate-processor.d.ts +28 -0
  57. package/dist/lib/processors/mutate-processor.d.ts.map +1 -0
  58. package/dist/lib/{validate-processor.d.ts → processors/validate-processor.d.ts} +5 -5
  59. package/dist/lib/processors/validate-processor.d.ts.map +1 -0
  60. package/dist/lib/{watch-processor.d.ts → processors/watch-processor.d.ts} +2 -2
  61. package/dist/lib/processors/watch-processor.d.ts.map +1 -0
  62. package/dist/lib/telemetry/logger.d.ts.map +1 -1
  63. package/dist/lib/telemetry/metrics.d.ts.map +1 -1
  64. package/dist/lib/validate-request.d.ts +2 -2
  65. package/dist/lib/validate-request.d.ts.map +1 -1
  66. package/dist/lib.d.ts +2 -2
  67. package/dist/lib.d.ts.map +1 -1
  68. package/dist/lib.js +383 -243
  69. package/dist/lib.js.map +4 -4
  70. package/dist/sdk/heredoc.d.ts.map +1 -1
  71. package/package.json +9 -9
  72. package/src/cli/deploy.ts +113 -74
  73. package/src/cli/dev.ts +2 -2
  74. package/src/cli/format.helpers.ts +27 -0
  75. package/src/cli/format.ts +4 -18
  76. package/src/cli/init/enums.ts +9 -0
  77. package/src/cli/init/index.ts +4 -3
  78. package/src/cli/init/templates.ts +30 -2
  79. package/src/cli/init/utils.ts +3 -3
  80. package/src/cli/init/walkthrough.ts +7 -8
  81. package/src/cli/kfc.ts +1 -1
  82. package/src/cli/root.ts +1 -1
  83. package/src/cli/update.ts +1 -1
  84. package/src/cli/uuid.ts +1 -1
  85. package/src/fixtures/loader.ts +2 -2
  86. package/src/lib/assets/deploy.ts +5 -5
  87. package/src/lib/assets/index.ts +1 -1
  88. package/src/lib/assets/pods.ts +1 -1
  89. package/src/lib/assets/webhooks.ts +30 -45
  90. package/src/lib/controller/index.ts +4 -4
  91. package/src/lib/controller/store.ts +2 -2
  92. package/src/lib/controller/storeCache.ts +6 -2
  93. package/src/lib/{capability.ts → core/capability.ts} +4 -4
  94. package/src/lib/{module.ts → core/module.ts} +10 -10
  95. package/src/lib/{queue.ts → core/queue.ts} +1 -1
  96. package/src/lib/deploymentChecks.ts +2 -2
  97. package/src/lib/errors.ts +3 -8
  98. package/src/lib/filesystemService.ts +1 -1
  99. package/src/lib/filter/adjudicators/adjudicators.ts +40 -9
  100. package/src/lib/filter/filter.ts +204 -111
  101. package/src/lib/finalizer.ts +2 -2
  102. package/src/lib/helpers.ts +20 -133
  103. package/src/lib/included-files.ts +1 -1
  104. package/src/lib/processors/mutate-processor.ts +225 -0
  105. package/src/lib/{validate-processor.ts → processors/validate-processor.ts} +8 -8
  106. package/src/lib/{watch-processor.ts → processors/watch-processor.ts} +8 -8
  107. package/src/lib/telemetry/logger.ts +3 -1
  108. package/src/lib/tls.ts +5 -1
  109. package/src/lib/validate-request.ts +4 -4
  110. package/src/lib.ts +2 -2
  111. package/src/runtime/controller.ts +2 -2
  112. package/src/sdk/heredoc.ts +1 -1
  113. package/dist/lib/capability.d.ts.map +0 -1
  114. package/dist/lib/module.d.ts.map +0 -1
  115. package/dist/lib/mutate-processor.d.ts +0 -6
  116. package/dist/lib/mutate-processor.d.ts.map +0 -1
  117. package/dist/lib/queue.d.ts.map +0 -1
  118. package/dist/lib/schedule.d.ts.map +0 -1
  119. package/dist/lib/storage.d.ts.map +0 -1
  120. package/dist/lib/validate-processor.d.ts.map +0 -1
  121. package/dist/lib/watch-processor.d.ts.map +0 -1
  122. package/src/lib/mutate-processor.ts +0 -165
  123. /package/dist/lib/{queue.d.ts → core/queue.d.ts} +0 -0
  124. /package/dist/lib/{storage.d.ts → core/storage.d.ts} +0 -0
  125. /package/src/lib/{schedule.ts → core/schedule.ts} +0 -0
  126. /package/src/lib/{storage.ts → core/storage.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"heredoc.d.ts","sourceRoot":"","sources":["../../src/sdk/heredoc.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,UAgCzE"}
1
+ {"version":3,"file":"heredoc.d.ts","sourceRoot":"","sources":["../../src/sdk/heredoc.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAgClF"}
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "!src/**/*.test.ts",
16
16
  "!dist/**/*.test.d.ts*"
17
17
  ],
18
- "version": "0.42.1",
18
+ "version": "0.42.2",
19
19
  "main": "dist/lib.js",
20
20
  "types": "dist/lib.d.ts",
21
21
  "scripts": {
@@ -47,14 +47,14 @@
47
47
  "http-status-codes": "^2.3.0",
48
48
  "json-pointer": "^0.6.2",
49
49
  "kubernetes-fluent-client": "3.3.7",
50
- "pino": "9.5.0",
50
+ "pino": "9.6.0",
51
51
  "pino-pretty": "13.0.0",
52
52
  "prom-client": "15.1.3",
53
53
  "ramda": "0.30.1",
54
54
  "sigstore": "3.0.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@commitlint/cli": "19.6.0",
57
+ "@commitlint/cli": "19.6.1",
58
58
  "@commitlint/config-conventional": "19.6.0",
59
59
  "@fast-check/jest": "^2.0.1",
60
60
  "@jest/globals": "29.7.0",
@@ -73,16 +73,16 @@
73
73
  "undici": "^7.0.1"
74
74
  },
75
75
  "peerDependencies": {
76
- "@types/prompts": "2.4.9",
77
76
  "@typescript-eslint/eslint-plugin": "7.18.0",
78
77
  "@typescript-eslint/parser": "7.18.0",
79
- "commander": "12.1.0",
80
- "esbuild": "0.23.0",
78
+ "@types/prompts": "2.4.9",
81
79
  "eslint": "8.57.0",
80
+ "commander": "12.1.0",
81
+ "esbuild": "0.24.0",
82
82
  "node-forge": "1.3.1",
83
- "prettier": "3.3.3",
83
+ "prettier": "3.4.2",
84
84
  "prompts": "2.4.2",
85
- "typescript": "5.3.3",
86
- "uuid": "10.0.0"
85
+ "typescript": "^5.3.3",
86
+ "uuid": "11.0.3"
87
87
  }
88
88
  }
package/src/cli/deploy.ts CHANGED
@@ -12,7 +12,88 @@ import { sanitizeName } from "./init/utils";
12
12
  import { deployImagePullSecret } from "../lib/assets/deploy";
13
13
  import { namespaceDeploymentsReady } from "../lib/deploymentChecks";
14
14
 
15
- export default function (program: RootCmd) {
15
+ export interface ImagePullSecretDetails {
16
+ pullSecret?: string;
17
+ dockerServer?: string;
18
+ dockerUsername?: string;
19
+ dockerEmail?: string;
20
+ dockerPassword?: string;
21
+ }
22
+
23
+ export function validateImagePullSecretDetails(details: ImagePullSecretDetails): {
24
+ valid: boolean;
25
+ error?: string;
26
+ } {
27
+ if (!details.pullSecret) {
28
+ return { valid: true };
29
+ }
30
+
31
+ // https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
32
+ if (details.pullSecret !== sanitizeName(details.pullSecret)) {
33
+ return {
34
+ valid: false,
35
+ error: `Invalid --pullSecret. Must be valid name as defined in RFC 1123.`,
36
+ };
37
+ }
38
+
39
+ const missing: string[] = [];
40
+ if (!details.dockerEmail) {
41
+ missing.push("--docker-email");
42
+ }
43
+ if (!details.dockerServer) {
44
+ missing.push("--docker-server");
45
+ }
46
+ if (!details.dockerUsername) {
47
+ missing.push("--docker-username");
48
+ }
49
+ if (!details.dockerPassword) {
50
+ missing.push("--docker-password");
51
+ }
52
+
53
+ if (missing.length > 0) {
54
+ return {
55
+ valid: false,
56
+ error: `Error: Must provide ${missing.join(", ")} when providing --pullSecret`,
57
+ };
58
+ }
59
+
60
+ return { valid: true };
61
+ }
62
+
63
+ export type ValidatedImagePullSecretDetails = Required<ImagePullSecretDetails>;
64
+
65
+ function generateImagePullSecret(details: ValidatedImagePullSecretDetails): ImagePullSecret {
66
+ const auth = Buffer.from(`${details.dockerUsername}:${details.dockerPassword}`).toString(
67
+ "base64",
68
+ );
69
+ return {
70
+ auths: {
71
+ [details.dockerServer]: {
72
+ username: details.dockerUsername,
73
+ password: details.dockerPassword,
74
+ email: details.dockerEmail,
75
+ auth,
76
+ },
77
+ },
78
+ };
79
+ }
80
+
81
+ export async function getUserConfirmation(opts: { confirm: boolean }): Promise<boolean> {
82
+ if (opts.confirm) {
83
+ return true;
84
+ }
85
+
86
+ // Prompt the user to confirm
87
+ const confirm = await prompt({
88
+ type: "confirm",
89
+ name: "confirm",
90
+ message: "This will remove and redeploy the module. Continue?",
91
+ });
92
+
93
+ return confirm.confirm ? true : false;
94
+ }
95
+
96
+ export default function (program: RootCmd): void {
16
97
  program
17
98
  .command("deploy")
18
99
  .description("Deploy a Pepr Module")
@@ -25,85 +106,43 @@ export default function (program: RootCmd) {
25
106
  .option("--docker-password <password>", "Password for Docker registry")
26
107
  .option("--force", "Force deploy the module, override manager field")
27
108
  .action(async opts => {
28
- let imagePullSecret: ImagePullSecret | undefined;
29
-
30
- if (
31
- opts.pullSecret &&
32
- opts.pullSecret.length > 0 &&
33
- (!opts.dockerServer || !opts.dockerUsername || !opts.dockerEmail || !opts.dockerPassword)
34
- ) {
35
- console.error(
36
- "Error: Must provide docker server, username, email, and password when providing pull secret",
37
- );
109
+ const valResp = validateImagePullSecretDetails(opts);
110
+ if (!valResp.valid) {
111
+ console.error(valResp.error);
38
112
  process.exit(1);
39
- } else if (opts.pullSecret && opts.pullSecret !== sanitizeName(opts.pullSecret)) {
40
- // https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
41
- console.error(
42
- "Invalid imagePullSecret name. Please provide a valid name as defined in RFC 1123.",
43
- );
44
- process.exit(1);
45
- } else if (opts.pullSecret) {
46
- imagePullSecret = {
47
- auths: {
48
- [opts.dockerServer]: {
49
- username: opts.dockerUsername,
50
- password: opts.dockerPassword,
51
- email: opts.dockerEmail,
52
- auth: Buffer.from(`${opts.dockerUsername}:${opts.dockerPassword}`).toString("base64"),
53
- },
54
- },
55
- };
56
-
57
- await deployImagePullSecret(imagePullSecret, opts.pullSecret);
113
+ }
114
+
115
+ if (opts.pullSecret) {
116
+ await deployImagePullSecret(generateImagePullSecret(opts), opts.pullSecret);
58
117
  return;
59
118
  }
60
119
 
61
- if (!opts.confirm) {
62
- // Prompt the user to confirm
63
- const confirm = await prompt({
64
- type: "confirm",
65
- name: "confirm",
66
- message: "This will remove and redeploy the module. Continue?",
67
- });
68
-
69
- // Exit if the user doesn't confirm
70
- if (!confirm.confirm) {
71
- process.exit(0);
72
- }
120
+ (await getUserConfirmation(opts)) || process.exit(0);
121
+
122
+ const builtModule = await buildModule();
123
+ if (!builtModule) {
124
+ return;
73
125
  }
74
126
 
75
- // Build the module
76
- const buildModuleResult = await buildModule();
77
- if (buildModuleResult?.cfg && buildModuleResult?.path) {
78
- const { cfg, path } = buildModuleResult;
79
-
80
- // Generate a secret for the module
81
- const webhook = new Assets(
82
- {
83
- ...cfg.pepr,
84
- description: cfg.description,
85
- },
86
- path,
87
- );
88
-
89
- if (opts.image) {
90
- webhook.image = opts.image;
91
- }
92
-
93
- // Identify conf'd webhookTimeout to give to deploy call
94
- const timeout = cfg.pepr.webhookTimeout ? cfg.pepr.webhookTimeout : 10;
95
-
96
- try {
97
- await webhook.deploy(opts.force, timeout);
98
- // wait for capabilities to be loaded and test names
99
- validateCapabilityNames(webhook.capabilities);
100
- // Wait for the pepr-system resources to be fully up
101
- await namespaceDeploymentsReady();
102
- console.info(`✅ Module deployed successfully`);
103
- } catch (e) {
104
- console.error(`Error deploying module:`, e);
105
- process.exit(1);
106
- }
127
+ // Generate a secret for the module
128
+ const webhook = new Assets(
129
+ { ...builtModule.cfg.pepr, description: builtModule.cfg.description },
130
+ builtModule.path,
131
+ );
132
+ webhook.image = opts.image ?? webhook.image;
133
+
134
+ try {
135
+ await webhook.deploy(opts.force, builtModule.cfg.pepr.webhookTimeout ?? 10);
136
+
137
+ // wait for capabilities to be loaded and test names
138
+ validateCapabilityNames(webhook.capabilities);
139
+
140
+ // Wait for the pepr-system resources to be fully up
141
+ await namespaceDeploymentsReady();
142
+ console.info(`✅ Module deployed successfully`);
143
+ } catch (e) {
144
+ console.error(`Error deploying module:`, e);
145
+ process.exit(1);
107
146
  }
108
147
  });
109
148
  }
package/src/cli/dev.ts CHANGED
@@ -10,7 +10,7 @@ import { buildModule, loadModule } from "./build";
10
10
  import { RootCmd } from "./root";
11
11
  import { K8s, kind } from "kubernetes-fluent-client";
12
12
  import { Store } from "../lib/k8s";
13
- export default function (program: RootCmd) {
13
+ export default function (program: RootCmd): void {
14
14
  program
15
15
  .command("dev")
16
16
  .description("Setup a local webhook development environment")
@@ -55,7 +55,7 @@ export default function (program: RootCmd) {
55
55
  const store = `pepr-${cfg.pepr.uuid}-store`;
56
56
 
57
57
  // Run the processed javascript file
58
- const runFork = async () => {
58
+ const runFork = async (): Promise<void> => {
59
59
  console.info(`Running module ${path}`);
60
60
 
61
61
  // Deploy the webhook with a 30 second timeout for debugging, don't force
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
+
4
+ import { ESLint } from "eslint";
5
+ import { promises as fs } from "fs";
6
+ import { format, resolveConfig } from "prettier";
7
+
8
+ export async function formatWithPrettier(
9
+ results: ESLint.LintResult[],
10
+ validateOnly: boolean,
11
+ ): Promise<boolean> {
12
+ let hasFailure = false;
13
+ for (const { filePath } of results) {
14
+ const content = await fs.readFile(filePath, "utf8");
15
+ const cfg = await resolveConfig(filePath);
16
+ const formatted = await format(content, { filepath: filePath, ...cfg });
17
+
18
+ // If in validate-only mode, check if the file is formatted correctly
19
+ if (validateOnly && formatted !== content) {
20
+ hasFailure = true;
21
+ console.error(`File ${filePath} is not formatted correctly`);
22
+ } else {
23
+ await fs.writeFile(filePath, formatted);
24
+ }
25
+ }
26
+ return hasFailure;
27
+ }
package/src/cli/format.ts CHANGED
@@ -2,12 +2,11 @@
2
2
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
3
 
4
4
  import { ESLint } from "eslint";
5
- import { promises as fs } from "fs";
6
- import { format, resolveConfig } from "prettier";
5
+ import { formatWithPrettier } from "./format.helpers";
7
6
 
8
7
  import { RootCmd } from "./root";
9
8
 
10
- export default function (program: RootCmd) {
9
+ export default function (program: RootCmd): void {
11
10
  program
12
11
  .command("format")
13
12
  .description("Lint and format this Pepr module")
@@ -28,7 +27,7 @@ export default function (program: RootCmd) {
28
27
  * @param validateOnly
29
28
  * @returns success
30
29
  */
31
- export async function peprFormat(validateOnly: boolean) {
30
+ export async function peprFormat(validateOnly: boolean): Promise<boolean> {
32
31
  {
33
32
  try {
34
33
  const eslint = new ESLint();
@@ -56,20 +55,7 @@ export async function peprFormat(validateOnly: boolean) {
56
55
  await ESLint.outputFixes(results);
57
56
  }
58
57
 
59
- // Format with Prettier
60
- for (const { filePath } of results) {
61
- const content = await fs.readFile(filePath, "utf8");
62
- const cfg = await resolveConfig(filePath);
63
- const formatted = await format(content, { filepath: filePath, ...cfg });
64
-
65
- // If in validate-only mode, check if the file is formatted correctly
66
- if (validateOnly && formatted !== content) {
67
- hasFailure = true;
68
- console.error(`File ${filePath} is not formatted correctly`);
69
- } else {
70
- await fs.writeFile(filePath, formatted);
71
- }
72
- }
58
+ hasFailure = await formatWithPrettier(results, validateOnly);
73
59
 
74
60
  return !hasFailure;
75
61
  } catch (e) {
@@ -0,0 +1,9 @@
1
+ export enum RbacMode {
2
+ SCOPED = "scoped",
3
+ ADMIN = "admin",
4
+ }
5
+ export enum OnError {
6
+ AUDIT = "audit",
7
+ IGNORE = "ignore",
8
+ REJECT = "reject",
9
+ }
@@ -21,9 +21,10 @@ import {
21
21
  } from "./templates";
22
22
  import { createDir, sanitizeName, write } from "./utils";
23
23
  import { confirm, PromptOptions, walkthrough } from "./walkthrough";
24
- import { ErrorList, Errors } from "../../lib/errors";
24
+ import { ErrorList } from "../../lib/errors";
25
+ import { OnError } from "./enums";
25
26
 
26
- export default function (program: RootCmd) {
27
+ export default function (program: RootCmd): void {
27
28
  let response = {} as PromptOptions;
28
29
  let pkgOverride = "";
29
30
  program
@@ -33,7 +34,7 @@ export default function (program: RootCmd) {
33
34
  .option("--description <string>", "Explain the purpose of the new module.")
34
35
  .option("--name <string>", "Set the name of the new module.")
35
36
  .option("--skip-post-init", "Skip npm install, git init, and VSCode launch.")
36
- .option(`--errorBehavior <${ErrorList.join("|")}>`, "Set an errorBehavior.", Errors.reject)
37
+ .option(`--errorBehavior <${ErrorList.join("|")}>`, "Set an errorBehavior.", OnError.REJECT)
37
38
  .hook("preAction", async thisCommand => {
38
39
  // TODO: Overrides for testing. Don't be so gross with Node CLI testing
39
40
  // TODO: See pepr/#1140
@@ -14,10 +14,38 @@ import settingsJSON from "../../templates/settings.json";
14
14
  import tsConfigJSON from "../../templates/tsconfig.module.json";
15
15
  import { sanitizeName } from "./utils";
16
16
  import { InitOptions } from "../types";
17
+ import { V1PolicyRule as PolicyRule } from "@kubernetes/client-node";
18
+ import { OnError, RbacMode } from "./enums";
17
19
 
18
20
  export const { dependencies, devDependencies, peerDependencies, scripts, version } = packageJSON;
19
21
 
20
- export function genPkgJSON(opts: InitOptions, pgkVerOverride?: string) {
22
+ type peprPackageJSON = {
23
+ data: {
24
+ name: string;
25
+ version: string;
26
+ description: string;
27
+ keywords: string[];
28
+ engines: { node: string };
29
+ pepr: {
30
+ uuid: string;
31
+ onError: OnError;
32
+ webhookTimeout: number;
33
+ customLabels: { namespace: Record<string, string> };
34
+ alwaysIgnore: { namespaces: string[] };
35
+ includedFiles: string[];
36
+ env: object;
37
+ rbac?: PolicyRule[];
38
+ rbacMode?: RbacMode;
39
+ };
40
+ scripts: { "k3d-setup": string };
41
+ dependencies: { pepr: string; undici: string };
42
+ devDependencies: { typescript: string };
43
+ };
44
+ path: string;
45
+ print: string;
46
+ };
47
+
48
+ export function genPkgJSON(opts: InitOptions, pgkVerOverride?: string): peprPackageJSON {
21
49
  // Generate a random UUID for the module based on the module name
22
50
  const uuid = uuidv5(opts.name, uuidv4());
23
51
  // Generate a name for the module based on the module name
@@ -72,7 +100,7 @@ export function genPkgJSON(opts: InitOptions, pgkVerOverride?: string) {
72
100
  };
73
101
  }
74
102
 
75
- export function genPeprTS() {
103
+ export function genPeprTS(): { path: string; data: string } {
76
104
  return {
77
105
  path: "pepr.ts",
78
106
  data: peprTS,
@@ -9,7 +9,7 @@ import { promises as fs } from "fs";
9
9
  * @param name the user input name
10
10
  * @returns the sanitized name
11
11
  */
12
- export function sanitizeName(name: string) {
12
+ export function sanitizeName(name: string): string {
13
13
  if (typeof name !== "string") {
14
14
  throw TypeError(
15
15
  `sanitizeName() was called with a non-string value. The value is: ${name} of type ${typeof name}`,
@@ -32,7 +32,7 @@ export function sanitizeName(name: string) {
32
32
  *
33
33
  * @param dir - The directory to create
34
34
  */
35
- export async function createDir(dir: string) {
35
+ export async function createDir(dir: string): Promise<void> {
36
36
  try {
37
37
  await fs.mkdir(dir);
38
38
  } catch (err) {
@@ -51,7 +51,7 @@ export async function createDir(dir: string) {
51
51
  * @param data - The data to write
52
52
  * @returns A promise that resolves when the file has been written
53
53
  */
54
- export function write(path: string, data: unknown) {
54
+ export function write(path: string, data: unknown): Promise<void> {
55
55
  // If the data is not a string, stringify it
56
56
  if (typeof data !== "string") {
57
57
  data = JSON.stringify(data, null, 2);
@@ -4,14 +4,15 @@
4
4
  import { promises as fs } from "fs";
5
5
  import prompt, { Answers, PromptObject } from "prompts";
6
6
 
7
- import { ErrorList, Errors } from "../../lib/errors";
8
7
  import { eslint, gitignore, prettier, readme, tsConfig } from "./templates";
9
8
  import { sanitizeName } from "./utils";
9
+ import { OnError } from "./enums";
10
+ import { ErrorList } from "../../lib/errors";
10
11
 
11
12
  export type PromptOptions = {
12
13
  name: string;
13
14
  description: string;
14
- errorBehavior: "audit" | "ignore" | "reject";
15
+ errorBehavior: OnError;
15
16
  };
16
17
 
17
18
  export type PartialPromptOptions = Partial<PromptOptions>;
@@ -70,9 +71,7 @@ async function setDescription(description?: string): Promise<Answers<string>> {
70
71
  return prompt([askDescription]);
71
72
  }
72
73
 
73
- export async function setErrorBehavior(
74
- errorBehavior?: "audit" | "ignore" | "reject",
75
- ): Promise<Answers<string>> {
74
+ export async function setErrorBehavior(errorBehavior?: OnError): Promise<Answers<string>> {
76
75
  const askErrorBehavior: PromptObject = {
77
76
  type: "select",
78
77
  name: "errorBehavior",
@@ -80,20 +79,20 @@ export async function setErrorBehavior(
80
79
  choices: [
81
80
  {
82
81
  title: "Reject the operation",
83
- value: Errors.reject,
82
+ value: OnError.REJECT,
84
83
  description:
85
84
  "In the event that Pepr is down or other module errors occur, the operation will not be allowed to continue. (Recommended for production.)",
86
85
  },
87
86
  {
88
87
  title: "Ignore",
89
- value: Errors.ignore,
88
+ value: OnError.IGNORE,
90
89
  description:
91
90
  "In the event that Pepr is down or other module errors occur, an entry will be generated in the Pepr Controller Log and the operation will be allowed to continue. (Recommended for development, not for production.)",
92
91
  selected: true,
93
92
  },
94
93
  {
95
94
  title: "Log an audit event",
96
- value: Errors.audit,
95
+ value: OnError.AUDIT,
97
96
  description:
98
97
  "Pepr will continue processing and generate an entry in the Pepr Controller log as well as an audit event in the cluster.",
99
98
  },
package/src/cli/kfc.ts CHANGED
@@ -6,7 +6,7 @@ import prompt from "prompts";
6
6
 
7
7
  import { RootCmd } from "./root";
8
8
 
9
- export default function (program: RootCmd) {
9
+ export default function (program: RootCmd): void {
10
10
  program
11
11
  .command("kfc [args...]")
12
12
  .description("Execute Kubernetes Fluent Client commands")
package/src/cli/root.ts CHANGED
@@ -5,7 +5,7 @@ import { Command } from "commander";
5
5
 
6
6
  export class RootCmd extends Command {
7
7
  // eslint-disable-next-line class-methods-use-this
8
- createCommand(name: string) {
8
+ createCommand(name: string): Command {
9
9
  const cmd = new Command(name);
10
10
  return cmd;
11
11
  }
package/src/cli/update.ts CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  import { write } from "./init/utils";
18
18
  import { RootCmd } from "./root";
19
19
 
20
- export default function (program: RootCmd) {
20
+ export default function (program: RootCmd): void {
21
21
  program
22
22
  .command("update")
23
23
  .description("Update this Pepr module. Not recommended for prod as it may change files.")
package/src/cli/uuid.ts CHANGED
@@ -5,7 +5,7 @@ import { KubernetesListObject } from "@kubernetes/client-node";
5
5
  import { K8s, kind } from "kubernetes-fluent-client";
6
6
  import { RootCmd } from "./root";
7
7
 
8
- export default function (program: RootCmd) {
8
+ export default function (program: RootCmd): void {
9
9
  program
10
10
  .command("uuid [uuid]")
11
11
  .description("Module UUID(s) currently deployed in the cluster")
@@ -14,11 +14,11 @@ export function AdmissionRequestCreatePod() {
14
14
  return cloneObject<kind.Pod>(admissionRequestCreatePod);
15
15
  }
16
16
 
17
- export function AdmissionRequestDeletePod() {
17
+ export function AdmissionRequestDeletePod(): AdmissionRequest<kind.Pod> {
18
18
  return cloneObject<kind.Pod>(admissionRequestDeletePod);
19
19
  }
20
20
 
21
- export function AdmissionRequestCreateClusterRole() {
21
+ export function AdmissionRequestCreateClusterRole(): AdmissionRequest<kind.ClusterRole> {
22
22
  return cloneObject<kind.ClusterRole>(admissionRequestCreateClusterRole);
23
23
  }
24
24
 
@@ -15,7 +15,7 @@ import { peprStoreCRD } from "./store";
15
15
  import { webhookConfig } from "./webhooks";
16
16
  import { CapabilityExport, ImagePullSecret } from "../types";
17
17
 
18
- export async function deployImagePullSecret(imagePullSecret: ImagePullSecret, name: string) {
18
+ export async function deployImagePullSecret(imagePullSecret: ImagePullSecret, name: string): Promise<void> {
19
19
  try {
20
20
  await K8s(kind.Namespace).Get("pepr-system");
21
21
  } catch {
@@ -42,7 +42,7 @@ export async function deployImagePullSecret(imagePullSecret: ImagePullSecret, na
42
42
  Log.error(e);
43
43
  }
44
44
  }
45
- export async function deploy(assets: Assets, force: boolean, webhookTimeout?: number) {
45
+ export async function deploy(assets: Assets, force: boolean, webhookTimeout?: number): Promise<void> {
46
46
  Log.info("Establishing connection to Kubernetes");
47
47
 
48
48
  const { name, host, path } = assets;
@@ -95,7 +95,7 @@ async function setupRBAC(
95
95
  capabilities: CapabilityExport[],
96
96
  force: boolean,
97
97
  config: { rbacMode?: string; rbac?: PolicyRule[] },
98
- ) {
98
+ ): Promise<void> {
99
99
  const { rbacMode, rbac } = config;
100
100
 
101
101
  Log.info("Applying cluster role binding");
@@ -119,7 +119,7 @@ async function setupRBAC(
119
119
  await K8s(kind.RoleBinding).Apply(roleBinding, { force });
120
120
  }
121
121
 
122
- async function setupController(assets: Assets, code: Buffer, hash: string, force: boolean) {
122
+ async function setupController(assets: Assets, code: Buffer, hash: string, force: boolean): Promise<void> {
123
123
  const { name } = assets;
124
124
 
125
125
  Log.info("Applying module secret");
@@ -144,7 +144,7 @@ async function setupController(assets: Assets, code: Buffer, hash: string, force
144
144
  }
145
145
 
146
146
  // Setup the watcher deployment and service
147
- async function setupWatcher(assets: Assets, hash: string, force: boolean) {
147
+ async function setupWatcher(assets: Assets, hash: string, force: boolean): Promise<void> {
148
148
  // If the module has a watcher, deploy it
149
149
  const watchDeployment = getWatcher(assets, hash, assets.buildTimestamp);
150
150
  if (watchDeployment) {
@@ -4,7 +4,7 @@
4
4
  import crypto from "crypto";
5
5
  import { dumpYaml } from "@kubernetes/client-node";
6
6
  import { kind } from "kubernetes-fluent-client";
7
- import { ModuleConfig } from "../module";
7
+ import { ModuleConfig } from "../core/module";
8
8
  import { TLSOut, genTLS } from "../tls";
9
9
  import { CapabilityExport } from "../types";
10
10
  import { WebhookIgnore } from "../k8s";
@@ -6,7 +6,7 @@ import { kind } from "kubernetes-fluent-client";
6
6
  import { gzipSync } from "zlib";
7
7
  import { secretOverLimit } from "../helpers";
8
8
  import { Assets } from ".";
9
- import { ModuleConfig } from "../module";
9
+ import { ModuleConfig } from "../core/module";
10
10
  import { Binding } from "../types";
11
11
 
12
12
  /** Generate the pepr-system namespace */