@catladder/cli 1.145.0 → 1.146.0

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 (107) hide show
  1. package/dist/bundles/catenv/index.js +1 -1
  2. package/dist/bundles/cli/index.js +1 -1
  3. package/dist/cli/src/apps/catci/commands/security/evaluateSecurityAudit.js.map +1 -1
  4. package/dist/cli/src/apps/catenv/catenv.js +8 -12
  5. package/dist/cli/src/apps/catenv/catenv.js.map +1 -1
  6. package/dist/cli/src/apps/cli/commands/general/namespaceAutoCompletion.js +1 -1
  7. package/dist/cli/src/apps/cli/commands/mongodb/projectMongoGetShell.js.map +1 -1
  8. package/dist/cli/src/apps/cli/commands/mongodb/projectMongoPortForward.js.map +1 -1
  9. package/dist/cli/src/apps/cli/commands/mongodb/utils/index.js.map +1 -1
  10. package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -1
  11. package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js +1 -2
  12. package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js.map +1 -1
  13. package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js +1 -2
  14. package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -1
  15. package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.js.map +1 -1
  16. package/dist/cli/src/apps/cli/commands/project/utils/ensureNamespace.js +1 -2
  17. package/dist/cli/src/apps/cli/commands/project/utils/ensureNamespace.js.map +1 -1
  18. package/dist/cli/src/gcloud/cloudSql/startProxy.js +1 -2
  19. package/dist/cli/src/gcloud/cloudSql/startProxy.js.map +1 -1
  20. package/dist/cli/src/utils/gitlab.d.ts +1 -1
  21. package/dist/cli/src/utils/gitlab.js +38 -26
  22. package/dist/cli/src/utils/gitlab.js.map +1 -1
  23. package/dist/cli/src/utils/promise.js.map +1 -1
  24. package/dist/pipeline/src/context/getEnvironmentVariables.js +1 -2
  25. package/dist/pipeline/src/context/getEnvironmentVariables.js.map +1 -1
  26. package/dist/pipeline/src/context/resolveReferences.js.map +1 -1
  27. package/dist/pipeline/src/deploy/base/deploy.js.map +1 -1
  28. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +1 -2
  29. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js.map +1 -1
  30. package/dist/pipeline/src/deploy/cloudRun/index.js.map +1 -1
  31. package/dist/pipeline/src/deploy/kubernetes/kubeValues.js +1 -2
  32. package/dist/pipeline/src/deploy/kubernetes/kubeValues.js.map +1 -1
  33. package/dist/pipeline/src/pipeline/createMainPipeline.js.map +1 -1
  34. package/dist/pipeline/src/pipeline/gitlab/createGitlabJobs.js.map +1 -1
  35. package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js.map +1 -1
  36. package/dist/pipeline/src/types/config.d.ts +1 -1
  37. package/dist/pipeline/src/types/jobs.d.ts +1 -1
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +2 -2
  40. package/src/apps/catci/commands/security/auditDocument.ts +4 -4
  41. package/src/apps/catci/commands/security/commands.ts +14 -14
  42. package/src/apps/catci/commands/security/createSecurityAuditMergeRequest.ts +9 -9
  43. package/src/apps/catci/commands/security/evaluateSecurityAudit.ts +2 -2
  44. package/src/apps/catci/commands/security/topics.json +8 -16
  45. package/src/apps/catenv/catenv.ts +8 -7
  46. package/src/apps/catenv/printVariables.ts +3 -3
  47. package/src/apps/catenv/utils.ts +4 -4
  48. package/src/apps/catenv/writeDotEnvFiles.ts +1 -1
  49. package/src/apps/catenv/writeEnvDTs.ts +3 -3
  50. package/src/apps/cli/cli.ts +1 -1
  51. package/src/apps/cli/commands/cloudSQL/commandRestoreDb.ts +1 -1
  52. package/src/apps/cli/commands/general/index.ts +2 -2
  53. package/src/apps/cli/commands/general/namespaceAutoCompletion.ts +1 -1
  54. package/src/apps/cli/commands/mongodb/projectMongoDestroyMember.ts +11 -11
  55. package/src/apps/cli/commands/mongodb/projectMongoGetShell.ts +3 -4
  56. package/src/apps/cli/commands/mongodb/projectMongoPortForward.ts +3 -4
  57. package/src/apps/cli/commands/mongodb/utils/index.ts +8 -10
  58. package/src/apps/cli/commands/project/cloudSql/commandProjectRestoreDb.ts +6 -6
  59. package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +7 -7
  60. package/src/apps/cli/commands/project/commandConfigSecrets.ts +22 -22
  61. package/src/apps/cli/commands/project/commandDeletePods.ts +1 -1
  62. package/src/apps/cli/commands/project/commandDeleteProject.ts +1 -1
  63. package/src/apps/cli/commands/project/commandEnvVars.ts +1 -1
  64. package/src/apps/cli/commands/project/commandGetMyTotalWorktime.ts +1 -1
  65. package/src/apps/cli/commands/project/commandGetShell.ts +1 -1
  66. package/src/apps/cli/commands/project/commandGitlabCi.ts +4 -4
  67. package/src/apps/cli/commands/project/commandListPods.ts +2 -2
  68. package/src/apps/cli/commands/project/commandMigrateHelm3.ts +6 -6
  69. package/src/apps/cli/commands/project/commandNamespace.ts +1 -1
  70. package/src/apps/cli/commands/project/commandOpenCostDashboard.ts +2 -2
  71. package/src/apps/cli/commands/project/commandOpenDashboard.ts +1 -1
  72. package/src/apps/cli/commands/project/commandOpenGit.ts +1 -1
  73. package/src/apps/cli/commands/project/commandOpenGrafana.ts +2 -2
  74. package/src/apps/cli/commands/project/commandOpenGrafanaPod.ts +2 -2
  75. package/src/apps/cli/commands/project/commandOpenLogs.ts +1 -1
  76. package/src/apps/cli/commands/project/commandPauseProject.ts +1 -1
  77. package/src/apps/cli/commands/project/commandSecretsClearBackups.ts +1 -1
  78. package/src/apps/cli/commands/project/commandSecurityEvaluate.ts +2 -2
  79. package/src/apps/cli/commands/project/commandSetup.ts +1 -1
  80. package/src/apps/cli/commands/project/setup/index.ts +1 -1
  81. package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +5 -6
  82. package/src/apps/cli/commands/project/setup/setupCloudRun.ts +5 -5
  83. package/src/apps/cli/commands/project/setup/setupContext.ts +4 -4
  84. package/src/apps/cli/commands/project/setup/setupKubernetes.ts +14 -14
  85. package/src/apps/cli/commands/project/setup/setupTopic.ts +4 -9
  86. package/src/apps/cli/commands/project/utils/autocompletions.ts +1 -1
  87. package/src/apps/cli/commands/project/utils/ensureCluster.ts +2 -2
  88. package/src/apps/cli/commands/project/utils/ensureNamespace.ts +5 -5
  89. package/src/apps/cli/utils/getGoogleAuthUserNumber.ts +1 -1
  90. package/src/config/getProjectConfig.ts +11 -11
  91. package/src/gcloud/artifactsRegistry.ts +1 -1
  92. package/src/gcloud/cloudRun/getCloudRunDomainSuffix.ts +2 -2
  93. package/src/gcloud/cloudRun/openCloudRunDashboards.ts +2 -2
  94. package/src/gcloud/cloudSql/copyDb.ts +1 -1
  95. package/src/gcloud/cloudSql/startProxy.ts +7 -7
  96. package/src/gcloud/enableServices.ts +2 -2
  97. package/src/gcloud/openDashboard.ts +1 -1
  98. package/src/gcloud/serviceAccounts.ts +8 -8
  99. package/src/kubernetes/index.ts +1 -1
  100. package/src/kubernetes/openKubernetesDashboards.ts +2 -2
  101. package/src/kubernetes/portForward.ts +2 -2
  102. package/src/types/child-process-promise.d.ts +3 -3
  103. package/src/utils/editAsFile.ts +2 -2
  104. package/src/utils/gitlab.ts +43 -27
  105. package/src/utils/log.ts +1 -1
  106. package/src/utils/portForwards.ts +1 -1
  107. package/src/utils/promise.ts +7 -5
@@ -42,7 +42,7 @@ export const getGitlabToken = async (vorpal: CommandInstance | null) => {
42
42
  if (!(await hasGitlabToken())) {
43
43
  if (!vorpal) {
44
44
  console.error(
45
- "⚠️ gitlab token missing, please run catladder to set it up"
45
+ "⚠️ gitlab token missing, please run catladder to set it up",
46
46
  );
47
47
  process.exit(1);
48
48
  }
@@ -56,7 +56,7 @@ export const doGitlabRequest = async <T = any>(
56
56
  vorpal: CommandInstance | null,
57
57
  path: string,
58
58
  data: any = undefined,
59
- method: Method = "GET"
59
+ method: Method = "GET",
60
60
  ): Promise<T> => {
61
61
  const rootToken = await getGitlabToken(vorpal);
62
62
 
@@ -84,23 +84,23 @@ export const doGitlabRequest = async <T = any>(
84
84
  throw new Error(
85
85
  `Could not send request to gitlab api ${path}: ${result.status} "${
86
86
  result.statusText
87
- }".\nResponse: ${JSON.stringify(await result.json(), null, 2)}`
87
+ }".\nResponse: ${JSON.stringify(await result.json(), null, 2)}`,
88
88
  );
89
89
  };
90
90
 
91
91
  export const getProjectInfo = async (
92
- vorpal: CommandInstance | null
92
+ vorpal: CommandInstance | null,
93
93
  ): Promise<{ id: string; web_url: string }> => {
94
94
  const gitRemoteOriginUrl = (
95
95
  await exec("git config --get remote.origin.url")
96
96
  ).stdout.trim();
97
97
  const projectPath =
98
98
  /(https:\/\/|git@)git\.panter\.ch[:/]([^.]*)(\.git)?/g.exec(
99
- gitRemoteOriginUrl
99
+ gitRemoteOriginUrl,
100
100
  );
101
101
  const project = await doGitlabRequest(
102
102
  vorpal,
103
- `projects/${encodeURIComponent(projectPath[2])}`
103
+ `projects/${encodeURIComponent(projectPath[2])}`,
104
104
  );
105
105
  return project;
106
106
  };
@@ -114,28 +114,44 @@ type GitlabVariable = {
114
114
  environment_scope: string;
115
115
  };
116
116
  export const getAllVariables = memoizee(
117
- async (vorpal: CommandInstance | null): Promise<Array<GitlabVariable>> => {
117
+ async (
118
+ vorpal: CommandInstance | null,
119
+ n = 5, // how many requests to do in parallel, 5 seems a good value for many projects, ideally we would do one request in parallel per component
120
+ ): Promise<Array<GitlabVariable>> => {
118
121
  const { id } = await getProjectInfo(vorpal);
122
+
119
123
  let all: Array<GitlabVariable> = [];
120
- let result: Array<GitlabVariable>;
124
+ let result: Array<Array<GitlabVariable>> = [];
121
125
  let page = 1;
126
+
122
127
  do {
123
- result = await doGitlabRequest(
124
- vorpal,
125
- // 100 is max page size
126
- `projects/${id}/variables?per_page=100&page=${page}`
127
- );
128
- page++;
129
- all = [...all, ...result];
130
- } while (result?.length > 0);
128
+ // Create an array of promises for N pages
129
+ const promises = Array.from({ length: n }, (_, i) => {
130
+ return doGitlabRequest(
131
+ vorpal,
132
+ `projects/${id}/variables?per_page=100&page=${page + i}`,
133
+ );
134
+ });
135
+
136
+ // Wait for all promises to resolve
137
+ result = await Promise.all(promises);
138
+
139
+ // Increment the page by N
140
+ page += n;
141
+
142
+ // Flatten the result array and add it to 'all'
143
+ all = [...all, ...result.flat()];
144
+ // Continue only if the last page had results
145
+ } while (result.length > 0 && result[result.length - 1].length > 0);
146
+
131
147
  return all;
132
148
  },
133
- { promise: true }
149
+ { promise: true },
134
150
  );
135
151
 
136
152
  export const getVariableValueByRawName = async (
137
153
  vorpal: CommandInstance,
138
- rawName: string
154
+ rawName: string,
139
155
  ) => {
140
156
  const allVariables = await getAllVariables(vorpal);
141
157
  return allVariables.find((v) => v.key === rawName)?.value;
@@ -150,7 +166,7 @@ const createVariable = async (
150
166
  key: string,
151
167
  value: string,
152
168
  masked = true,
153
- environment_scope = "*"
169
+ environment_scope = "*",
154
170
  ) => {
155
171
  return await doGitlabRequest(
156
172
  vorpal,
@@ -161,7 +177,7 @@ const createVariable = async (
161
177
  masked: masked && isMaskable(value),
162
178
  environment_scope,
163
179
  },
164
- "POST"
180
+ "POST",
165
181
  );
166
182
  };
167
183
 
@@ -170,7 +186,7 @@ const updateVariable = async (
170
186
  projectId: string,
171
187
  key: string,
172
188
  value: string,
173
- masked = true
189
+ masked = true,
174
190
  ) => {
175
191
  return await doGitlabRequest(
176
192
  vorpal,
@@ -179,20 +195,20 @@ const updateVariable = async (
179
195
  value,
180
196
  masked: masked && isMaskable(value),
181
197
  },
182
- "PUT"
198
+ "PUT",
183
199
  );
184
200
  };
185
201
 
186
202
  const deleteVariable = async (
187
203
  vorpal: CommandInstance,
188
204
  projectId: string,
189
- key: string
205
+ key: string,
190
206
  ) => {
191
207
  return await doGitlabRequest(
192
208
  vorpal,
193
209
  `projects/${projectId}/variables/${key}`,
194
210
  undefined,
195
- "DELETE"
211
+ "DELETE",
196
212
  );
197
213
  };
198
214
 
@@ -233,7 +249,7 @@ const getAllCatladderEnvVarsInGitlab = async (vorpal: CommandInstance) => {
233
249
  }
234
250
 
235
251
  return acc;
236
- }, {})
252
+ }, {}),
237
253
  );
238
254
  return allVariables;
239
255
  };
@@ -260,7 +276,7 @@ export const upsertAllVariables = async (
260
276
  env: string,
261
277
  componentName: string,
262
278
  backup = true,
263
- masked = true // FIXME: would be better to have this per variable
279
+ masked = true, // FIXME: would be better to have this per variable
264
280
  ): Promise<void> => {
265
281
  const { id } = await getProjectInfo(vorpal);
266
282
 
@@ -286,7 +302,7 @@ export const upsertAllVariables = async (
286
302
  getBackupKey(fullKey, new Date().getTime()),
287
303
  oldValue,
288
304
  masked,
289
- "_backup"
305
+ "_backup",
290
306
  );
291
307
  }
292
308
  } else {
package/src/utils/log.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export const logError = (
2
2
  cmd: any,
3
3
  message: string,
4
- additionalMessage?: any
4
+ additionalMessage?: any,
5
5
  ) => {
6
6
  cmd.log("");
7
7
  cmd.log(`[ERROR] 🙀 :${message}`);
@@ -34,7 +34,7 @@ const addPortForward = (name: string, portForward: PortForward) => {
34
34
 
35
35
  export const startPortForwardCommand = async (
36
36
  name: string,
37
- command: string
37
+ command: string,
38
38
  ) => {
39
39
  // stop if already there
40
40
  await stopPortForward(name);
@@ -1,11 +1,13 @@
1
1
  export async function filter<T>(
2
2
  arr: T[],
3
- iterator: (item: T) => Promise<boolean>
3
+ iterator: (item: T) => Promise<boolean>,
4
4
  ) {
5
5
  const fail = Symbol("fail");
6
- return ((await Promise.all(
7
- arr.map(async item => ((await iterator(item)) ? item : fail))
8
- )).filter(i => i !== fail) as any) as Promise<T[]>;
6
+ return (
7
+ await Promise.all(
8
+ arr.map(async (item) => ((await iterator(item)) ? item : fail)),
9
+ )
10
+ ).filter((i) => i !== fail) as any as Promise<T[]>;
9
11
  }
10
12
 
11
- export const delay = (ms: number) => new Promise(res => setTimeout(res, ms));
13
+ export const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));