@catladder/cli 1.136.1 → 1.136.4

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
@@ -52,7 +52,7 @@
52
52
  }
53
53
  ],
54
54
  "license": "MIT",
55
- "version": "1.136.1",
55
+ "version": "1.136.4",
56
56
  "scripts": {
57
57
  "lint": "eslint \"src/**/*.ts\"",
58
58
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
@@ -71,7 +71,7 @@
71
71
  "node": ">=12.0.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@catladder/pipeline": "1.136.1",
74
+ "@catladder/pipeline": "1.136.4",
75
75
  "@gitbeaker/rest": "^39.28.0",
76
76
  "@kubernetes/client-node": "^0.16.2",
77
77
  "@tsconfig/node14": "^1.0.1",
@@ -2,6 +2,10 @@ import Vorpal from "vorpal";
2
2
  import packageInfo from "../../packageInfos";
3
3
  import securityCommands from "./commands/security/commands";
4
4
 
5
+ function reconstructArgs(args: string[]): string {
6
+ return [args[0], ...args.slice(1).map((arg) => `"${arg}"`)].join(" ");
7
+ }
8
+
5
9
  export async function runCatCi() {
6
10
  const vorpal = new Vorpal();
7
11
 
@@ -14,7 +18,9 @@ export async function runCatCi() {
14
18
  if (isInteractive) {
15
19
  vorpal.log(`Catladder CI Tools 😻🔨 version ${packageInfo.version}`).show();
16
20
  } else {
17
- await vorpal.exec(process.argv.slice(2).join(" "));
21
+ process.exitCode = 1;
22
+ const args = reconstructArgs(process.argv.slice(2));
23
+ await vorpal.exec(args);
18
24
  process.exit();
19
25
  }
20
26
  }
@@ -8,6 +8,7 @@ import {
8
8
  SECURITY_AUDIT_FILE_NAME,
9
9
  createSecurityAuditMergeRequest,
10
10
  } from "./createSecurityAuditMergeRequest";
11
+ import { Err, Ok, type Result } from "ts-results-es";
11
12
 
12
13
  const GITLAB_HOST = "https://git.panter.ch";
13
14
 
@@ -17,6 +18,17 @@ export default function (vorpal: Vorpal) {
17
18
  commandCreate(vorpal);
18
19
  }
19
20
 
21
+ type ActionFunc = (args: Vorpal.Args) => Promise<void>;
22
+
23
+ function resultAsExitCode(
24
+ func: (args: Vorpal.Args) => Promise<Result<unknown, unknown>>
25
+ ): ActionFunc {
26
+ return async (args: Vorpal.Args) => {
27
+ const result = await func(args);
28
+ process.exitCode = result.isErr() ? 1 : 0;
29
+ };
30
+ }
31
+
20
32
  async function commandCiJob(vorpal: Vorpal) {
21
33
  vorpal
22
34
  .command(
@@ -30,56 +42,55 @@ async function commandCiJob(vorpal: Vorpal) {
30
42
  <user-id> gitlab user id that will be assignee of the audit
31
43
  `
32
44
  )
33
- .action(async (args) => {
34
- const evaluation = await evaluateSecurityAudit({ path: args.path });
35
-
36
- if (evaluation.isErr()) {
37
- console.log("could not evaluate security audit document");
38
- console.log(
39
- "creating new merge request with security audit template..."
40
- );
41
-
42
- const { token, mainBranch, projectId, userId } = args;
43
- const api = new Gitlab({
44
- host: GITLAB_HOST,
45
- token,
46
- });
45
+ .action(
46
+ resultAsExitCode(async (args) => {
47
+ const evaluation = await evaluateSecurityAudit({ path: args.path });
48
+
49
+ if (evaluation.isErr()) {
50
+ console.log("could not evaluate security audit document");
51
+ console.log(
52
+ "creating new merge request with security audit template..."
53
+ );
47
54
 
48
- const mr = await createSecurityAuditMergeRequest({
49
- api,
50
- mainBranch,
51
- projectId,
52
- userId: parseInt(userId),
53
- });
55
+ const { token, mainBranch, projectId, userId } = args;
56
+ const api = new Gitlab({
57
+ host: GITLAB_HOST,
58
+ token,
59
+ });
60
+
61
+ const mr = await createSecurityAuditMergeRequest({
62
+ api,
63
+ mainBranch,
64
+ projectId,
65
+ userId: parseInt(userId),
66
+ });
67
+
68
+ if (mr.isErr()) {
69
+ console.error(
70
+ `could not create merge request with security audit template: ${mr.error}`
71
+ );
72
+ return mr;
73
+ }
74
+
75
+ console.log("security audit merge request created successfully");
76
+ console.log(
77
+ `please finish the MR by updating SECURITY.md document: ${mr.value.web_url}`
78
+ );
79
+ return Err("merge request created" as const);
80
+ }
54
81
 
55
- if (mr.isErr()) {
82
+ if (evaluation.value.score.answeredTopics === 0) {
83
+ console.error("audit document has no answered topics");
56
84
  console.error(
57
- `could not create merge request with security audit template: ${mr.error}`
85
+ `please answer security topics in ${SECURITY_AUDIT_FILE_NAME} by adding responsible people and check/cross in the table`
58
86
  );
59
- process.exitCode = 1;
60
- return;
87
+ return Err("audit document has no answered topics" as const);
61
88
  }
62
89
 
63
- console.log("security audit merge request created successfully");
64
- console.log(
65
- `please finish the MR by updating SECURITY.md document: ${mr.value.web_url}`
66
- );
67
- process.exitCode = 1;
68
- return;
69
- }
70
-
71
- if (evaluation.value.score.answeredTopics === 0) {
72
- console.error("audit document has no answered topics");
73
- console.error(
74
- `please answer security topics in ${SECURITY_AUDIT_FILE_NAME} by adding responsible people and check/cross in the table`
75
- );
76
- process.exitCode = 1;
77
- return;
78
- }
79
-
80
- process.exitCode = 0;
81
- console.log(makeSecurityAuditOverview(evaluation.value));
82
- });
90
+ console.log(makeSecurityAuditOverview(evaluation.value));
91
+ return Ok({});
92
+ })
93
+ );
83
94
  }
84
95
 
85
96
  async function commandEvaluate(vorpal: Vorpal) {
@@ -88,20 +99,22 @@ async function commandEvaluate(vorpal: Vorpal) {
88
99
  "security-audit-evaluate <path>",
89
100
  "Evaluates security audit document in given <path>"
90
101
  )
91
- .action(async (args) => {
92
- console.log("evaluating security audit document...");
93
-
94
- const result = await evaluateSecurityAudit({ path: args.path });
95
- if (result.isErr()) {
96
- console.error(result.error);
97
- console.error(
98
- `please make sure the security audit document ${SECURITY_AUDIT_FILE_NAME} is in the repository`
99
- );
100
- process.exitCode = 1;
101
- } else {
102
- console.log(makeSecurityAuditOverview(result.value));
103
- }
104
- });
102
+ .action(
103
+ resultAsExitCode(async (args) => {
104
+ console.log("evaluating security audit document...");
105
+
106
+ const result = await evaluateSecurityAudit({ path: args.path });
107
+ if (result.isErr()) {
108
+ console.error(result.error);
109
+ console.error(
110
+ `please make sure the security audit document ${SECURITY_AUDIT_FILE_NAME} is in the repository`
111
+ );
112
+ } else {
113
+ console.log(makeSecurityAuditOverview(result.value));
114
+ }
115
+ return result;
116
+ })
117
+ );
105
118
  }
106
119
 
107
120
  async function commandCreate(vorpal: Vorpal) {
@@ -116,31 +129,33 @@ async function commandCreate(vorpal: Vorpal) {
116
129
  <user-id> gitlab user id that will be assignee of the audit
117
130
  `
118
131
  )
119
- .action(async (args) => {
120
- const { token, mainBranch, projectId, userId } = args;
121
-
122
- const api = new Gitlab({
123
- host: GITLAB_HOST,
124
- token,
125
- });
126
-
127
- const result = await createSecurityAuditMergeRequest({
128
- api,
129
- mainBranch,
130
- projectId,
131
- userId: parseInt(userId),
132
- });
133
-
134
- if (result.isErr()) {
135
- console.error(
136
- `could not create security audit merge request: ${result.error}`
137
- );
138
- process.exitCode = 1;
139
- } else {
140
- console.log("security audit merge request created successfully");
141
- console.log(
142
- `please finish the MR by updating SECURITY.md document: ${result.value.web_url}`
143
- );
144
- }
145
- });
132
+ .action(
133
+ resultAsExitCode(async (args) => {
134
+ const { token, mainBranch, projectId, userId } = args;
135
+
136
+ const api = new Gitlab({
137
+ host: GITLAB_HOST,
138
+ token,
139
+ });
140
+
141
+ const result = await createSecurityAuditMergeRequest({
142
+ api,
143
+ mainBranch,
144
+ projectId,
145
+ userId: parseInt(userId),
146
+ });
147
+
148
+ if (result.isErr()) {
149
+ console.error(
150
+ `could not create security audit merge request: ${result.error}`
151
+ );
152
+ } else {
153
+ console.log("security audit merge request created successfully");
154
+ console.log(
155
+ `please finish the MR by updating SECURITY.md document: ${result.value.web_url}`
156
+ );
157
+ }
158
+ return result;
159
+ })
160
+ );
146
161
  }
@@ -69,7 +69,8 @@ const upsertGcloudServiceAccount = async (
69
69
  }
70
70
 
71
71
  return await exec(
72
- `gcloud iam service-accounts keys create /dev/stdout --iam-account=${fullIdentifier}`
72
+ // on some platforms /dev/stdout is not available without the pipe
73
+ `gcloud iam service-accounts keys create /dev/stdout --iam-account=${fullIdentifier} | cat`
73
74
  ).then((o) => o.stdout);
74
75
  };
75
76