@catladder/cli 0.0.0-refactor-untangle-gitlab-api-requests-from-vorpal-57cf3cf2 → 0.0.0-reference-database-url-1befbbee

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 (192) hide show
  1. package/dist/bundles/catenv/index.js +2146 -23675
  2. package/dist/bundles/cli/index.js +575 -1032
  3. package/dist/cli/src/apps/cli/commands/project/commandGitlabCi.d.ts +2 -5
  4. package/dist/cli/src/apps/cli/commands/project/commandGitlabCi.js +9 -26
  5. package/dist/cli/src/apps/cli/commands/project/commandGitlabCi.js.map +1 -1
  6. package/dist/cli/src/apps/cli/commands/project/commandSetup.js +5 -3
  7. package/dist/cli/src/apps/cli/commands/project/commandSetup.js.map +1 -1
  8. package/dist/cli/src/apps/cli/commands/project/setup/index.d.ts +1 -1
  9. package/dist/cli/src/apps/cli/commands/project/setup/index.js +6 -17
  10. package/dist/cli/src/apps/cli/commands/project/setup/index.js.map +1 -1
  11. package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.d.ts +1 -4
  12. package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.js +23 -35
  13. package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -1
  14. package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.d.ts +2 -5
  15. package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js +23 -38
  16. package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -1
  17. package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.d.ts +1 -2
  18. package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.js +4 -5
  19. package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.js.map +1 -1
  20. package/dist/cli/src/apps/cli/commands/project/utils/autocompletions.d.ts +1 -0
  21. package/dist/cli/src/apps/cli/commands/project/utils/autocompletions.js +9 -1
  22. package/dist/cli/src/apps/cli/commands/project/utils/autocompletions.js.map +1 -1
  23. package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -1
  24. package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.js +11 -20
  25. package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -1
  26. package/dist/cli/src/apps/cli/verify/index.js +5 -22
  27. package/dist/cli/src/apps/cli/verify/index.js.map +1 -1
  28. package/dist/cli/src/config/getProjectConfig.d.ts +1 -1
  29. package/dist/cli/src/config/getProjectConfig.js +10 -12
  30. package/dist/cli/src/config/getProjectConfig.js.map +1 -1
  31. package/dist/cli/src/git/gitProjectInformation.d.ts +1 -14
  32. package/dist/cli/src/git/gitProjectInformation.js +2 -29
  33. package/dist/cli/src/git/gitProjectInformation.js.map +1 -1
  34. package/dist/cli/src/utils/gitlab.d.ts +23 -17
  35. package/dist/cli/src/utils/gitlab.js +161 -120
  36. package/dist/cli/src/utils/gitlab.js.map +1 -1
  37. package/dist/cli/src/utils/log.d.ts +0 -15
  38. package/dist/cli/src/utils/log.js +1 -23
  39. package/dist/cli/src/utils/log.js.map +1 -1
  40. package/dist/cli/src/utils/preferences.d.ts +4 -0
  41. package/dist/cli/src/utils/preferences.js +58 -0
  42. package/dist/cli/src/utils/preferences.js.map +1 -0
  43. package/dist/pipeline/src/build/artifacts/createBuildJobArtifact.js +3 -1
  44. package/dist/pipeline/src/build/artifacts/createBuildJobArtifact.js.map +1 -1
  45. package/dist/pipeline/src/build/base/index.d.ts +2 -3
  46. package/dist/pipeline/src/build/base/index.js.map +1 -1
  47. package/dist/pipeline/src/build/cache/getAllCacheConfigsFromConfig.js +6 -4
  48. package/dist/pipeline/src/build/cache/getAllCacheConfigsFromConfig.js.map +1 -1
  49. package/dist/pipeline/src/build/custom/buildJob.d.ts +2 -2
  50. package/dist/pipeline/src/build/custom/buildJob.js.map +1 -1
  51. package/dist/pipeline/src/build/custom/index.d.ts +2 -2
  52. package/dist/pipeline/src/build/custom/index.js.map +1 -1
  53. package/dist/pipeline/src/build/custom/testJob.d.ts +2 -2
  54. package/dist/pipeline/src/build/custom/testJob.js.map +1 -1
  55. package/dist/pipeline/src/build/docker.d.ts +4 -4
  56. package/dist/pipeline/src/build/docker.js +1 -1
  57. package/dist/pipeline/src/build/docker.js.map +1 -1
  58. package/dist/pipeline/src/build/index.d.ts +2 -2
  59. package/dist/pipeline/src/build/index.js +2 -3
  60. package/dist/pipeline/src/build/index.js.map +1 -1
  61. package/dist/pipeline/src/build/node/buildJob.d.ts +5 -3
  62. package/dist/pipeline/src/build/node/buildJob.js.map +1 -1
  63. package/dist/pipeline/src/build/node/index.d.ts +4 -4
  64. package/dist/pipeline/src/build/node/index.js.map +1 -1
  65. package/dist/pipeline/src/build/node/meteor.d.ts +2 -2
  66. package/dist/pipeline/src/build/node/meteor.js.map +1 -1
  67. package/dist/pipeline/src/build/node/yarn.d.ts +1 -1
  68. package/dist/pipeline/src/build/node/yarn.js +3 -1
  69. package/dist/pipeline/src/build/node/yarn.js.map +1 -1
  70. package/dist/pipeline/src/build/rails/build.d.ts +2 -2
  71. package/dist/pipeline/src/build/rails/build.js +0 -1
  72. package/dist/pipeline/src/build/rails/build.js.map +1 -1
  73. package/dist/pipeline/src/build/rails/index.d.ts +2 -2
  74. package/dist/pipeline/src/build/rails/index.js.map +1 -1
  75. package/dist/pipeline/src/build/rails/test.js +18 -1
  76. package/dist/pipeline/src/build/rails/test.js.map +1 -1
  77. package/dist/pipeline/src/build/sbom.d.ts +2 -2
  78. package/dist/pipeline/src/build/sbom.js +4 -1
  79. package/dist/pipeline/src/build/sbom.js.map +1 -1
  80. package/dist/pipeline/src/build/types.d.ts +8 -0
  81. package/dist/pipeline/src/build/types.js.map +1 -1
  82. package/dist/pipeline/src/context/createComponentContext.js +17 -6
  83. package/dist/pipeline/src/context/createComponentContext.js.map +1 -1
  84. package/dist/pipeline/src/context/getLabels.js +3 -1
  85. package/dist/pipeline/src/context/getLabels.js.map +1 -1
  86. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js +2 -2
  87. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js.map +1 -1
  88. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunServices.js +32 -7
  89. package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunServices.js.map +1 -1
  90. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.d.ts +1 -2
  91. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.js +3 -10
  92. package/dist/pipeline/src/deploy/cloudRun/createJobs/execute/onDeploy.js.map +1 -1
  93. package/dist/pipeline/src/deploy/cloudRun/createJobs/healthCheck.d.ts +5 -0
  94. package/dist/pipeline/src/deploy/cloudRun/createJobs/healthCheck.js +51 -0
  95. package/dist/pipeline/src/deploy/cloudRun/createJobs/healthCheck.js.map +1 -0
  96. package/dist/pipeline/src/deploy/cloudRun/index.js +7 -4
  97. package/dist/pipeline/src/deploy/cloudRun/index.js.map +1 -1
  98. package/dist/pipeline/src/deploy/cloudRun/utils/database.d.ts +21 -2
  99. package/dist/pipeline/src/deploy/cloudRun/utils/database.js +55 -6
  100. package/dist/pipeline/src/deploy/cloudRun/utils/database.js.map +1 -1
  101. package/dist/pipeline/src/deploy/cloudRun/utils/getJobOrServiceArgs.d.ts +2 -0
  102. package/dist/pipeline/src/deploy/cloudRun/utils/getJobOrServiceArgs.js +12 -0
  103. package/dist/pipeline/src/deploy/cloudRun/utils/getJobOrServiceArgs.js.map +1 -0
  104. package/dist/pipeline/src/deploy/kubernetes/kubeValues.d.ts +2 -2
  105. package/dist/pipeline/src/deploy/kubernetes/kubeValues.js +3 -1
  106. package/dist/pipeline/src/deploy/kubernetes/kubeValues.js.map +1 -1
  107. package/dist/pipeline/src/deploy/sbom.js +4 -3
  108. package/dist/pipeline/src/deploy/sbom.js.map +1 -1
  109. package/dist/pipeline/src/deploy/types/googleCloudRun.d.ts +100 -0
  110. package/dist/pipeline/src/deploy/types/googleCloudRun.js +16 -0
  111. package/dist/pipeline/src/deploy/types/googleCloudRun.js.map +1 -1
  112. package/dist/pipeline/src/pipeline/createJobsForComponent.js +3 -1
  113. package/dist/pipeline/src/pipeline/createJobsForComponent.js.map +1 -1
  114. package/dist/pipeline/src/types/config.d.ts +1 -1
  115. package/dist/pipeline/src/types/context.d.ts +6 -1
  116. package/dist/pipeline/src/types/context.js.map +1 -1
  117. package/dist/tsconfig.tsbuildinfo +1 -1
  118. package/package.json +1 -1
  119. package/src/apps/cli/commands/project/commandGitlabCi.ts +20 -58
  120. package/src/apps/cli/commands/project/commandSetup.ts +5 -3
  121. package/src/apps/cli/commands/project/setup/index.ts +9 -19
  122. package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +45 -62
  123. package/src/apps/cli/commands/project/setup/setupKubernetes.ts +32 -53
  124. package/src/apps/cli/commands/project/setup/setupTopic.ts +12 -17
  125. package/src/apps/cli/commands/project/utils/autocompletions.ts +9 -0
  126. package/src/apps/cli/utils/getGoogleAuthUserNumber.ts +18 -28
  127. package/src/apps/cli/verify/index.ts +7 -25
  128. package/src/config/getProjectConfig.ts +21 -22
  129. package/src/git/gitProjectInformation.ts +1 -31
  130. package/src/utils/gitlab.ts +247 -200
  131. package/src/utils/log.ts +0 -26
  132. package/src/utils/preferences.ts +60 -0
  133. package/dist/cli/src/utils/gitlab-without-vorpal/FetchGitLabError.d.ts +0 -18
  134. package/dist/cli/src/utils/gitlab-without-vorpal/FetchGitLabError.js +0 -32
  135. package/dist/cli/src/utils/gitlab-without-vorpal/FetchGitLabError.js.map +0 -1
  136. package/dist/cli/src/utils/gitlab-without-vorpal/FetchMethod.d.ts +0 -1
  137. package/dist/cli/src/utils/gitlab-without-vorpal/FetchMethod.js +0 -3
  138. package/dist/cli/src/utils/gitlab-without-vorpal/FetchMethod.js.map +0 -1
  139. package/dist/cli/src/utils/gitlab-without-vorpal/GitLabApiDataOptional.d.ts +0 -14
  140. package/dist/cli/src/utils/gitlab-without-vorpal/GitLabApiDataOptional.js +0 -3
  141. package/dist/cli/src/utils/gitlab-without-vorpal/GitLabApiDataOptional.js.map +0 -1
  142. package/dist/cli/src/utils/gitlab-without-vorpal/GitLabTokenMissingError.d.ts +0 -4
  143. package/dist/cli/src/utils/gitlab-without-vorpal/GitLabTokenMissingError.js +0 -12
  144. package/dist/cli/src/utils/gitlab-without-vorpal/GitLabTokenMissingError.js.map +0 -1
  145. package/dist/cli/src/utils/gitlab-without-vorpal/fetchGitLabApi.d.ts +0 -8
  146. package/dist/cli/src/utils/gitlab-without-vorpal/fetchGitLabApi.js +0 -47
  147. package/dist/cli/src/utils/gitlab-without-vorpal/fetchGitLabApi.js.map +0 -1
  148. package/dist/cli/src/utils/gitlab-without-vorpal/getGitlabHostPathToken.d.ts +0 -20
  149. package/dist/cli/src/utils/gitlab-without-vorpal/getGitlabHostPathToken.js +0 -15
  150. package/dist/cli/src/utils/gitlab-without-vorpal/getGitlabHostPathToken.js.map +0 -1
  151. package/dist/cli/src/utils/gitlab-without-vorpal/gitLabProjectByGitPath.d.ts +0 -23
  152. package/dist/cli/src/utils/gitlab-without-vorpal/gitLabProjectByGitPath.js +0 -30
  153. package/dist/cli/src/utils/gitlab-without-vorpal/gitLabProjectByGitPath.js.map +0 -1
  154. package/dist/cli/src/utils/gitlab-without-vorpal/gitLabVariables.d.ts +0 -66
  155. package/dist/cli/src/utils/gitlab-without-vorpal/gitLabVariables.js +0 -129
  156. package/dist/cli/src/utils/gitlab-without-vorpal/gitLabVariables.js.map +0 -1
  157. package/dist/cli/src/utils/gitlab-without-vorpal/index.d.ts +0 -12
  158. package/dist/cli/src/utils/gitlab-without-vorpal/index.js +0 -29
  159. package/dist/cli/src/utils/gitlab-without-vorpal/index.js.map +0 -1
  160. package/dist/cli/src/utils/gitlab-without-vorpal/insertProjectTopics.d.ts +0 -5
  161. package/dist/cli/src/utils/gitlab-without-vorpal/insertProjectTopics.js +0 -23
  162. package/dist/cli/src/utils/gitlab-without-vorpal/insertProjectTopics.js.map +0 -1
  163. package/dist/cli/src/utils/gitlab-without-vorpal/loadGitLabToken.d.ts +0 -2
  164. package/dist/cli/src/utils/gitlab-without-vorpal/loadGitLabToken.js +0 -27
  165. package/dist/cli/src/utils/gitlab-without-vorpal/loadGitLabToken.js.map +0 -1
  166. package/dist/cli/src/utils/gitlab-without-vorpal/projectAccessToken.d.ts +0 -29
  167. package/dist/cli/src/utils/gitlab-without-vorpal/projectAccessToken.js +0 -24
  168. package/dist/cli/src/utils/gitlab-without-vorpal/projectAccessToken.js.map +0 -1
  169. package/dist/cli/src/utils/gitlab-without-vorpal/storeGitLabToken.d.ts +0 -3
  170. package/dist/cli/src/utils/gitlab-without-vorpal/storeGitLabToken.js +0 -19
  171. package/dist/cli/src/utils/gitlab-without-vorpal/storeGitLabToken.js.map +0 -1
  172. package/dist/cli/src/utils/preferences/CatladderPreferences.d.ts +0 -27
  173. package/dist/cli/src/utils/preferences/CatladderPreferences.js +0 -34
  174. package/dist/cli/src/utils/preferences/CatladderPreferences.js.map +0 -1
  175. package/dist/cli/src/utils/preferences/index.d.ts +0 -11
  176. package/dist/cli/src/utils/preferences/index.js +0 -79
  177. package/dist/cli/src/utils/preferences/index.js.map +0 -1
  178. package/src/utils/gitlab-without-vorpal/FetchGitLabError.ts +0 -57
  179. package/src/utils/gitlab-without-vorpal/FetchMethod.ts +0 -1
  180. package/src/utils/gitlab-without-vorpal/GitLabApiDataOptional.ts +0 -14
  181. package/src/utils/gitlab-without-vorpal/GitLabTokenMissingError.ts +0 -7
  182. package/src/utils/gitlab-without-vorpal/fetchGitLabApi.ts +0 -74
  183. package/src/utils/gitlab-without-vorpal/getGitlabHostPathToken.ts +0 -31
  184. package/src/utils/gitlab-without-vorpal/gitLabProjectByGitPath.ts +0 -57
  185. package/src/utils/gitlab-without-vorpal/gitLabVariables.ts +0 -290
  186. package/src/utils/gitlab-without-vorpal/index.ts +0 -12
  187. package/src/utils/gitlab-without-vorpal/insertProjectTopics.ts +0 -35
  188. package/src/utils/gitlab-without-vorpal/loadGitLabToken.ts +0 -29
  189. package/src/utils/gitlab-without-vorpal/projectAccessToken.ts +0 -86
  190. package/src/utils/gitlab-without-vorpal/storeGitLabToken.ts +0 -23
  191. package/src/utils/preferences/CatladderPreferences.ts +0 -51
  192. package/src/utils/preferences/index.ts +0 -103
@@ -1,290 +0,0 @@
1
- import memoizee from "memoizee";
2
- import { times } from "lodash";
3
-
4
- import type { LoggerCmdInstance } from "../log";
5
- import { fetchGitLabApi } from "./fetchGitLabApi";
6
- import type { GitLabApiDataOptional } from "./GitLabApiDataOptional";
7
- import { getGitLabHostPathToken } from "./getGitlabHostPathToken";
8
- import { getGitLabProjectId } from "./gitLabProjectByGitPath";
9
- import { GitLabTokenMissingError } from "./GitLabTokenMissingError";
10
-
11
- /**
12
- * @see {@link https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js#L20}
13
- */
14
- const maskableRegex = new RegExp("^[a-zA-Z0-9_+=/@:.~-]{8,}$");
15
- /**
16
- * @see {@link https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js#L20}
17
- */
18
- const isMaskable = (value: string): boolean => maskableRegex.test(value);
19
-
20
- export type GitlabVariable = {
21
- variable_type: string;
22
- key: string;
23
- value: string;
24
- hidden: boolean;
25
- protected: boolean;
26
- masked: boolean;
27
- raw: boolean;
28
- environment_scope: string;
29
- description: string | null;
30
- };
31
- const getGitLabVariable = async (
32
- {
33
- projectId,
34
- key,
35
- host,
36
- token,
37
- }: {
38
- projectId: string | number;
39
- key: string;
40
- } & Omit<GitLabApiDataOptional, "path">,
41
- logger: LoggerCmdInstance = console,
42
- ) =>
43
- fetchGitLabApi<GitlabVariable>(
44
- {
45
- resourcePath: `projects/${projectId}/variables/${key}`,
46
- host,
47
- token,
48
- },
49
- logger,
50
- );
51
-
52
- const createGitLabVariable = async (
53
- {
54
- projectId,
55
- key,
56
- value,
57
- masked = true,
58
- scope = "*",
59
- host,
60
- token,
61
- }: {
62
- projectId: string | number;
63
- key: string;
64
- value: string;
65
- masked?: boolean;
66
- scope?: string;
67
- } & Omit<GitLabApiDataOptional, "path">,
68
- logger: LoggerCmdInstance = console,
69
- ) =>
70
- fetchGitLabApi<GitlabVariable>(
71
- {
72
- resourcePath: `projects/${projectId}/variables`,
73
- method: "POST",
74
- data: {
75
- key,
76
- value,
77
- masked: masked && isMaskable(value),
78
- environment_scope: scope,
79
- },
80
- host,
81
- token,
82
- },
83
- logger,
84
- );
85
-
86
- const updateGitLabVariable = async (
87
- {
88
- projectId,
89
- key,
90
- value,
91
- masked = true,
92
- host,
93
- token,
94
- }: {
95
- projectId: string | number;
96
- key: string;
97
- value: string;
98
- masked?: boolean;
99
- } & Omit<GitLabApiDataOptional, "path">,
100
- logger: LoggerCmdInstance = console,
101
- ) =>
102
- fetchGitLabApi<GitlabVariable>(
103
- {
104
- resourcePath: `projects/${projectId}/variables/${key}`,
105
- method: "PUT",
106
- data: {
107
- value,
108
- masked: masked && isMaskable(value),
109
- },
110
- host,
111
- token,
112
- },
113
- logger,
114
- );
115
-
116
- const deleteGitLabVariable = async (
117
- {
118
- projectId,
119
- key,
120
- host,
121
- token,
122
- }: {
123
- projectId: string | number;
124
- key: string;
125
- } & Omit<GitLabApiDataOptional, "path">,
126
- logger: LoggerCmdInstance = console,
127
- ) =>
128
- fetchGitLabApi(
129
- {
130
- resourcePath: `projects/${projectId}/variables/${key}`,
131
- method: "DELETE",
132
- host,
133
- token,
134
- },
135
- logger,
136
- );
137
-
138
- const getGitlabVariablesPage = async (
139
- {
140
- projectId,
141
- page = 1,
142
- perPage = 100,
143
- host,
144
- token,
145
- }: {
146
- projectId: string | number;
147
- /**
148
- * @defaultValue 1
149
- */
150
- page?: number;
151
- /**
152
- * @defaultValue 100
153
- */
154
- perPage?: number;
155
- } & Omit<GitLabApiDataOptional, "path">,
156
- logger: LoggerCmdInstance = console,
157
- ) =>
158
- fetchGitLabApi<GitlabVariable[]>(
159
- {
160
- resourcePath: `projects/${projectId}/variables?per_page=${perPage}&page=${page}`,
161
- host,
162
- token,
163
- },
164
- logger,
165
- );
166
-
167
- export type GetAllVariablesArgs = {
168
- /**
169
- * Amount of requests in parallel to GitLab
170
- *
171
- * 5 seems a good value for many projects.
172
- * Ideally we would do one request in parallel per component.
173
- * @defaultValue 5
174
- */
175
- parallelRequests?: number;
176
- projectId?: string | number;
177
- logger?: LoggerCmdInstance;
178
- } & GitLabApiDataOptional;
179
-
180
- const getAllVariables = memoizee(
181
- async ({
182
- logger = console,
183
- parallelRequests = 5,
184
- projectId,
185
- ...existing
186
- }: GetAllVariablesArgs = {}): Promise<Array<GitlabVariable>> => {
187
- const { host, path, token } = await getGitLabHostPathToken(
188
- existing,
189
- logger,
190
- );
191
- if (!token?.length) {
192
- throw new GitLabTokenMissingError();
193
- }
194
- const id =
195
- projectId || (await getGitLabProjectId({ host, path, token }, logger));
196
-
197
- let all: GitlabVariable[] = [];
198
- let result: GitlabVariable[][] = [];
199
- let page = 1;
200
-
201
- do {
202
- // Create an array of promises for parallelRequests pages - Wait for all promises to resolve
203
- result = await Promise.all(
204
- times(parallelRequests, (i) => i + 1).map((parallelPage) =>
205
- getGitlabVariablesPage(
206
- { projectId: id, page: parallelPage, host, token },
207
- logger,
208
- ),
209
- ),
210
- );
211
-
212
- // Increment the page by parallelRequests
213
- page += parallelRequests;
214
-
215
- // Flatten the result array and add it to 'all'
216
- all = all.concat(result.flat());
217
- // Continue only if the last page had results
218
- } while (result.length > 0 && result.slice(-1)[0].length > 0);
219
-
220
- return all;
221
- },
222
- { promise: true },
223
- );
224
-
225
- type ClVarNameStart = "CL_";
226
-
227
- const getAllCatladderEnvVars = async ({
228
- logger = console,
229
- projectId,
230
- ...existing
231
- }: Omit<GetAllVariablesArgs, "parallelRequests"> = {}) => {
232
- const { host, path, token } = await getGitLabHostPathToken(existing, logger);
233
- if (!token?.length) {
234
- throw new GitLabTokenMissingError();
235
- }
236
- const id =
237
- projectId || (await getGitLabProjectId({ host, path, token }, logger));
238
-
239
- const fetchResults = await gitLabVariable.getAll({
240
- projectId: id,
241
- host,
242
- path,
243
- token,
244
- logger,
245
- });
246
- const catladderPrefixed = fetchResults.filter(({ key }) =>
247
- key.startsWith("CL_"),
248
- );
249
- const allVariables = catladderPrefixed.reduce<{
250
- [key in `${ClVarNameStart}${string}`]: { backups: number[] } & Omit<
251
- Partial<GitlabVariable>,
252
- "key"
253
- >;
254
- }>((acc, { key, value, ...rest }) => {
255
- const matchBackup = key.match(/(CL_.*)_backup_([0-9]+)/);
256
- if (matchBackup) {
257
- const key = matchBackup[1];
258
- const timestamp = Number(matchBackup[2]);
259
- const backups = [...(acc[key]?.backups ?? []), timestamp];
260
- return {
261
- ...acc,
262
- [key]: {
263
- ...(acc[key] ?? {}), // add value
264
- backups,
265
- },
266
- };
267
- }
268
-
269
- return {
270
- ...acc,
271
- [key]: {
272
- backups: [],
273
- ...(acc[key] ?? {}), // may add backups
274
- value,
275
- ...rest,
276
- },
277
- };
278
- }, {});
279
- return allVariables;
280
- };
281
-
282
- export const gitLabVariable = {
283
- get: getGitLabVariable,
284
- create: createGitLabVariable,
285
- update: updateGitLabVariable,
286
- delete: deleteGitLabVariable,
287
- getPage: getGitlabVariablesPage,
288
- getAll: getAllVariables,
289
- getAllCatladder: getAllCatladderEnvVars,
290
- };
@@ -1,12 +0,0 @@
1
- export * from "./FetchGitLabError";
2
- export * from "./FetchMethod";
3
- export * from "./GitLabApiDataOptional";
4
- export * from "./GitLabTokenMissingError";
5
- export * from "./fetchGitLabApi";
6
- export * from "./getGitlabHostPathToken";
7
- export * from "./gitLabProjectByGitPath";
8
- export * from "./gitLabVariables";
9
- export * from "./insertProjectTopics";
10
- export * from "./loadGitLabToken";
11
- export * from "./projectAccessToken";
12
- export * from "./storeGitLabToken";
@@ -1,35 +0,0 @@
1
- import type { LoggerCmdInstance } from "../log";
2
- import { fetchGitLabApi } from "./fetchGitLabApi";
3
- import { getGitLabHostPathToken } from "./getGitlabHostPathToken";
4
- import type { GitLabApiDataOptional } from "./GitLabApiDataOptional";
5
- import { gitLabProjectByGitPath } from "./gitLabProjectByGitPath";
6
- import { GitLabTokenMissingError } from "./GitLabTokenMissingError";
7
-
8
- export const insertProjectTopics = async (
9
- {
10
- topics: insertTopics,
11
- ...existing
12
- }: GitLabApiDataOptional & { topics: string[] },
13
- logger: LoggerCmdInstance = console,
14
- ) => {
15
- const { host, path, token } = await getGitLabHostPathToken(existing, logger);
16
- if (!token?.length) {
17
- throw new GitLabTokenMissingError();
18
- }
19
-
20
- const { id, topics } = await gitLabProjectByGitPath(
21
- { path, host, token },
22
- logger,
23
- );
24
-
25
- await fetchGitLabApi(
26
- {
27
- resourcePath: `projects/${id}`,
28
- data: { topics: [...insertTopics, ...topics] },
29
- method: "PUT",
30
- host,
31
- token,
32
- },
33
- logger,
34
- );
35
- };
@@ -1,29 +0,0 @@
1
- import { GitLabTokenMissingError } from "./GitLabTokenMissingError";
2
- import { storeGitLabToken } from "./storeGitLabToken";
3
- import type { LoggerCmdInstance } from "../log";
4
- import { getPreferences } from "../preferences";
5
- import { getGitRemoteHost } from "../../git";
6
-
7
- export const loadGitLabToken = async (
8
- gitlabHost?: string,
9
- logger: LoggerCmdInstance = console,
10
- ) => {
11
- const [preferences, host] = await Promise.all([
12
- getPreferences(logger),
13
- getGitRemoteHost(gitlabHost),
14
- ]);
15
- if (preferences.gitlabTokens[host]?.length) {
16
- return preferences.gitlabTokens[host];
17
- }
18
- if (preferences["gitlab-personal-access-token"]?.length) {
19
- // Add the token to the hostname based preferences
20
- return storeGitLabToken(
21
- {
22
- token: preferences["gitlab-personal-access-token"],
23
- host,
24
- },
25
- logger,
26
- );
27
- }
28
- throw new GitLabTokenMissingError();
29
- };
@@ -1,86 +0,0 @@
1
- import { format } from "date-fns";
2
- import type { LoggerCmdInstance } from "../log";
3
- import { fetchGitLabApi } from "./fetchGitLabApi";
4
- import type { GitLabApiDataOptional } from "./GitLabApiDataOptional";
5
-
6
- export type GitLabProjectAccessToken = {
7
- id: number;
8
- name: string;
9
- revoked: boolean;
10
- created_at: Date;
11
- expires_at: Date;
12
- user_id: number;
13
- last_used_at: Date;
14
- active: boolean;
15
- access_level: number;
16
- scopes: string[];
17
- token: string;
18
- };
19
-
20
- const getProjectAccessTokens = async (
21
- {
22
- projectId,
23
- path,
24
- ...existing
25
- }: { projectId: string | number } & GitLabApiDataOptional,
26
- logger: LoggerCmdInstance = console,
27
- ) =>
28
- fetchGitLabApi<GitLabProjectAccessToken[]>(
29
- { resourcePath: `projects/${projectId}/access_tokens`, ...existing },
30
- logger,
31
- );
32
-
33
- const rotate = async (
34
- {
35
- projectId,
36
- tokenId,
37
- data: { expires_at },
38
- path,
39
- ...existing
40
- }: {
41
- projectId: string | number;
42
- tokenId: number;
43
- data: Pick<GitLabProjectAccessToken, "expires_at">;
44
- } & GitLabApiDataOptional,
45
- logger: LoggerCmdInstance = console,
46
- ) =>
47
- fetchGitLabApi<GitLabProjectAccessToken>(
48
- {
49
- resourcePath: `projects/${projectId}/access_tokens/${tokenId}/rotate`,
50
- data: { expires_at: format(expires_at, "yyyy-MM-dd") },
51
- method: "POST",
52
- ...existing,
53
- },
54
- logger,
55
- );
56
-
57
- const create = async (
58
- {
59
- projectId,
60
- path,
61
- data: { expires_at, ...data },
62
- ...existing
63
- }: {
64
- projectId: string | number;
65
- data: Pick<
66
- GitLabProjectAccessToken,
67
- "access_level" | "name" | "scopes" | "expires_at"
68
- >;
69
- } & GitLabApiDataOptional,
70
- logger: LoggerCmdInstance = console,
71
- ) =>
72
- fetchGitLabApi<GitLabProjectAccessToken>(
73
- {
74
- resourcePath: `projects/${projectId}/access_tokens`,
75
- data: { expires_at: format(expires_at, "yyyy-MM-dd"), ...data },
76
- method: "POST",
77
- ...existing,
78
- },
79
- logger,
80
- );
81
-
82
- export const gitLabProjectAccessToken = {
83
- getList: getProjectAccessTokens,
84
- rotate,
85
- create,
86
- };
@@ -1,23 +0,0 @@
1
- import type { LoggerCmdInstance } from "../log";
2
- import { upsertPreferences } from "../preferences";
3
- import { GitLabTokenMissingError } from "./GitLabTokenMissingError";
4
- import type { GitLabApiDataOptional } from "./GitLabApiDataOptional";
5
- import { getGitRemoteHost } from "../../git";
6
-
7
- export const storeGitLabToken = async (
8
- { token, host }: Omit<GitLabApiDataOptional, "path">,
9
- logger: LoggerCmdInstance = console,
10
- ) => {
11
- if (typeof token !== "string" || !token.length) {
12
- throw new GitLabTokenMissingError();
13
- }
14
- const gitRemoteHost = await getGitRemoteHost(host);
15
- await upsertPreferences(
16
- {
17
- "gitlab-personal-access-token": token,
18
- gitlabTokens: { [gitRemoteHost]: token },
19
- },
20
- logger,
21
- );
22
- return token;
23
- };
@@ -1,51 +0,0 @@
1
- const gitlabPersonalAccessToken = "gitlab-personal-access-token";
2
- const googleAuthUserNumber = "googleAuthUserNumber";
3
- const gitlabTokens = "gitlabTokens";
4
- const gitLabProjectIds = "gitLabProjectIds";
5
-
6
- const preferenceKeys = [
7
- gitlabPersonalAccessToken,
8
- googleAuthUserNumber,
9
- gitlabTokens,
10
- gitLabProjectIds,
11
- ] as const;
12
-
13
- export type CatladderPreferences = {
14
- /**
15
- * @deprecated Use the hostname based `gitlabTokens` instead.
16
- */
17
- [gitlabPersonalAccessToken]: string | undefined;
18
- [googleAuthUserNumber]: string | number | undefined;
19
- /**
20
- * GitLab tokens by GitLab instance hostname.
21
- */
22
- [gitlabTokens]: { [instanceHostname in string]: string };
23
- [gitLabProjectIds]: { [hostnameProjectPath in string]: number };
24
- };
25
-
26
- const perfFallback: CatladderPreferences = {
27
- [gitlabPersonalAccessToken]: undefined,
28
- [googleAuthUserNumber]: undefined,
29
- [gitlabTokens]: {},
30
- [gitLabProjectIds]: {},
31
- };
32
-
33
- /**
34
- * Merges a partial configuration object with a fallback configuration object.
35
- * @param config - A partial configuration object of type `Partial<CatladderPreferences>`.
36
- * @param fallback - The fallback can be passed, in order to use this function for upserting as well.
37
- */
38
- export const mergeWithFallback = (
39
- config: Partial<CatladderPreferences> = {},
40
- fallback = perfFallback,
41
- ): CatladderPreferences =>
42
- preferenceKeys.reduce(
43
- (acc, key) =>
44
- Object.assign(acc, {
45
- [key]:
46
- typeof fallback[key] === "object"
47
- ? Object.assign(fallback[key], config[key] ?? {})
48
- : (config[key] ?? fallback[key]),
49
- }),
50
- {} as CatladderPreferences,
51
- );
@@ -1,103 +0,0 @@
1
- import { existsSync } from "fs";
2
- import { writeFile, readFile, mkdir, cp, chmod } from "fs/promises";
3
- import { homedir } from "os";
4
- import { join } from "path/posix";
5
- import { parse, stringify } from "yaml";
6
- import {
7
- mergeWithFallback,
8
- type CatladderPreferences,
9
- } from "./CatladderPreferences";
10
- import type { LoggerCmdInstance } from "../log";
11
- import { logError } from "../log";
12
-
13
- export { type CatladderPreferences } from "./CatladderPreferences";
14
-
15
- const legacyDir = join(homedir(), ".catladder");
16
- const legacyPath = join(legacyDir, "preferences.yml");
17
-
18
- const configDir = join(homedir(), ".config/catladder");
19
- const configPath = join(configDir, "preferences.yml");
20
- const legacyBackupPath = join(configDir, "old_preferences_backup.yml");
21
-
22
- const encoding = "utf-8";
23
- const mode = 0o600;
24
-
25
- const readPerfString = () => readFile(configPath, { encoding });
26
- const writePerfString = (str: string) =>
27
- writeFile(configPath, str, { encoding, mode });
28
-
29
- const isConfigPath = () => existsSync(configPath);
30
- const isLegacyPath = () => existsSync(legacyPath);
31
-
32
- const createDir = () => mkdir(configDir, { recursive: true, mode: 0o700 });
33
-
34
- const copyLegacyConfig = async (target = configPath) => {
35
- await cp(legacyPath, target);
36
- return chmod(target, mode);
37
- };
38
-
39
- const parseConfigString = (
40
- yamlString: string,
41
- logger: LoggerCmdInstance = console,
42
- ): CatladderPreferences => {
43
- try {
44
- return mergeWithFallback(parse(yamlString) ?? {});
45
- } catch (error) {
46
- logError(logger, "Error when trying to parse preferences", `${error}`);
47
- throw error;
48
- }
49
- };
50
-
51
- const readPreferences = async (logger: LoggerCmdInstance = console) => {
52
- const yamlContent = await readPerfString();
53
- return parseConfigString(yamlContent, logger);
54
- };
55
-
56
- const stringifyConfig = (
57
- config: Partial<CatladderPreferences> = {},
58
- logger: LoggerCmdInstance = console,
59
- ) => {
60
- try {
61
- const preferences = mergeWithFallback(config);
62
- return stringify(preferences);
63
- } catch (error) {
64
- logError(logger, "Error when trying to stringify preferences", `${error}`);
65
- throw error;
66
- }
67
- };
68
-
69
- const writePreferences = async (
70
- preferences: Partial<CatladderPreferences> = {},
71
- logger: LoggerCmdInstance = console,
72
- ) => writePerfString(stringifyConfig(preferences, logger));
73
-
74
- const ensureConfigFile = async () => {
75
- if (isConfigPath()) {
76
- return;
77
- }
78
- await createDir();
79
- if (!isLegacyPath()) {
80
- return writePreferences();
81
- }
82
- await copyLegacyConfig();
83
- return copyLegacyConfig(legacyBackupPath);
84
- };
85
-
86
- /**
87
- * Load preferences from ~/.config/catladder/preferences.yml
88
- */
89
- export const getPreferences = async (logger: LoggerCmdInstance = console) => {
90
- await ensureConfigFile();
91
- return readPreferences(logger);
92
- };
93
-
94
- /**
95
- * Add or update preference values in ~/.config/catladder/preferences.yml
96
- */
97
- export const upsertPreferences = async (
98
- preferences: Partial<CatladderPreferences> = {},
99
- logger: LoggerCmdInstance = console,
100
- ) => {
101
- const current = await getPreferences(logger);
102
- return writePreferences(mergeWithFallback(preferences, current), logger);
103
- };