@catladder/cli 0.0.0-new-cli-80ac360a → 0.0.0-new-cli-a65ec262

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 (151) hide show
  1. package/README.md +2 -2
  2. package/dist/bundles/catenv/index.js +4341 -27
  3. package/dist/bundles/cli/index.js +15981 -771
  4. package/dist/cli/src/apps/catenv/catenv.d.ts +1 -0
  5. package/dist/cli/src/apps/catenv/catenv.js +1 -1
  6. package/dist/cli/src/apps/catenv/catenv.js.map +1 -1
  7. package/dist/cli/src/apps/catenv/printVariables.js +0 -10
  8. package/dist/cli/src/apps/catenv/printVariables.js.map +1 -1
  9. package/dist/cli/src/catenv.js +13 -16
  10. package/dist/cli/src/catenv.js.map +1 -1
  11. package/dist/cli/src/cli.js +24 -5
  12. package/dist/cli/src/cli.js.map +1 -1
  13. package/dist/cli/src/commands/cloudSQL/commandRestoreDb.js +1 -1
  14. package/dist/cli/src/commands/cloudSQL/commandRestoreDb.js.map +1 -1
  15. package/dist/cli/src/commands/fun/commandDadjoke.js +1 -1
  16. package/dist/cli/src/commands/fun/commandDadjoke.js.map +1 -1
  17. package/dist/cli/src/commands/fun/commandStarwars.js +1 -1
  18. package/dist/cli/src/commands/fun/commandStarwars.js.map +1 -1
  19. package/dist/cli/src/commands/general/commandKubeCurrentContext.js +1 -1
  20. package/dist/cli/src/commands/general/commandKubeGetShell.js +1 -1
  21. package/dist/cli/src/commands/general/commandKubeListNamespaces.js +1 -1
  22. package/dist/cli/src/commands/general/commandKubeListPods.js +1 -1
  23. package/dist/cli/src/commands/general/commandKubeListSecrets.js +1 -1
  24. package/dist/cli/src/commands/general/commandKubePortForward.js +1 -1
  25. package/dist/cli/src/commands/general/commandKubeStopPortforward.js +1 -1
  26. package/dist/cli/src/commands/index.d.ts +3 -0
  27. package/dist/cli/src/commands/index.js +23 -1
  28. package/dist/cli/src/commands/index.js.map +1 -1
  29. package/dist/cli/src/commands/mongodb/commandMongoDestroyMember.js +1 -1
  30. package/dist/cli/src/commands/mongodb/commandMongoGetShell.js +1 -1
  31. package/dist/cli/src/commands/mongodb/commandMongoPortForward.js +1 -1
  32. package/dist/cli/src/commands/project/commandCloudSqlProxy.js +1 -1
  33. package/dist/cli/src/commands/project/commandCloudSqlProxy.js.map +1 -1
  34. package/dist/cli/src/commands/project/commandConfigSecrets.js +1 -1
  35. package/dist/cli/src/commands/project/commandDeletePods.js +1 -1
  36. package/dist/cli/src/commands/project/commandDeleteProject.js +1 -1
  37. package/dist/cli/src/commands/project/commandEnvVars.js +1 -1
  38. package/dist/cli/src/commands/project/commandGetMyTotalWorktime.js +1 -1
  39. package/dist/cli/src/commands/project/commandGetMyTotalWorktime.js.map +1 -1
  40. package/dist/cli/src/commands/project/commandGetShell.js +1 -1
  41. package/dist/cli/src/commands/project/commandGitlabCi.js +2 -2
  42. package/dist/cli/src/commands/project/commandListPods.js +1 -1
  43. package/dist/cli/src/commands/project/commandNamespace.js +1 -1
  44. package/dist/cli/src/commands/project/commandOpenEnv.js +1 -1
  45. package/dist/cli/src/commands/project/commandOpenGit.js +1 -1
  46. package/dist/cli/src/commands/project/commandOpenLogs.js +1 -1
  47. package/dist/cli/src/commands/project/commandPauseProject.js +1 -1
  48. package/dist/cli/src/commands/project/commandPortForward.js +1 -1
  49. package/dist/cli/src/commands/project/commandProjectRestoreDb.js +1 -1
  50. package/dist/cli/src/commands/project/commandProjectRestoreDb.js.map +1 -1
  51. package/dist/cli/src/commands/project/commandRenewToken.js +1 -1
  52. package/dist/cli/src/commands/project/commandSecretsClearBackups.js +1 -1
  53. package/dist/cli/src/commands/project/commandSecurityEvaluate.js +2 -2
  54. package/dist/cli/src/commands/project/commandSecurityEvaluate.js.map +1 -1
  55. package/dist/cli/src/commands/project/commandSetup.js +1 -1
  56. package/dist/cli/src/commands/project/commandTriggerCronjob.js +2 -2
  57. package/dist/cli/src/commands/project/commandTriggerCronjob.js.map +1 -1
  58. package/dist/cli/src/commands/security/commandSecurityAuditCiJob.d.ts +27 -0
  59. package/dist/cli/src/commands/security/commandSecurityAuditCiJob.js +83 -0
  60. package/dist/cli/src/commands/security/commandSecurityAuditCiJob.js.map +1 -0
  61. package/dist/cli/src/commands/security/commandSecurityAuditCreate.d.ts +22 -0
  62. package/dist/cli/src/commands/security/commandSecurityAuditCreate.js +60 -0
  63. package/dist/cli/src/commands/security/commandSecurityAuditCreate.js.map +1 -0
  64. package/dist/cli/src/commands/security/commandSecurityAuditEvaluate.d.ts +7 -0
  65. package/dist/cli/src/commands/security/commandSecurityAuditEvaluate.js +35 -0
  66. package/dist/cli/src/commands/security/commandSecurityAuditEvaluate.js.map +1 -0
  67. package/dist/cli/src/completion.js +49 -36
  68. package/dist/cli/src/completion.js.map +1 -1
  69. package/dist/cli/src/security/auditDocument.js.map +1 -0
  70. package/dist/cli/src/security/createSecurityAuditMergeRequest.js.map +1 -0
  71. package/dist/cli/src/security/evaluateSecurityAudit.js.map +1 -0
  72. package/dist/pipeline/src/build/types.d.ts +1 -1
  73. package/dist/pipeline/src/constants.js +1 -1
  74. package/dist/pipeline/src/context/getEnvironmentVariables.d.ts +1 -1
  75. package/dist/pipeline/src/deploy/types/index.d.ts +2 -2
  76. package/dist/pipeline/src/types/config.d.ts +3 -3
  77. package/dist/tsconfig.tsbuildinfo +1 -1
  78. package/package.json +3 -6
  79. package/scripts/bundle +0 -2
  80. package/src/apps/catenv/catenv.ts +4 -2
  81. package/src/apps/catenv/printVariables.ts +0 -8
  82. package/src/catenv.ts +18 -19
  83. package/src/cli.ts +29 -5
  84. package/src/commands/cloudSQL/commandRestoreDb.ts +1 -1
  85. package/src/commands/fun/commandDadjoke.ts +1 -1
  86. package/src/commands/fun/commandStarwars.ts +1 -1
  87. package/src/commands/general/commandKubeCurrentContext.ts +1 -1
  88. package/src/commands/general/commandKubeGetShell.ts +1 -1
  89. package/src/commands/general/commandKubeListNamespaces.ts +1 -1
  90. package/src/commands/general/commandKubeListPods.ts +1 -1
  91. package/src/commands/general/commandKubeListSecrets.ts +1 -1
  92. package/src/commands/general/commandKubePortForward.ts +1 -1
  93. package/src/commands/general/commandKubeStopPortforward.ts +1 -1
  94. package/src/commands/index.ts +5 -0
  95. package/src/commands/mongodb/commandMongoDestroyMember.ts +1 -1
  96. package/src/commands/mongodb/commandMongoGetShell.ts +1 -1
  97. package/src/commands/mongodb/commandMongoPortForward.ts +1 -1
  98. package/src/commands/project/commandCloudSqlProxy.ts +1 -1
  99. package/src/commands/project/commandConfigSecrets.ts +1 -1
  100. package/src/commands/project/commandDeletePods.ts +1 -1
  101. package/src/commands/project/commandDeleteProject.ts +1 -1
  102. package/src/commands/project/commandEnvVars.ts +1 -1
  103. package/src/commands/project/commandGetMyTotalWorktime.ts +1 -1
  104. package/src/commands/project/commandGetShell.ts +1 -1
  105. package/src/commands/project/commandGitlabCi.ts +2 -2
  106. package/src/commands/project/commandListPods.ts +1 -1
  107. package/src/commands/project/commandNamespace.ts +1 -1
  108. package/src/commands/project/commandOpenEnv.ts +1 -1
  109. package/src/commands/project/commandOpenGit.ts +1 -1
  110. package/src/commands/project/commandOpenLogs.ts +1 -1
  111. package/src/commands/project/commandPauseProject.ts +1 -1
  112. package/src/commands/project/commandPortForward.ts +1 -1
  113. package/src/commands/project/commandProjectRestoreDb.ts +1 -1
  114. package/src/commands/project/commandRenewToken.ts +1 -1
  115. package/src/commands/project/commandSecretsClearBackups.ts +1 -1
  116. package/src/commands/project/commandSecurityEvaluate.ts +2 -2
  117. package/src/commands/project/commandSetup.ts +1 -1
  118. package/src/commands/project/commandTriggerCronjob.ts +2 -2
  119. package/src/commands/security/commandSecurityAuditCiJob.ts +91 -0
  120. package/src/commands/security/commandSecurityAuditCreate.ts +58 -0
  121. package/src/commands/security/commandSecurityAuditEvaluate.ts +30 -0
  122. package/src/completion.ts +53 -45
  123. package/bin/catci +0 -3
  124. package/bin/catci-dev +0 -3
  125. package/dist/bundles/catci/index.js +0 -71714
  126. package/dist/cli/src/apps/catci/catci.d.ts +0 -1
  127. package/dist/cli/src/apps/catci/catci.js +0 -33
  128. package/dist/cli/src/apps/catci/catci.js.map +0 -1
  129. package/dist/cli/src/apps/catci/commands/security/auditDocument.js.map +0 -1
  130. package/dist/cli/src/apps/catci/commands/security/commands.d.ts +0 -2
  131. package/dist/cli/src/apps/catci/commands/security/commands.js +0 -118
  132. package/dist/cli/src/apps/catci/commands/security/commands.js.map +0 -1
  133. package/dist/cli/src/apps/catci/commands/security/createSecurityAuditMergeRequest.js.map +0 -1
  134. package/dist/cli/src/apps/catci/commands/security/evaluateSecurityAudit.js.map +0 -1
  135. package/dist/cli/src/catci.d.ts +0 -1
  136. package/dist/cli/src/catci.js +0 -7
  137. package/dist/cli/src/catci.js.map +0 -1
  138. package/src/apps/catci/catci.ts +0 -26
  139. package/src/apps/catci/commands/security/commands.ts +0 -161
  140. package/src/catci.ts +0 -3
  141. /package/dist/cli/src/{apps/catci/commands/security → security}/auditDocument.d.ts +0 -0
  142. /package/dist/cli/src/{apps/catci/commands/security → security}/auditDocument.js +0 -0
  143. /package/dist/cli/src/{apps/catci/commands/security → security}/createSecurityAuditMergeRequest.d.ts +0 -0
  144. /package/dist/cli/src/{apps/catci/commands/security → security}/createSecurityAuditMergeRequest.js +0 -0
  145. /package/dist/cli/src/{apps/catci/commands/security → security}/evaluateSecurityAudit.d.ts +0 -0
  146. /package/dist/cli/src/{apps/catci/commands/security → security}/evaluateSecurityAudit.js +0 -0
  147. /package/dist/cli/src/{apps/catci/commands/security → security}/topics.json +0 -0
  148. /package/src/{apps/catci/commands/security → security}/auditDocument.ts +0 -0
  149. /package/src/{apps/catci/commands/security → security}/createSecurityAuditMergeRequest.ts +0 -0
  150. /package/src/{apps/catci/commands/security → security}/evaluateSecurityAudit.ts +0 -0
  151. /package/src/{apps/catci/commands/security → security}/topics.json +0 -0
@@ -0,0 +1,91 @@
1
+ import { defineCommand } from "../../core/defineCommand";
2
+ import { Gitlab } from "@gitbeaker/rest";
3
+ import {
4
+ evaluateSecurityAudit,
5
+ makeSecurityAuditOverview,
6
+ } from "../../security/evaluateSecurityAudit";
7
+ import {
8
+ createSecurityAuditMergeRequest,
9
+ SECURITY_AUDIT_FILE_NAME,
10
+ } from "../../security/createSecurityAuditMergeRequest";
11
+
12
+ const GITLAB_HOST = "https://git.panter.ch";
13
+
14
+ export const commandSecurityAuditCiJob = defineCommand({
15
+ name: "security audit ci-job",
16
+ description:
17
+ "Evaluates security audit document. Creates MR with template if missing.",
18
+ group: "security",
19
+ inputs: {
20
+ path: { type: "string", message: "path to project root", positional: true },
21
+ token: {
22
+ type: "string",
23
+ message: "GitLab token (api scope)",
24
+ positional: true,
25
+ },
26
+ mainBranch: {
27
+ type: "string",
28
+ message: "main branch name",
29
+ positional: true,
30
+ },
31
+ projectId: {
32
+ type: "string",
33
+ message: "GitLab project ID",
34
+ positional: true,
35
+ },
36
+ userId: {
37
+ type: "string",
38
+ message: "GitLab user ID (assignee)",
39
+ positional: true,
40
+ },
41
+ },
42
+ execute: async (ctx) => {
43
+ const path = await ctx.get("path");
44
+ const evaluation = await evaluateSecurityAudit({ path });
45
+
46
+ if (evaluation.isErr()) {
47
+ ctx.log("could not evaluate security audit document");
48
+ ctx.log("creating new merge request with security audit template...");
49
+
50
+ const token = await ctx.get("token");
51
+ const mainBranch = await ctx.get("mainBranch");
52
+ const projectId = await ctx.get("projectId");
53
+ const userId = await ctx.get("userId");
54
+
55
+ const api = new Gitlab({ host: GITLAB_HOST, token });
56
+
57
+ const mr = await createSecurityAuditMergeRequest({
58
+ api,
59
+ mainBranch,
60
+ projectId,
61
+ userId: parseInt(userId),
62
+ });
63
+
64
+ if (mr.isErr()) {
65
+ ctx.log(
66
+ `could not create merge request with security audit template: ${mr.error}`,
67
+ );
68
+ process.exitCode = 1;
69
+ return;
70
+ }
71
+
72
+ ctx.log("security audit merge request created successfully");
73
+ ctx.log(
74
+ `please finish the MR by updating SECURITY.md document: ${mr.value.web_url}`,
75
+ );
76
+ process.exitCode = 1;
77
+ return;
78
+ }
79
+
80
+ if (evaluation.value.score.answeredTopics === 0) {
81
+ ctx.log("audit document has no answered topics");
82
+ ctx.log(
83
+ `please answer security topics in ${SECURITY_AUDIT_FILE_NAME} by adding responsible people and check/cross in the table`,
84
+ );
85
+ process.exitCode = 1;
86
+ return;
87
+ }
88
+
89
+ ctx.log(makeSecurityAuditOverview(evaluation.value));
90
+ },
91
+ });
@@ -0,0 +1,58 @@
1
+ import { defineCommand } from "../../core/defineCommand";
2
+ import { Gitlab } from "@gitbeaker/rest";
3
+ import { createSecurityAuditMergeRequest } from "../../security/createSecurityAuditMergeRequest";
4
+
5
+ const GITLAB_HOST = "https://git.panter.ch";
6
+
7
+ export const commandSecurityAuditCreate = defineCommand({
8
+ name: "security audit create",
9
+ description: "Creates a MR with the latest security audit template document",
10
+ group: "security",
11
+ inputs: {
12
+ token: {
13
+ type: "string",
14
+ message: "GitLab token (api scope)",
15
+ positional: true,
16
+ },
17
+ mainBranch: {
18
+ type: "string",
19
+ message: "main branch name",
20
+ positional: true,
21
+ },
22
+ projectId: {
23
+ type: "string",
24
+ message: "GitLab project ID",
25
+ positional: true,
26
+ },
27
+ userId: {
28
+ type: "string",
29
+ message: "GitLab user ID (assignee)",
30
+ positional: true,
31
+ },
32
+ },
33
+ execute: async (ctx) => {
34
+ const token = await ctx.get("token");
35
+ const mainBranch = await ctx.get("mainBranch");
36
+ const projectId = await ctx.get("projectId");
37
+ const userId = await ctx.get("userId");
38
+
39
+ const api = new Gitlab({ host: GITLAB_HOST, token });
40
+
41
+ const result = await createSecurityAuditMergeRequest({
42
+ api,
43
+ mainBranch,
44
+ projectId,
45
+ userId: parseInt(userId),
46
+ });
47
+
48
+ if (result.isErr()) {
49
+ ctx.log(`could not create security audit merge request: ${result.error}`);
50
+ process.exitCode = 1;
51
+ } else {
52
+ ctx.log("security audit merge request created successfully");
53
+ ctx.log(
54
+ `please finish the MR by updating SECURITY.md document: ${result.value.web_url}`,
55
+ );
56
+ }
57
+ },
58
+ });
@@ -0,0 +1,30 @@
1
+ import { defineCommand } from "../../core/defineCommand";
2
+ import {
3
+ evaluateSecurityAudit,
4
+ makeSecurityAuditOverview,
5
+ } from "../../security/evaluateSecurityAudit";
6
+ import { SECURITY_AUDIT_FILE_NAME } from "../../security/createSecurityAuditMergeRequest";
7
+
8
+ export const commandSecurityAuditEvaluate = defineCommand({
9
+ name: "security audit evaluate",
10
+ description: "Evaluates security audit document in given path",
11
+ group: "security",
12
+ inputs: {
13
+ path: { type: "string", message: "path to project root", positional: true },
14
+ },
15
+ execute: async (ctx) => {
16
+ const path = await ctx.get("path");
17
+ ctx.log("evaluating security audit document...");
18
+
19
+ const result = await evaluateSecurityAudit({ path });
20
+ if (result.isErr()) {
21
+ ctx.log(`${result.error}`);
22
+ ctx.log(
23
+ `please make sure the security audit document ${SECURITY_AUDIT_FILE_NAME} is in the repository`,
24
+ );
25
+ process.exitCode = 1;
26
+ } else {
27
+ ctx.log(makeSecurityAuditOverview(result.value));
28
+ }
29
+ },
30
+ });
package/src/completion.ts CHANGED
@@ -16,60 +16,68 @@ export async function getCompletions(
16
16
  words: string[],
17
17
  cursorWord: string,
18
18
  ): Promise<string[]> {
19
- // If no command yet, complete command names
20
- if (words.length === 0) {
21
- return allCommands
22
- .map((c) => c.name)
23
- .filter((name) => name.startsWith(cursorWord));
24
- }
25
-
26
- const commandName = words[0];
27
- const command = allCommands.find((c) => c.name === commandName);
19
+ // Try to match words against command names (which can be multi-word)
20
+ // Walk through words, consuming them as command name parts until we find
21
+ // an exact command match or need to suggest the next subcommand level.
22
+
23
+ // Find all commands whose name starts with the words typed so far
24
+ const typed = words.join(" ");
25
+
26
+ // Exact match: we've typed a full command name, now complete its inputs
27
+ const exactCommand = allCommands.find((c) => c.name === typed);
28
+ if (exactCommand) {
29
+ // Check if cursor is a --flag
30
+ if (cursorWord.startsWith("--")) {
31
+ return getFlagCompletions(exactCommand, cursorWord);
32
+ }
28
33
 
29
- // If the first word doesn't match a command, complete command names
30
- if (!command) {
31
- return allCommands
32
- .map((c) => c.name)
33
- .filter((name) => name.startsWith(commandName));
34
- }
34
+ // Check if previous word was a --flag (complete its value)
35
+ const prevWord = words[words.length - 1];
36
+ if (prevWord?.startsWith("--")) {
37
+ const flagName = prevWord.replace(/^--/, "");
38
+ const inputName = flagNameToInputName(flagName);
39
+ const inputDef = exactCommand.inputs[inputName];
40
+ if (inputDef && "choices" in inputDef && inputDef.choices) {
41
+ return resolveChoicesForCompletion(inputDef, cursorWord);
42
+ }
43
+ return [];
44
+ }
35
45
 
36
- // We have a valid command. Figure out what to complete.
37
- const argsAfterCommand = words.slice(1);
38
-
39
- // Check if we're completing a --flag value
40
- const prevWord = argsAfterCommand[argsAfterCommand.length - 1];
41
- if (prevWord?.startsWith("--")) {
42
- // Previous word is a flag, complete its values
43
- const flagName = prevWord.replace(/^--/, "");
44
- const inputName = flagNameToInputName(flagName);
45
- const inputDef = command.inputs[inputName];
46
- if (inputDef && "choices" in inputDef && inputDef.choices) {
47
- return resolveChoicesForCompletion(inputDef, cursorWord);
46
+ // Complete positional inputs
47
+ const positionalInputs = getPositionalInputs(exactCommand);
48
+ // Count non-flag args after the command name
49
+ const argsAfterCommand = words.slice(exactCommand.name.split(" ").length);
50
+ const positionalArgs = argsAfterCommand.filter((w) => !w.startsWith("--"));
51
+ const positionalIndex = positionalArgs.length;
52
+ const targetInput = positionalInputs[positionalIndex];
53
+
54
+ if (targetInput) {
55
+ const [, inputDef] = targetInput;
56
+ if ("choices" in inputDef && inputDef.choices) {
57
+ return resolveChoicesForCompletion(inputDef, cursorWord);
58
+ }
48
59
  }
49
60
  return [];
50
61
  }
51
62
 
52
- // Check if we're typing a --flag name
53
- if (cursorWord.startsWith("--")) {
54
- return getFlagCompletions(command, cursorWord);
55
- }
56
-
57
- // Otherwise, complete positional inputs
58
- const positionalInputs = getPositionalInputs(command);
59
- const positionalArgs = argsAfterCommand.filter((w) => !w.startsWith("--"));
60
-
61
- // Which positional index are we on?
62
- const positionalIndex = positionalArgs.length;
63
- const targetInput = positionalInputs[positionalIndex];
64
-
65
- if (targetInput) {
66
- const [, inputDef] = targetInput;
67
- if ("choices" in inputDef && inputDef.choices) {
68
- return resolveChoicesForCompletion(inputDef, cursorWord);
63
+ // No exact match. Complete the next level of subcommand names.
64
+ // The prefix is what's been typed so far (words joined with space).
65
+ const prefix = typed ? typed + " " : "";
66
+
67
+ // Find unique next-level subcommand names
68
+ const nextParts = new Set<string>();
69
+ for (const cmd of allCommands) {
70
+ if (cmd.name.startsWith(prefix)) {
71
+ // Get the next word after the prefix
72
+ const rest = cmd.name.slice(prefix.length);
73
+ const nextPart = rest.split(" ")[0];
74
+ if (nextPart && nextPart.startsWith(cursorWord)) {
75
+ nextParts.add(nextPart);
76
+ }
69
77
  }
70
78
  }
71
79
 
72
- return [];
80
+ return [...nextParts].sort();
73
81
  }
74
82
 
75
83
  function getPositionalInputs(command: CommandDef): [string, InputDef][] {
package/bin/catci DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- // tslint:disable-next-line:no-var-requires
3
- require("../dist/bundles/catci/index.js");
package/bin/catci-dev DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- // tslint:disable-next-line:no-var-requires
3
- require("../dist/cli/src/catci.js");