pepr 0.42.1 → 0.42.3
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/dist/cli/build.helpers.d.ts +1 -1
- package/dist/cli/build.helpers.d.ts.map +1 -1
- package/dist/cli/deploy.d.ts +15 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.helpers.d.ts +3 -0
- package/dist/cli/format.helpers.d.ts.map +1 -0
- package/dist/cli/init/enums.d.ts +10 -0
- package/dist/cli/init/enums.d.ts.map +1 -0
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +15 -11
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/init/utils.d.ts.map +1 -1
- package/dist/cli/init/walkthrough.d.ts +3 -2
- package/dist/cli/init/walkthrough.d.ts.map +1 -1
- package/dist/cli/kfc.d.ts.map +1 -1
- package/dist/cli/root.d.ts.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/uuid.d.ts.map +1 -1
- package/dist/cli.js +1073 -1220
- package/dist/controller.js +1 -195
- package/dist/fixtures/loader.d.ts.map +1 -1
- package/dist/lib/assets/assets.d.ts +27 -0
- package/dist/lib/assets/assets.d.ts.map +1 -0
- package/dist/lib/assets/deploy.d.ts +1 -1
- package/dist/lib/assets/deploy.d.ts.map +1 -1
- package/dist/lib/assets/index.d.ts +5 -24
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/pods.d.ts +2 -4
- package/dist/lib/assets/pods.d.ts.map +1 -1
- package/dist/lib/assets/rbac.d.ts.map +1 -1
- package/dist/lib/assets/webhooks.d.ts +1 -1
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts +31 -5
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts +2 -2
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts +1 -1
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/controller/storeCache.d.ts +1 -1
- package/dist/lib/controller/storeCache.d.ts.map +1 -1
- package/dist/lib/{capability.d.ts → core/capability.d.ts} +1 -1
- package/dist/lib/core/capability.d.ts.map +1 -0
- package/dist/lib/{module.d.ts → core/module.d.ts} +2 -2
- package/dist/lib/core/module.d.ts.map +1 -0
- package/dist/lib/core/queue.d.ts.map +1 -0
- package/dist/lib/{schedule.d.ts → core/schedule.d.ts} +0 -1
- package/dist/lib/core/schedule.d.ts.map +1 -0
- package/dist/lib/core/storage.d.ts.map +1 -0
- package/dist/lib/deploymentChecks.d.ts.map +1 -1
- package/dist/lib/errors.d.ts +0 -5
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/filesystemService.d.ts.map +1 -1
- package/dist/lib/filter/adjudicators/adjudicators.d.ts +5 -4
- package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -1
- package/dist/lib/filter/filter.d.ts +33 -1
- package/dist/lib/filter/filter.d.ts.map +1 -1
- package/dist/lib/finalizer.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +4 -9
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/included-files.d.ts.map +1 -1
- package/dist/lib/mutate-request.d.ts.map +1 -1
- package/dist/lib/processors/mutate-processor.d.ts +28 -0
- package/dist/lib/processors/mutate-processor.d.ts.map +1 -0
- package/dist/lib/{validate-processor.d.ts → processors/validate-processor.d.ts} +5 -5
- package/dist/lib/processors/validate-processor.d.ts.map +1 -0
- package/dist/lib/{watch-processor.d.ts → processors/watch-processor.d.ts} +2 -2
- package/dist/lib/processors/watch-processor.d.ts.map +1 -0
- package/dist/lib/telemetry/logger.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib/validate-request.d.ts +2 -2
- package/dist/lib/validate-request.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +383 -243
- package/dist/lib.js.map +4 -4
- package/dist/sdk/heredoc.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/cli/build.helpers.ts +1 -1
- package/src/cli/build.ts +1 -1
- package/src/cli/deploy.ts +114 -75
- package/src/cli/dev.ts +3 -3
- package/src/cli/format.helpers.ts +27 -0
- package/src/cli/format.ts +4 -18
- package/src/cli/init/enums.ts +9 -0
- package/src/cli/init/index.ts +4 -3
- package/src/cli/init/templates.ts +30 -2
- package/src/cli/init/utils.ts +3 -3
- package/src/cli/init/walkthrough.ts +7 -8
- package/src/cli/kfc.ts +1 -1
- package/src/cli/root.ts +1 -1
- package/src/cli/update.ts +1 -1
- package/src/cli/uuid.ts +1 -1
- package/src/fixtures/loader.ts +2 -2
- package/src/lib/assets/assets.ts +176 -0
- package/src/lib/assets/deploy.ts +6 -6
- package/src/lib/assets/index.ts +10 -144
- package/src/lib/assets/pods.ts +2 -2
- package/src/lib/assets/webhooks.ts +32 -56
- package/src/lib/assets/yaml.ts +47 -25
- package/src/lib/controller/index.ts +4 -4
- package/src/lib/controller/store.ts +2 -2
- package/src/lib/controller/storeCache.ts +6 -2
- package/src/lib/{capability.ts → core/capability.ts} +4 -4
- package/src/lib/{module.ts → core/module.ts} +10 -10
- package/src/lib/{queue.ts → core/queue.ts} +1 -1
- package/src/lib/deploymentChecks.ts +2 -2
- package/src/lib/errors.ts +3 -8
- package/src/lib/filesystemService.ts +1 -1
- package/src/lib/filter/adjudicators/adjudicators.ts +40 -9
- package/src/lib/filter/filter.ts +204 -111
- package/src/lib/finalizer.ts +2 -2
- package/src/lib/helpers.ts +20 -133
- package/src/lib/included-files.ts +1 -1
- package/src/lib/processors/mutate-processor.ts +225 -0
- package/src/lib/{validate-processor.ts → processors/validate-processor.ts} +8 -8
- package/src/lib/{watch-processor.ts → processors/watch-processor.ts} +8 -8
- package/src/lib/telemetry/logger.ts +3 -1
- package/src/lib/tls.ts +5 -1
- package/src/lib/validate-request.ts +4 -4
- package/src/lib.ts +2 -2
- package/src/runtime/controller.ts +2 -2
- package/src/sdk/heredoc.ts +1 -1
- package/dist/lib/capability.d.ts.map +0 -1
- package/dist/lib/module.d.ts.map +0 -1
- package/dist/lib/mutate-processor.d.ts +0 -6
- package/dist/lib/mutate-processor.d.ts.map +0 -1
- package/dist/lib/queue.d.ts.map +0 -1
- package/dist/lib/schedule.d.ts.map +0 -1
- package/dist/lib/storage.d.ts.map +0 -1
- package/dist/lib/validate-processor.d.ts.map +0 -1
- package/dist/lib/watch-processor.d.ts.map +0 -1
- package/src/lib/mutate-processor.ts +0 -165
- /package/dist/lib/{queue.d.ts → core/queue.d.ts} +0 -0
- /package/dist/lib/{storage.d.ts → core/storage.d.ts} +0 -0
- /package/src/lib/{schedule.ts → core/schedule.ts} +0 -0
- /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,
|
|
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.
|
|
18
|
+
"version": "0.42.3",
|
|
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.
|
|
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.
|
|
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
|
-
"
|
|
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.
|
|
83
|
+
"prettier": "3.4.2",
|
|
84
84
|
"prompts": "2.4.2",
|
|
85
|
-
"typescript": "5.3.3",
|
|
86
|
-
"uuid": "
|
|
85
|
+
"typescript": "^5.3.3",
|
|
86
|
+
"uuid": "11.0.3"
|
|
87
87
|
}
|
|
88
88
|
}
|
package/src/cli/build.helpers.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { execSync } from "child_process";
|
|
|
5
5
|
import { CapabilityExport } from "../lib/types";
|
|
6
6
|
import { validateCapabilityNames } from "../lib/helpers";
|
|
7
7
|
import { BuildOptions, BuildResult, context, BuildContext } from "esbuild";
|
|
8
|
-
import { Assets } from "../lib/assets";
|
|
8
|
+
import { Assets } from "../lib/assets/assets";
|
|
9
9
|
import { resolve } from "path";
|
|
10
10
|
import { promises as fs } from "fs";
|
|
11
11
|
|
package/src/cli/build.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { execFileSync } from "child_process";
|
|
|
5
5
|
import { BuildOptions, BuildResult, analyzeMetafile } from "esbuild";
|
|
6
6
|
import { promises as fs } from "fs";
|
|
7
7
|
import { basename, dirname, extname, resolve } from "path";
|
|
8
|
-
import { Assets } from "../lib/assets";
|
|
8
|
+
import { Assets } from "../lib/assets/assets";
|
|
9
9
|
import { dependencies, version } from "./init/templates";
|
|
10
10
|
import { RootCmd } from "./root";
|
|
11
11
|
import { Option } from "commander";
|
package/src/cli/deploy.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import prompt from "prompts";
|
|
5
5
|
|
|
6
|
-
import { Assets } from "../lib/assets";
|
|
6
|
+
import { Assets } from "../lib/assets/assets";
|
|
7
7
|
import { buildModule } from "./build";
|
|
8
8
|
import { RootCmd } from "./root";
|
|
9
9
|
import { validateCapabilityNames } from "../lib/helpers";
|
|
@@ -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
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
//
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
@@ -5,12 +5,12 @@ import { ChildProcess, fork } from "child_process";
|
|
|
5
5
|
import { promises as fs } from "fs";
|
|
6
6
|
import prompt from "prompts";
|
|
7
7
|
import { validateCapabilityNames } from "../lib/helpers";
|
|
8
|
-
import { Assets } from "../lib/assets";
|
|
8
|
+
import { Assets } from "../lib/assets/assets";
|
|
9
9
|
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 {
|
|
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
|
-
|
|
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) {
|
package/src/cli/init/index.ts
CHANGED
|
@@ -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
|
|
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.",
|
|
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
|
-
|
|
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,
|
package/src/cli/init/utils.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
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")
|
package/src/fixtures/loader.ts
CHANGED
|
@@ -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
|
|