pepr 0.52.3-nightly.5 → 0.52.3-nightly.7

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.52.3-nightly.5",
19
+ "version": "0.52.3-nightly.7",
20
20
  "main": "dist/lib.js",
21
21
  "types": "dist/lib.d.ts",
22
22
  "scripts": {
@@ -79,7 +79,7 @@
79
79
  "globals": "^16.0.0",
80
80
  "husky": "^9.1.6",
81
81
  "js-yaml": "^4.1.0",
82
- "shellcheck": "^3.0.0",
82
+ "shellcheck": "^4.1.0",
83
83
  "tsx": "^4.20.3",
84
84
  "undici": "^7.0.1",
85
85
  "vitest": "^3.2.3"
@@ -0,0 +1,45 @@
1
+ import { resolve } from "path/posix";
2
+ import {
3
+ peprPackageJSON,
4
+ gitignore,
5
+ eslint,
6
+ prettier,
7
+ readme,
8
+ tsConfig,
9
+ peprTSTemplate,
10
+ snippet,
11
+ codeSettings,
12
+ samplesYaml,
13
+ helloPepr,
14
+ } from "./templates";
15
+ import { write } from "./utils";
16
+
17
+ export async function createProjectFiles(
18
+ dirName: string,
19
+ packageJSON: peprPackageJSON,
20
+ ): Promise<void> {
21
+ const files = [
22
+ { path: gitignore.path, data: gitignore.data },
23
+ { path: eslint.path, data: eslint.data },
24
+ { path: prettier.path, data: prettier.data },
25
+ { path: packageJSON.path, data: packageJSON.data },
26
+ { path: readme.path, data: readme.data },
27
+ { path: tsConfig.path, data: tsConfig.data },
28
+ { path: peprTSTemplate.path, data: peprTSTemplate.data },
29
+ ];
30
+
31
+ const nestedFiles = [
32
+ { dir: ".vscode", path: snippet.path, data: snippet.data },
33
+ { dir: ".vscode", path: codeSettings.path, data: codeSettings.data },
34
+ { dir: "capabilities", path: samplesYaml.path, data: samplesYaml.data },
35
+ { dir: "capabilities", path: helloPepr.path, data: helloPepr.data },
36
+ ];
37
+
38
+ for (const file of files) {
39
+ await write(resolve(dirName, file.path), file.data);
40
+ }
41
+
42
+ for (const file of nestedFiles) {
43
+ await write(resolve(dirName, file.dir, file.path), file.data);
44
+ }
45
+ }
@@ -0,0 +1,23 @@
1
+ import { execSync } from "child_process";
2
+
3
+ export const doPostInitActions = (dirName: string): void => {
4
+ // run npm install from the new directory
5
+ process.chdir(dirName);
6
+ execSync("npm install", {
7
+ stdio: "inherit",
8
+ });
9
+
10
+ // setup git
11
+ execSync("git init --initial-branch=main", {
12
+ stdio: "inherit",
13
+ });
14
+
15
+ // try to open vscode
16
+ try {
17
+ execSync("code .", {
18
+ stdio: "inherit",
19
+ });
20
+ } catch {
21
+ console.warn("VSCode was not found, IDE will not automatically open.");
22
+ }
23
+ };
@@ -1,35 +1,23 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
3
 
4
- import { execSync } from "child_process";
5
- import { resolve } from "path";
6
-
7
4
  import { Command } from "commander";
8
- import {
9
- codeSettings,
10
- eslint,
11
- peprTSTemplate,
12
- genPkgJSON,
13
- gitignore,
14
- helloPepr,
15
- peprPackageJSON,
16
- prettier,
17
- readme,
18
- samplesYaml,
19
- snippet,
20
- tsConfig,
21
- } from "./templates";
22
- import { createDir, sanitizeName, write } from "./utils";
5
+ import { peprTSTemplate, genPkgJSON } from "./templates";
6
+ import { sanitizeName } from "./utils";
23
7
  import { confirm, PromptOptions, walkthrough } from "./walkthrough";
24
8
  import { ErrorList } from "../../lib/errors";
25
9
  import { UUID_LENGTH_LIMIT } from "./enums";
26
10
  import { Option } from "commander";
11
+ import { setupProjectStructure } from "./setupProjectStructure";
12
+ import { doPostInitActions } from "./doPostInitActions";
13
+ import { createProjectFiles } from "./createProjectFiles";
14
+ import { v4 as uuidv4 } from "uuid";
15
+ import Log from "../../lib/telemetry/logger";
27
16
 
28
- export default function (program: Command): void {
17
+ export default function (): Command {
29
18
  let response = {} as PromptOptions;
30
19
 
31
- program
32
- .command("init")
20
+ return new Command("init")
33
21
  .description("Initialize a new Pepr Module")
34
22
  .option("-d, --description <string>", "Explain the purpose of the new module.")
35
23
  .addOption(
@@ -41,6 +29,10 @@ export default function (program: Command): void {
41
29
  "-u, --uuid <string>",
42
30
  "Unique identifier for your module with a max length of 36 characters.",
43
31
  (uuid: string): string => {
32
+ if (typeof uuid === "undefined" || uuid === "") {
33
+ uuid = uuidv4();
34
+ Log.warn(`The UUID was empty. Generated new UUID: '${uuid}'`);
35
+ }
44
36
  if (uuid.length > UUID_LENGTH_LIMIT) {
45
37
  throw new Error("The UUID must be 36 characters or fewer.");
46
38
  }
@@ -59,7 +51,7 @@ export default function (program: Command): void {
59
51
  const confirmed = await confirm(dirName, packageJSON, peprTSTemplate.path, opts.yes);
60
52
 
61
53
  if (confirmed) {
62
- console.log("Creating new Pepr module...");
54
+ Log.info("Creating new Pepr module...");
63
55
 
64
56
  try {
65
57
  await setupProjectStructure(dirName);
@@ -69,69 +61,11 @@ export default function (program: Command): void {
69
61
  doPostInitActions(dirName);
70
62
  }
71
63
 
72
- console.log(`New Pepr module created at ${dirName}`);
73
- console.log(`Open VSCode or your editor of choice in ${dirName} to get started!`);
74
- } catch (e) {
75
- if (e instanceof Error) {
76
- console.error(`Error creating Pepr module:`, e);
77
- }
78
- process.exit(1);
64
+ Log.info(`New Pepr module created at ${dirName}`);
65
+ Log.info(`Open VSCode or your editor of choice in ${dirName} to get started!`);
66
+ } catch (error) {
67
+ throw new Error(`Error creating Pepr module:`, { cause: error });
79
68
  }
80
69
  }
81
70
  });
82
71
  }
83
-
84
- async function setupProjectStructure(dirName: string): Promise<void> {
85
- await createDir(dirName);
86
- await createDir(resolve(dirName, ".vscode"));
87
- await createDir(resolve(dirName, "capabilities"));
88
- }
89
-
90
- async function createProjectFiles(dirName: string, packageJSON: peprPackageJSON): Promise<void> {
91
- const files = [
92
- { path: gitignore.path, data: gitignore.data },
93
- { path: eslint.path, data: eslint.data },
94
- { path: prettier.path, data: prettier.data },
95
- { path: packageJSON.path, data: packageJSON.data },
96
- { path: readme.path, data: readme.data },
97
- { path: tsConfig.path, data: tsConfig.data },
98
- { path: peprTSTemplate.path, data: peprTSTemplate.data },
99
- ];
100
-
101
- const nestedFiles = [
102
- { dir: ".vscode", path: snippet.path, data: snippet.data },
103
- { dir: ".vscode", path: codeSettings.path, data: codeSettings.data },
104
- { dir: "capabilities", path: samplesYaml.path, data: samplesYaml.data },
105
- { dir: "capabilities", path: helloPepr.path, data: helloPepr.data },
106
- ];
107
-
108
- for (const file of files) {
109
- await write(resolve(dirName, file.path), file.data);
110
- }
111
-
112
- for (const file of nestedFiles) {
113
- await write(resolve(dirName, file.dir, file.path), file.data);
114
- }
115
- }
116
-
117
- const doPostInitActions = (dirName: string): void => {
118
- // run npm install from the new directory
119
- process.chdir(dirName);
120
- execSync("npm install", {
121
- stdio: "inherit",
122
- });
123
-
124
- // setup git
125
- execSync("git init --initial-branch=main", {
126
- stdio: "inherit",
127
- });
128
-
129
- // try to open vscode
130
- try {
131
- execSync("code .", {
132
- stdio: "inherit",
133
- });
134
- } catch {
135
- console.warn("VSCode was not found, IDE will not automatically open.");
136
- }
137
- };
@@ -0,0 +1,8 @@
1
+ import { createDir } from "./utils";
2
+ import { resolve } from "path";
3
+
4
+ export async function setupProjectStructure(dirName: string): Promise<void> {
5
+ await createDir(dirName);
6
+ await createDir(resolve(dirName, ".vscode"));
7
+ await createDir(resolve(dirName, "capabilities"));
8
+ }
@@ -3,7 +3,6 @@
3
3
 
4
4
  import { dumpYaml } from "@kubernetes/client-node";
5
5
  import { inspect } from "util";
6
- import { v4 as uuidv4 } from "uuid";
7
6
  import { readFileSync } from "fs";
8
7
  import path from "path";
9
8
 
@@ -50,8 +49,7 @@ export type peprPackageJSON = {
50
49
  };
51
50
 
52
51
  export function genPkgJSON(opts: InitOptions): peprPackageJSON {
53
- // Generate a random UUID for the module based on the module name if it is not provided
54
- const uuid = !opts.uuid ? uuidv4() : opts.uuid;
52
+ const uuid = opts.uuid;
55
53
  // Generate a name for the module based on the module name
56
54
  const name = sanitizeName(opts.name);
57
55
  // Make typescript a dev dependency
@@ -33,6 +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
+ if (typeof val === "undefined" || val === "") {
37
+ return "The UUID must be at least 1 character long";
38
+ }
36
39
  return (
37
40
  val.length <= UUID_LENGTH_LIMIT ||
38
41
  `The UUID must be ${UUID_LENGTH_LIMIT} characters or fewer.`
package/src/cli.ts CHANGED
@@ -30,6 +30,7 @@ program
30
30
  .version(version)
31
31
  .description(`Pepr (v${version}) - Type safe K8s middleware for humans`)
32
32
  .addCommand(crd())
33
+ .addCommand(init())
33
34
  .action(() => {
34
35
  if (program.args.length < 1) {
35
36
  console.log(banner);
@@ -41,7 +42,6 @@ program
41
42
  }
42
43
  });
43
44
 
44
- init(program);
45
45
  build(program);
46
46
  deploy(program);
47
47
  dev(program);
@@ -85,9 +85,9 @@ export function getWatcher(
85
85
  serviceAccountName: name,
86
86
  securityContext: {
87
87
  runAsUser: image.includes("private") ? 1000 : 65532,
88
- runAsGroup: 65532,
88
+ runAsGroup: image.includes("private") ? 1000 : 65532,
89
89
  runAsNonRoot: true,
90
- fsGroup: 65532,
90
+ fsGroup: image.includes("private") ? 1000 : 65532,
91
91
  },
92
92
  containers: [
93
93
  {
@@ -128,7 +128,7 @@ export function getWatcher(
128
128
  },
129
129
  securityContext: {
130
130
  runAsUser: image.includes("private") ? 1000 : 65532,
131
- runAsGroup: 65532,
131
+ runAsGroup: image.includes("private") ? 1000 : 65532,
132
132
  runAsNonRoot: true,
133
133
  allowPrivilegeEscalation: false,
134
134
  capabilities: {
@@ -228,9 +228,9 @@ export function getDeployment(
228
228
  serviceAccountName: name,
229
229
  securityContext: {
230
230
  runAsUser: image.includes("private") ? 1000 : 65532,
231
- runAsGroup: 65532,
231
+ runAsGroup: image.includes("private") ? 1000 : 65532,
232
232
  runAsNonRoot: true,
233
- fsGroup: 65532,
233
+ fsGroup: image.includes("private") ? 1000 : 65532,
234
234
  },
235
235
  containers: [
236
236
  {
@@ -272,7 +272,7 @@ export function getDeployment(
272
272
  env: genEnv(config),
273
273
  securityContext: {
274
274
  runAsUser: image.includes("private") ? 1000 : 65532,
275
- runAsGroup: 65532,
275
+ runAsGroup: image.includes("private") ? 1000 : 65532,
276
276
  runAsNonRoot: true,
277
277
  allowPrivilegeEscalation: false,
278
278
  capabilities: {
@@ -60,9 +60,9 @@ export async function overridesFile(
60
60
  },
61
61
  securityContext: {
62
62
  runAsUser: image.includes("private") ? 1000 : 65532,
63
- runAsGroup: 65532,
63
+ runAsGroup: image.includes("private") ? 1000 : 65532,
64
64
  runAsNonRoot: true,
65
- fsGroup: 65532,
65
+ fsGroup: image.includes("private") ? 1000 : 65532,
66
66
  },
67
67
  readinessProbe: {
68
68
  httpGet: {
@@ -92,7 +92,7 @@ export async function overridesFile(
92
92
  },
93
93
  containerSecurityContext: {
94
94
  runAsUser: image.includes("private") ? 1000 : 65532,
95
- runAsGroup: 65532,
95
+ runAsGroup: image.includes("private") ? 1000 : 65532,
96
96
  runAsNonRoot: true,
97
97
  allowPrivilegeEscalation: false,
98
98
  capabilities: {
@@ -128,9 +128,9 @@ export async function overridesFile(
128
128
  },
129
129
  securityContext: {
130
130
  runAsUser: image.includes("private") ? 1000 : 65532,
131
- runAsGroup: 65532,
131
+ runAsGroup: image.includes("private") ? 1000 : 65532,
132
132
  runAsNonRoot: true,
133
- fsGroup: 65532,
133
+ fsGroup: image.includes("private") ? 1000 : 65532,
134
134
  },
135
135
  readinessProbe: {
136
136
  httpGet: {
@@ -160,7 +160,7 @@ export async function overridesFile(
160
160
  },
161
161
  containerSecurityContext: {
162
162
  runAsUser: image.includes("private") ? 1000 : 65532,
163
- runAsGroup: 65532,
163
+ runAsGroup: image.includes("private") ? 1000 : 65532,
164
164
  runAsNonRoot: true,
165
165
  allowPrivilegeEscalation: false,
166
166
  capabilities: {
@@ -50,6 +50,7 @@ export class Controller {
50
50
  const { beforeHook, afterHook, onReady } = hooks;
51
51
  this.#config = config;
52
52
  this.#capabilities = capabilities;
53
+ Log.info({ config }, "Controller configuration");
53
54
 
54
55
  // Initialize the Pepr store for each capability
55
56
  new StoreController(capabilities, `pepr-${config.uuid}-store`, () => {