@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/dist/apps/catci/catci.js +17 -2
- package/dist/apps/catci/catci.js.map +1 -1
- package/dist/apps/catci/commands/security/commands.js +28 -18
- package/dist/apps/catci/commands/security/commands.js.map +1 -1
- package/dist/bundles/catci/index.js +6 -6
- package/dist/bundles/catenv/index.js +1 -1
- package/dist/bundles/cli/index.js +2 -2
- package/dist/gcloud/serviceAccounts.js +3 -1
- package/dist/gcloud/serviceAccounts.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/apps/catci/catci.ts +7 -1
- package/src/apps/catci/commands/security/commands.ts +100 -85
- package/src/gcloud/serviceAccounts.ts +2 -1
package/package.json
CHANGED
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
],
|
|
54
54
|
"license": "MIT",
|
|
55
|
-
"version": "1.136.
|
|
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.
|
|
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",
|
package/src/apps/catci/catci.ts
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
49
|
-
api
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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 (
|
|
82
|
+
if (evaluation.value.score.answeredTopics === 0) {
|
|
83
|
+
console.error("audit document has no answered topics");
|
|
56
84
|
console.error(
|
|
57
|
-
`
|
|
85
|
+
`please answer security topics in ${SECURITY_AUDIT_FILE_NAME} by adding responsible people and check/cross in the table`
|
|
58
86
|
);
|
|
59
|
-
|
|
60
|
-
return;
|
|
87
|
+
return Err("audit document has no answered topics" as const);
|
|
61
88
|
}
|
|
62
89
|
|
|
63
|
-
console.log(
|
|
64
|
-
|
|
65
|
-
|
|
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(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
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
|
|