@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
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "0.0.0-refactor-untangle-gitlab-api-requests-from-vorpal-57cf3cf2",
56
+ "version": "0.0.0-reference-database-url-1befbbee",
57
57
  "scripts": {
58
58
  "lint": "eslint \"src/**/*.ts\"",
59
59
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
@@ -3,12 +3,11 @@ import { last } from "lodash";
3
3
  import open from "open";
4
4
  import type { CommandInstance } from "vorpal";
5
5
  import type Vorpal from "vorpal";
6
- import type { GitLabApiDataOptional } from "../../../../utils/gitlab-without-vorpal";
7
6
  import {
8
- getGitLabHostPathToken,
9
- getGitLabProjectId,
10
- } from "../../../../utils/gitlab-without-vorpal";
11
- import { doGitlabRequest, getGitlabToken } from "../../../../utils/gitlab";
7
+ doGitlabRequest,
8
+ getGitlabToken,
9
+ getProjectInfo,
10
+ } from "../../../../utils/gitlab";
12
11
 
13
12
  const statusEmojiMap: any = {
14
13
  failed: "🙀",
@@ -34,23 +33,8 @@ const getCurrentCommit = async () => {
34
33
  const delay = async (ms: any) =>
35
34
  new Promise((resolve) => setTimeout(resolve, ms));
36
35
 
37
- const promptJob = async (
38
- vorpal: CommandInstance,
39
- projectId: any,
40
- ctx: any,
41
- existing: GitLabApiDataOptional = {},
42
- ) => {
43
- const {
44
- host,
45
- path,
46
- token: inputToken,
47
- } = await getGitLabHostPathToken(existing, vorpal);
48
- const token = inputToken || (await getGitlabToken(vorpal, host));
49
- const jobs = await doGitlabRequest(vorpal, {
50
- path: `projects/${projectId}/jobs`,
51
- host,
52
- token,
53
- });
36
+ const promptJob = async (vorpal: CommandInstance, projectId: any, ctx: any) => {
37
+ const jobs = await doGitlabRequest(vorpal, `projects/${projectId}/jobs`);
54
38
 
55
39
  const commitId = await getCurrentCommit();
56
40
 
@@ -81,53 +65,33 @@ const promptJob = async (
81
65
  return jobs.find((j: any) => j.id === jobId);
82
66
  };
83
67
 
84
- const commandGitlabCi = async (
85
- vorpal: Vorpal,
86
- {
87
- projectId,
88
- ...existing
89
- }: GitLabApiDataOptional & { projectId?: number | string } = {},
90
- ) => {
68
+ export default async (vorpal: Vorpal) => {
91
69
  vorpal.command("project-ci-job-open", "Open a Job").action(async function () {
92
- const {
93
- host,
94
- path,
95
- token: inputToken,
96
- } = await getGitLabHostPathToken(existing, vorpal);
97
- const token = inputToken || (await getGitlabToken(this, host));
98
- const id =
99
- projectId || (await getGitLabProjectId({ host, path, token }, vorpal));
100
-
101
- const job = await promptJob(this, id, this, { host, path, token });
70
+ const { id: projectId } = await getProjectInfo(this);
71
+
72
+ const job = await promptJob(this, projectId, this);
102
73
  open(job.web_url);
103
74
  });
104
75
 
105
76
  vorpal
106
77
  .command("project-ci-job-log", "Show a job's log")
107
78
  .action(async function () {
108
- const {
109
- host,
110
- path,
111
- token: inputToken,
112
- } = await getGitLabHostPathToken(existing, vorpal);
113
- const token = inputToken || (await getGitlabToken(this, host));
114
- const apiData = { host, path, token };
115
- const pId =
116
- projectId || (await getGitLabProjectId({ host, path, token }, vorpal));
117
-
118
- const { id } = await promptJob(this, pId, this, apiData);
79
+ const { id: projectId } = await getProjectInfo(this);
80
+
81
+ const { id } = await promptJob(this, projectId, this);
119
82
 
120
83
  let finished = false;
121
84
  while (!finished) {
122
85
  const trace = await exec(
123
- `curl -s --header "PRIVATE-TOKEN: ${token}" "https://git.panter.ch/api/v4/projects/${pId}/jobs/${id}/trace"`,
86
+ `curl -s --header "PRIVATE-TOKEN: ${await getGitlabToken(
87
+ this,
88
+ )}" "https://git.panter.ch/api/v4/projects/${projectId}/jobs/${id}/trace"`,
124
89
  );
125
90
 
126
- const job = await doGitlabRequest(this, {
127
- path: `projects/${pId}/jobs/${id}`,
128
- host,
129
- token,
130
- });
91
+ const job = await doGitlabRequest(
92
+ this,
93
+ `projects/${projectId}/jobs/${id}`,
94
+ );
131
95
 
132
96
  if (trace.stdout) {
133
97
  vorpal.ui.redraw(`${trace.stdout}`);
@@ -149,5 +113,3 @@ const commandGitlabCi = async (
149
113
  }
150
114
  });
151
115
  };
152
-
153
- export default commandGitlabCi;
@@ -1,12 +1,14 @@
1
1
  import type Vorpal from "vorpal";
2
2
  import { setupProject } from "./setup";
3
+ import { allComponents } from "./utils/autocompletions";
3
4
 
4
5
  export default async (vorpal: Vorpal) =>
5
6
  vorpal
6
7
  .command(
7
- "project-setup",
8
+ "project-setup [component]",
8
9
  "Initializes all environments and creates requires resources, service accounts, etc.",
9
10
  )
10
- .action(async function () {
11
- await setupProject(this);
11
+ .autocomplete(await allComponents())
12
+ .action(async function ({ component }) {
13
+ await setupProject(this, component);
12
14
  });
@@ -1,34 +1,24 @@
1
1
  import type { CommandInstance } from "vorpal";
2
2
  import { getAllPipelineContexts } from "../../../../../config/getProjectConfig";
3
- import { projectConfigSecrets } from "../commandConfigSecrets";
4
3
  import { setupAccessTokens } from "./setupAccessTokens";
5
4
  import { setupContext } from "./setupContext";
6
5
  import { setupTopic } from "./setupTopic";
7
6
 
8
- export const setupProject = async (instance: CommandInstance) => {
9
- const allContext = await getAllPipelineContexts();
10
-
7
+ export const setupProject = async (
8
+ instance: CommandInstance,
9
+ onlyComponents?: string | string[],
10
+ ) => {
11
+ const allContext = await getAllPipelineContexts(onlyComponents);
12
+ instance.log("will setup those contexts:");
13
+ allContext.forEach((context) => {
14
+ instance.log(` - ${context.name}:${context.env}`);
15
+ });
11
16
  for (const context of allContext) {
12
17
  await setupContext(instance, context);
13
18
  }
14
19
  await setupAccessTokens(instance);
15
20
  await setupTopic(instance);
16
21
  instance.log("");
17
- const { configSecrets } = await instance.prompt({
18
- default: true,
19
- message: "Before deployments work, you need to config secrets. Do it now?",
20
- name: "configSecrets",
21
- type: "confirm",
22
- });
23
- instance.log("");
24
- if (configSecrets) {
25
- await projectConfigSecrets(instance);
26
- } else {
27
- instance.log(
28
- "👆 don't forget to config secret using `project-config-secrets`",
29
- );
30
- }
31
- instance.log("");
32
22
  instance.log("gitlab is ready! 🥂");
33
23
  instance.log("\n");
34
24
  instance.log("do not forget to make sure that:");
@@ -1,87 +1,70 @@
1
1
  import type { CommandInstance } from "vorpal";
2
- import { add } from "date-fns";
3
- import {
4
- getGitLabHostPathToken,
5
- gitLabProjectAccessToken,
6
- type GitLabApiDataOptional,
7
- gitLabVariable,
8
- FetchGitLabError,
9
- getGitLabProjectId,
10
- } from "../../../../../utils/gitlab-without-vorpal";
11
- import { getGitlabToken } from "../../../../../utils/gitlab";
2
+ import { add, format } from "date-fns";
3
+ import { doGitlabRequest, getProjectInfo } from "../../../../../utils/gitlab";
12
4
 
13
5
  const TOKEN_NAME = "semantic-release";
14
6
 
15
- export const setupAccessTokens = async (
16
- vorpal: CommandInstance,
17
- {
18
- projectId,
19
- ...existing
20
- }: GitLabApiDataOptional & { projectId?: number | string } = {},
21
- ) => {
22
- const {
23
- host,
24
- path,
25
- token: inputToken,
26
- } = await getGitLabHostPathToken(existing, vorpal);
27
- const token = inputToken || (await getGitlabToken(vorpal, host));
28
- const id =
29
- projectId || (await getGitLabProjectId({ host, path, token }, vorpal));
7
+ export const setupAccessTokens = async (instance: CommandInstance) => {
8
+ const { id: projectId } = await getProjectInfo(instance);
30
9
 
31
- const projectTokens = await gitLabProjectAccessToken.getList(
32
- { projectId: id, token, host },
33
- vorpal,
10
+ const projectTokens = await doGitlabRequest(
11
+ instance,
12
+ `projects/${projectId}/access_tokens`,
34
13
  );
35
- const accessToken = projectTokens.find(
14
+ const token = projectTokens.find(
36
15
  (t) => t.name === TOKEN_NAME && t.active === true,
37
16
  );
38
17
 
39
- const expires_at = add(new Date(), { years: 1, days: -1 });
18
+ const expires_at = format(
19
+ add(new Date(), { years: 1, days: -1 }),
20
+ "yyyy-MM-dd",
21
+ );
40
22
 
41
- const newToken = accessToken
42
- ? await gitLabProjectAccessToken.rotate(
43
- {
44
- projectId: id,
45
- tokenId: accessToken.id,
46
- token,
47
- host,
48
- data: { expires_at },
49
- },
50
- vorpal,
23
+ const newToken = token
24
+ ? await doGitlabRequest(
25
+ instance,
26
+ `projects/${projectId}/access_tokens/${token.id}/rotate`,
27
+ { expires_at },
28
+ "POST",
51
29
  )
52
- : await gitLabProjectAccessToken.create(
30
+ : await doGitlabRequest(
31
+ instance,
32
+ `projects/${projectId}/access_tokens`,
53
33
  {
54
- projectId: id,
55
- token,
56
- host,
57
- data: {
58
- expires_at,
59
- name: TOKEN_NAME,
60
- scopes: ["api", "read_repository"],
61
- access_level: 40, // Maintainer
62
- },
34
+ name: TOKEN_NAME,
35
+ scopes: ["api", "read_repository"],
36
+ access_level: 40, // Maintainer
37
+ expires_at,
63
38
  },
64
- vorpal,
39
+ "POST",
65
40
  );
66
41
 
67
- const fetchCommon = { key: "GL_TOKEN", projectId: id, host, token };
68
42
  try {
69
- await gitLabVariable.get(fetchCommon, vorpal);
70
- await gitLabVariable.update(
71
- { ...fetchCommon, value: newToken.token },
72
- vorpal,
43
+ await doGitlabRequest(instance, `projects/${projectId}/variables/GL_TOKEN`);
44
+ await doGitlabRequest(
45
+ instance,
46
+ `projects/${projectId}/variables/GL_TOKEN`,
47
+ { value: newToken.token },
48
+ "PUT",
73
49
  );
74
50
  } catch (e) {
75
- if (!(e instanceof FetchGitLabError)) throw e;
76
- if (e.status !== 404) throw e;
51
+ if (e.message !== "not found") {
52
+ throw e;
53
+ }
77
54
  // not found
78
- await gitLabVariable.create(
79
- { ...fetchCommon, value: newToken.token, masked: true },
80
- vorpal,
55
+ await doGitlabRequest(
56
+ instance,
57
+ `projects/${projectId}/variables`,
58
+ {
59
+ key: "GL_TOKEN",
60
+ value: newToken.token,
61
+ masked: true,
62
+ },
63
+ "POST",
81
64
  );
82
65
  }
83
66
 
84
- vorpal.log(
67
+ instance.log(
85
68
  "Token configured for semantic release. Renew me again in a year!",
86
69
  );
87
70
  };
@@ -1,87 +1,68 @@
1
- import { exec } from "child-process-promise";
2
- import type { CommandInstance } from "vorpal";
3
-
1
+ import type { ComponentContext } from "@catladder/pipeline";
4
2
  import {
5
- type ComponentContext,
6
3
  getFullKubernetesClusterName,
7
4
  isOfDeployType,
8
5
  } from "@catladder/pipeline";
9
- import ensureNamespace from "../utils/ensureNamespace";
10
- import type { GitLabApiDataOptional } from "../../../../../utils/gitlab-without-vorpal";
11
- import {
12
- getGitLabHostPathToken,
13
- getGitLabProjectId,
14
- } from "../../../../../utils/gitlab-without-vorpal";
6
+ import type { CommandInstance } from "vorpal";
7
+ import { exec } from "child-process-promise";
8
+ import { connectToCluster } from "../../../../../utils/cluster";
15
9
  import {
16
10
  doGitlabRequest,
17
- getGitlabToken,
11
+ getProjectInfo,
18
12
  upsertAllVariables,
19
13
  } from "../../../../../utils/gitlab";
20
- import { connectToCluster } from "../../../../../utils/cluster";
14
+ import ensureNamespace from "../utils/ensureNamespace";
21
15
 
22
16
  export const setupKubernetes = async (
23
- vorpal: CommandInstance,
17
+ instance: CommandInstance,
24
18
  context: ComponentContext,
25
- {
26
- projectId,
27
- ...existing
28
- }: GitLabApiDataOptional & { projectId?: number | string } = {},
29
19
  ) => {
30
20
  const deployConfig = context.deploy?.config;
31
21
  if (!isOfDeployType(deployConfig, "kubernetes")) {
32
22
  throw new Error("cannot run setupKubernetes on non-kubernetes deployments");
33
23
  }
34
- const {
35
- host,
36
- path,
37
- token: inputToken,
38
- } = await getGitLabHostPathToken(existing, vorpal);
39
- const token = inputToken || (await getGitlabToken(vorpal, host));
40
- const id =
41
- projectId || (await getGitLabProjectId({ host, path, token }, vorpal));
42
- const requestInfo = { host, path, token, projectId: id };
43
- const deploy_tokens = await doGitlabRequest(vorpal, {
44
- path: `projects/${id}/deploy_tokens`,
45
- host,
46
- token,
47
- });
24
+
25
+ const { id: projectId } = await getProjectInfo(instance);
26
+ const deploy_tokens = await doGitlabRequest(
27
+ instance,
28
+ `projects/${projectId}/deploy_tokens`,
29
+ );
48
30
 
49
31
  if (
50
32
  !deploy_tokens.find(
51
33
  (v: { name: string }) => v.name === "gitlab-deploy-token",
52
34
  )
53
35
  ) {
54
- vorpal.log(
36
+ instance.log(
55
37
  "I will setup the 'GitLab Deploy Token', so Kubernetes can pull images from this project.",
56
38
  );
57
39
 
58
- await doGitlabRequest(vorpal, {
59
- path: `projects/${id}/deploy_tokens`,
60
- data: {
61
- id,
40
+ await doGitlabRequest(
41
+ instance,
42
+ `projects/${projectId}/deploy_tokens`,
43
+ {
44
+ id: projectId,
62
45
  name: "gitlab-deploy-token",
63
46
  scopes: ["read_registry"],
64
47
  },
65
- method: "POST",
66
- host,
67
- token,
68
- });
48
+ "POST",
49
+ );
69
50
  }
70
51
 
71
52
  const fullName = getFullKubernetesClusterName(deployConfig.cluster);
72
- vorpal.log(`cluster: ${fullName}`);
53
+ instance.log(`cluster: ${fullName}`);
73
54
 
74
55
  await connectToCluster(fullName);
75
- vorpal.log("");
76
- vorpal.log("ensuring namespace ...");
56
+ instance.log("");
57
+ instance.log("ensuring namespace ...");
77
58
  const namespace = await ensureNamespace(context);
78
- vorpal.log("Namespace " + namespace + " created / updated!");
79
- vorpal.log("");
59
+ instance.log("Namespace " + namespace + " created / updated!");
60
+ instance.log("");
80
61
  //$.verbose = true;
81
62
 
82
63
  // we name the service account and the role and the role binding with the same name
83
64
  // we currently create one per component to better separate them
84
- vorpal.log("ensuring service accounts...");
65
+ instance.log("ensuring service accounts...");
85
66
  const serviceAccountName = `cl-${context.name}-deploy`;
86
67
  const KUBE_URL = await exec(
87
68
  `TERM=dumb kubectl cluster-info | grep -E 'Kubernetes master|Kubernetes control plane' | awk '/http/ {print $NF}'`,
@@ -174,19 +155,17 @@ EOF
174
155
  );
175
156
  }
176
157
 
177
- vorpal.log("service accounts created / updated!");
158
+ instance.log("service accounts created / updated!");
178
159
 
179
- vorpal.log("");
180
- vorpal.log("pusing secrets to gitlab...");
160
+ instance.log("");
161
+ instance.log("pusing secrets to gitlab...");
181
162
 
182
163
  await upsertAllVariables(
183
- vorpal,
164
+ instance,
184
165
  vars,
185
166
  context.env,
186
167
  context.name,
187
168
  false, // no backup
188
- undefined,
189
- requestInfo,
190
169
  );
191
- vorpal.log("done!");
170
+ instance.log("done!");
192
171
  };
@@ -1,22 +1,17 @@
1
1
  import type { CommandInstance } from "vorpal";
2
- import type { GitLabApiDataOptional } from "../../../../../utils/gitlab-without-vorpal";
3
- import {
4
- getGitLabHostPathToken,
5
- insertProjectTopics,
6
- } from "../../../../../utils/gitlab-without-vorpal";
7
- import { getGitlabToken } from "../../../../../utils/gitlab";
2
+ import { doGitlabRequest, getProjectInfo } from "../../../../../utils/gitlab";
8
3
 
9
4
  const catladderTopic = "catladder";
10
5
 
11
- export const setupTopic = async (
12
- vorpal: CommandInstance,
13
- existing: GitLabApiDataOptional = {},
14
- ) => {
15
- const {
16
- host,
17
- path,
18
- token: inputToken,
19
- } = await getGitLabHostPathToken(existing, vorpal);
20
- const token = inputToken || (await getGitlabToken(vorpal, host));
21
- return insertProjectTopics({ topics: [catladderTopic], token, host }, vorpal);
6
+ export const setupTopic = async (instance: CommandInstance) => {
7
+ const { id: projectId } = await getProjectInfo(instance);
8
+
9
+ const { topics } = await doGitlabRequest(instance, `projects/${projectId}`);
10
+
11
+ await doGitlabRequest(
12
+ instance,
13
+ `projects/${projectId}`,
14
+ { topics: [catladderTopic, ...topics] },
15
+ "PUT",
16
+ );
22
17
  };
@@ -12,6 +12,15 @@ export const allEnvs = async () => {
12
12
  return getAllEnvsInAllComponents(config);
13
13
  };
14
14
 
15
+ export const allComponents = async () => {
16
+ const config = await getProjectConfig();
17
+ if (!config) {
18
+ return [];
19
+ }
20
+
21
+ return Object.keys(config.components);
22
+ };
23
+
15
24
  export const envAndComponents = async () => {
16
25
  const allEnvAndcomponents = await getAllComponentsWithAllEnvsFlat();
17
26
 
@@ -1,33 +1,23 @@
1
- import { logError, logLines } from "../../../utils/log";
2
- import { getPreferences, upsertPreferences } from "../../../utils/preferences";
1
+ import {
2
+ getPreference,
3
+ hasPreference,
4
+ setPreference,
5
+ } from "../../../utils/preferences";
3
6
 
7
+ const KEY = "googleAuthUserNumber";
4
8
  export const getGoogleAuthUserNumber = async function () {
5
- const preferences = await getPreferences(this);
6
- if (
7
- typeof preferences.googleAuthUserNumber === "number" ||
8
- typeof preferences.googleAuthUserNumber === "string"
9
- ) {
10
- return preferences.googleAuthUserNumber;
11
- }
12
- logLines(
13
- this,
14
- "Please type in your google auth user number (0 if you have only one google account or maybe 1 if you have multiple)",
15
- );
9
+ if (!(await hasPreference(KEY))) {
10
+ this.log(
11
+ "Please type in your google auth user number (0 if you have only one google account or maybe 1 if you have multiple)",
12
+ );
16
13
 
17
- const { authUserNumber: googleAuthUserNumber } = await this.prompt({
18
- type: "number",
19
- name: "authUserNumber",
20
- default: "0",
21
- message: "Auth user ",
22
- });
23
- if (
24
- typeof googleAuthUserNumber === "number" ||
25
- (typeof googleAuthUserNumber === "string" &&
26
- googleAuthUserNumber.length > 0)
27
- ) {
28
- await upsertPreferences({ googleAuthUserNumber }, this);
29
- return googleAuthUserNumber;
14
+ const { authUserNumber } = await this.prompt({
15
+ type: "number",
16
+ name: "authUserNumber",
17
+ default: "0",
18
+ message: "Auth user ",
19
+ });
20
+ await setPreference(KEY, authUserNumber);
30
21
  }
31
- logError(this, "google auth user number input missing!");
32
- process.exit(1);
22
+ return getPreference(KEY);
33
23
  };
@@ -1,32 +1,14 @@
1
1
  import type Vorpal from "vorpal";
2
2
 
3
- import { setupGitlabToken } from "../../../utils/gitlab";
4
- import { getPreferences, upsertPreferences } from "../../../utils/preferences";
5
- import { getGitRemoteHostAndPath } from "../../../git";
3
+ import { hasGitlabToken, setupGitlabToken } from "../../../utils/gitlab";
6
4
 
7
5
  export const verify = async (vorpal: Vorpal) => {
8
- const [preferences, { gitRemoteHost }] = await Promise.all([
9
- getPreferences(vorpal),
10
- getGitRemoteHostAndPath(),
11
- ]);
12
6
  // check if has all settings
13
- if (preferences.gitlabTokens[gitRemoteHost]?.length) {
14
- return;
15
- }
16
- if (preferences["gitlab-personal-access-token"]?.length) {
17
- // Add the token to the hostname based preferences
18
- await upsertPreferences(
19
- {
20
- gitlabTokens: {
21
- [gitRemoteHost]: preferences["gitlab-personal-access-token"],
22
- },
23
- },
24
- vorpal,
25
- );
26
- return;
7
+
8
+ if (!(await hasGitlabToken())) {
9
+ vorpal.command("setup-gitlab-token").action(async function () {
10
+ await setupGitlabToken(this);
11
+ });
12
+ vorpal.exec("setup-gitlab-token");
27
13
  }
28
- vorpal.command("setup-gitlab-token").action(async function () {
29
- await setupGitlabToken(this, gitRemoteHost);
30
- });
31
- vorpal.exec("setup-gitlab-token");
32
14
  };