@catladder/cli 0.0.0-test4 → 1.0.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 (288) hide show
  1. package/.nvmrc +1 -1
  2. package/bin/catenv +3 -0
  3. package/bin/catladder +1 -1
  4. package/dist/apps/catenv/catenv.d.ts +2 -0
  5. package/dist/apps/catenv/catenv.js +135 -0
  6. package/dist/apps/catenv/catenv.js.map +1 -0
  7. package/dist/apps/cli/cli.d.ts +2 -0
  8. package/dist/apps/cli/cli.js +81 -0
  9. package/dist/apps/cli/cli.js.map +1 -0
  10. package/dist/apps/cli/commands/general/index.d.ts +4 -0
  11. package/dist/apps/cli/commands/general/index.js +274 -0
  12. package/dist/apps/cli/commands/general/index.js.map +1 -0
  13. package/dist/apps/cli/commands/general/namespaceAutoCompletion.d.ts +3 -0
  14. package/dist/apps/cli/commands/general/namespaceAutoCompletion.js +56 -0
  15. package/dist/apps/cli/commands/general/namespaceAutoCompletion.js.map +1 -0
  16. package/dist/apps/cli/commands/general/portForward.d.ts +3 -0
  17. package/dist/apps/cli/commands/general/portForward.js +98 -0
  18. package/dist/apps/cli/commands/general/portForward.js.map +1 -0
  19. package/dist/apps/cli/commands/mongodb/index.d.ts +3 -0
  20. package/dist/apps/cli/commands/mongodb/index.js +53 -0
  21. package/dist/apps/cli/commands/mongodb/index.js.map +1 -0
  22. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.d.ts +3 -0
  23. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js +190 -0
  24. package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js.map +1 -0
  25. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.d.ts +3 -0
  26. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js +96 -0
  27. package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js.map +1 -0
  28. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.d.ts +3 -0
  29. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js +105 -0
  30. package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js.map +1 -0
  31. package/dist/apps/cli/commands/mongodb/utils/index.d.ts +13 -0
  32. package/dist/apps/cli/commands/mongodb/utils/index.js +167 -0
  33. package/dist/apps/cli/commands/mongodb/utils/index.js.map +1 -0
  34. package/dist/apps/cli/commands/project/commandCloudSqlProxy.d.ts +3 -0
  35. package/dist/apps/cli/commands/project/commandCloudSqlProxy.js +128 -0
  36. package/dist/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -0
  37. package/dist/apps/cli/commands/project/commandConfigSecrets.d.ts +3 -0
  38. package/dist/apps/cli/commands/project/commandConfigSecrets.js +254 -0
  39. package/dist/apps/cli/commands/project/commandConfigSecrets.js.map +1 -0
  40. package/dist/apps/cli/commands/project/commandCopyDB.d.ts +3 -0
  41. package/dist/apps/cli/commands/project/commandCopyDB.js +102 -0
  42. package/dist/apps/cli/commands/project/commandCopyDB.js.map +1 -0
  43. package/dist/apps/cli/commands/project/commandDeletePods.d.ts +3 -0
  44. package/dist/apps/cli/commands/project/commandDeletePods.js +119 -0
  45. package/dist/apps/cli/commands/project/commandDeletePods.js.map +1 -0
  46. package/dist/apps/cli/commands/project/commandDeleteProject.d.ts +3 -0
  47. package/dist/apps/cli/commands/project/commandDeleteProject.js +97 -0
  48. package/dist/apps/cli/commands/project/commandDeleteProject.js.map +1 -0
  49. package/dist/apps/cli/commands/project/commandEnvVars.d.ts +3 -0
  50. package/dist/apps/cli/commands/project/commandEnvVars.js +74 -0
  51. package/dist/apps/cli/commands/project/commandEnvVars.js.map +1 -0
  52. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.d.ts +3 -0
  53. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js +58 -0
  54. package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js.map +1 -0
  55. package/dist/apps/cli/commands/project/commandGetShell.d.ts +3 -0
  56. package/dist/apps/cli/commands/project/commandGetShell.js +92 -0
  57. package/dist/apps/cli/commands/project/commandGetShell.js.map +1 -0
  58. package/dist/apps/cli/commands/project/commandGitlabCi.d.ts +3 -0
  59. package/dist/apps/cli/commands/project/commandGitlabCi.js +185 -0
  60. package/dist/apps/cli/commands/project/commandGitlabCi.js.map +1 -0
  61. package/dist/apps/cli/commands/project/commandInitGitlab.d.ts +3 -0
  62. package/dist/apps/cli/commands/project/commandInitGitlab.js +245 -0
  63. package/dist/apps/cli/commands/project/commandInitGitlab.js.map +1 -0
  64. package/dist/apps/cli/commands/project/commandInitProject.d.ts +3 -0
  65. package/dist/apps/cli/commands/project/commandInitProject.js +345 -0
  66. package/dist/apps/cli/commands/project/commandInitProject.js.map +1 -0
  67. package/dist/apps/cli/commands/project/commandListPods.d.ts +3 -0
  68. package/dist/apps/cli/commands/project/commandListPods.js +78 -0
  69. package/dist/apps/cli/commands/project/commandListPods.js.map +1 -0
  70. package/dist/apps/cli/commands/project/commandMigrateHelm3.d.ts +7 -0
  71. package/dist/apps/cli/commands/project/commandMigrateHelm3.js +113 -0
  72. package/dist/apps/cli/commands/project/commandMigrateHelm3.js.map +1 -0
  73. package/dist/apps/cli/commands/project/commandNamespace.d.ts +3 -0
  74. package/dist/apps/cli/commands/project/commandNamespace.js +70 -0
  75. package/dist/apps/cli/commands/project/commandNamespace.js.map +1 -0
  76. package/dist/apps/cli/commands/project/commandOpenCostDashboard.d.ts +3 -0
  77. package/dist/apps/cli/commands/project/commandOpenCostDashboard.js +83 -0
  78. package/dist/apps/cli/commands/project/commandOpenCostDashboard.js.map +1 -0
  79. package/dist/apps/cli/commands/project/commandOpenDashboard.d.ts +3 -0
  80. package/dist/apps/cli/commands/project/commandOpenDashboard.js +92 -0
  81. package/dist/apps/cli/commands/project/commandOpenDashboard.js.map +1 -0
  82. package/dist/apps/cli/commands/project/commandOpenEnv.d.ts +3 -0
  83. package/dist/apps/cli/commands/project/commandOpenEnv.js +80 -0
  84. package/dist/apps/cli/commands/project/commandOpenEnv.js.map +1 -0
  85. package/dist/apps/cli/commands/project/commandOpenGit.d.ts +3 -0
  86. package/dist/apps/cli/commands/project/commandOpenGit.js +56 -0
  87. package/dist/apps/cli/commands/project/commandOpenGit.js.map +1 -0
  88. package/dist/apps/cli/commands/project/commandOpenGrafana.d.ts +3 -0
  89. package/dist/apps/cli/commands/project/commandOpenGrafana.js +83 -0
  90. package/dist/apps/cli/commands/project/commandOpenGrafana.js.map +1 -0
  91. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.d.ts +3 -0
  92. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js +99 -0
  93. package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js.map +1 -0
  94. package/dist/apps/cli/commands/project/commandOpenLogs.d.ts +3 -0
  95. package/dist/apps/cli/commands/project/commandOpenLogs.js +87 -0
  96. package/dist/apps/cli/commands/project/commandOpenLogs.js.map +1 -0
  97. package/dist/apps/cli/commands/project/commandPauseProject.d.ts +3 -0
  98. package/dist/apps/cli/commands/project/commandPauseProject.js +97 -0
  99. package/dist/apps/cli/commands/project/commandPauseProject.js.map +1 -0
  100. package/dist/apps/cli/commands/project/commandPortForward.d.ts +3 -0
  101. package/dist/apps/cli/commands/project/commandPortForward.js +106 -0
  102. package/dist/apps/cli/commands/project/commandPortForward.js.map +1 -0
  103. package/dist/apps/cli/commands/project/commandReloadConfig.d.ts +3 -0
  104. package/dist/apps/cli/commands/project/commandReloadConfig.js +62 -0
  105. package/dist/apps/cli/commands/project/commandReloadConfig.js.map +1 -0
  106. package/dist/apps/cli/commands/project/commandTriggerCronjob.d.ts +3 -0
  107. package/dist/apps/cli/commands/project/commandTriggerCronjob.js +144 -0
  108. package/dist/apps/cli/commands/project/commandTriggerCronjob.js.map +1 -0
  109. package/dist/apps/cli/commands/project/index.d.ts +3 -0
  110. package/dist/apps/cli/commands/project/index.js +97 -0
  111. package/dist/apps/cli/commands/project/index.js.map +1 -0
  112. package/dist/apps/cli/commands/project/utils/autocompletions.d.ts +3 -0
  113. package/dist/apps/cli/commands/project/utils/autocompletions.js +96 -0
  114. package/dist/apps/cli/commands/project/utils/autocompletions.js.map +1 -0
  115. package/dist/apps/cli/commands/project/utils/ensureCluster.d.ts +1 -0
  116. package/dist/apps/cli/commands/project/utils/ensureCluster.js +84 -0
  117. package/dist/apps/cli/commands/project/utils/ensureCluster.js.map +1 -0
  118. package/dist/apps/cli/commands/project/utils/ensureNamespace.d.ts +1 -0
  119. package/dist/apps/cli/commands/project/utils/ensureNamespace.js +92 -0
  120. package/dist/apps/cli/commands/project/utils/ensureNamespace.js.map +1 -0
  121. package/dist/apps/cli/commands/project/utils/showProjectBanner.d.ts +2 -0
  122. package/dist/apps/cli/commands/project/utils/showProjectBanner.js +58 -0
  123. package/dist/apps/cli/commands/project/utils/showProjectBanner.js.map +1 -0
  124. package/dist/apps/cli/commands/shared/index.d.ts +2 -0
  125. package/dist/apps/cli/commands/shared/index.js +72 -0
  126. package/dist/apps/cli/commands/shared/index.js.map +1 -0
  127. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.d.ts +3 -0
  128. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js +131 -0
  129. package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js.map +1 -0
  130. package/dist/apps/cli/config/writeConfig.d.ts +5 -0
  131. package/dist/apps/cli/config/writeConfig.js +104 -0
  132. package/dist/apps/cli/config/writeConfig.js.map +1 -0
  133. package/dist/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -0
  134. package/dist/apps/cli/utils/getGoogleAuthUserNumber.js +69 -0
  135. package/dist/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -0
  136. package/dist/apps/cli/verify/index.d.ts +2 -0
  137. package/dist/apps/cli/verify/index.js +90 -0
  138. package/dist/apps/cli/verify/index.js.map +1 -0
  139. package/dist/apps/cli/verify/migration/fromv2.d.ts +3 -0
  140. package/dist/apps/cli/verify/migration/fromv2.js +322 -0
  141. package/dist/apps/cli/verify/migration/fromv2.js.map +1 -0
  142. package/dist/apps/cli/verify/migration/migrateSecrets.d.ts +4 -0
  143. package/dist/apps/cli/verify/migration/migrateSecrets.js +88 -0
  144. package/dist/apps/cli/verify/migration/migrateSecrets.js.map +1 -0
  145. package/dist/apps/cli/verify/migration/oldGitlabCi.d.ts +17 -0
  146. package/dist/apps/cli/verify/migration/oldGitlabCi.js +26 -0
  147. package/dist/apps/cli/verify/migration/oldGitlabCi.js.map +1 -0
  148. package/dist/catenv.d.ts +1 -0
  149. package/dist/catenv.js +8 -0
  150. package/dist/catenv.js.map +1 -0
  151. package/dist/cli.d.ts +1 -0
  152. package/dist/cli.js +13 -0
  153. package/dist/cli.js.map +1 -0
  154. package/dist/config/clusters.d.ts +14 -0
  155. package/dist/config/clusters.js +72 -0
  156. package/dist/config/clusters.js.map +1 -0
  157. package/dist/config/constants.d.ts +4 -0
  158. package/dist/config/constants.js +8 -0
  159. package/dist/config/constants.js.map +1 -0
  160. package/dist/config/getProjectConfig.d.ts +21 -0
  161. package/dist/config/getProjectConfig.js +212 -0
  162. package/dist/config/getProjectConfig.js.map +1 -0
  163. package/dist/k8sApi/index.d.ts +5 -0
  164. package/dist/k8sApi/index.js +11 -0
  165. package/dist/k8sApi/index.js.map +1 -0
  166. package/dist/packageInfos.d.ts +2 -0
  167. package/dist/packageInfos.js +6 -0
  168. package/dist/packageInfos.js.map +1 -0
  169. package/dist/tsconfig.tsbuildinfo +1 -0
  170. package/dist/types/types.d.ts +18 -0
  171. package/dist/types/types.js +3 -0
  172. package/dist/types/types.js.map +1 -0
  173. package/dist/utils/cluster.d.ts +12 -0
  174. package/dist/utils/cluster.js +100 -0
  175. package/dist/utils/cluster.js.map +1 -0
  176. package/dist/utils/dashboardToken.d.ts +2 -0
  177. package/dist/utils/dashboardToken.js +89 -0
  178. package/dist/utils/dashboardToken.js.map +1 -0
  179. package/dist/utils/editAsFile.d.ts +1 -0
  180. package/dist/utils/editAsFile.js +85 -0
  181. package/dist/utils/editAsFile.js.map +1 -0
  182. package/dist/utils/files.d.ts +2 -0
  183. package/dist/utils/files.js +83 -0
  184. package/dist/utils/files.js.map +1 -0
  185. package/dist/utils/formatEnvVars.d.ts +2 -0
  186. package/dist/utils/formatEnvVars.js +10 -0
  187. package/dist/utils/formatEnvVars.js.map +1 -0
  188. package/dist/utils/getEditor.d.ts +4 -0
  189. package/dist/utils/getEditor.js +70 -0
  190. package/dist/utils/getEditor.js.map +1 -0
  191. package/dist/utils/gitlab.d.ts +21 -0
  192. package/dist/utils/gitlab.js +258 -0
  193. package/dist/utils/gitlab.js.map +1 -0
  194. package/dist/utils/log.d.ts +1 -0
  195. package/dist/utils/log.js +14 -0
  196. package/dist/utils/log.js.map +1 -0
  197. package/dist/utils/passwordstore/index.d.ts +8 -0
  198. package/dist/utils/passwordstore/index.js +378 -0
  199. package/dist/utils/passwordstore/index.js.map +1 -0
  200. package/dist/utils/portForward.d.ts +4 -0
  201. package/dist/utils/portForward.js +116 -0
  202. package/dist/utils/portForward.js.map +1 -0
  203. package/dist/utils/preferences/index.d.ts +3 -0
  204. package/dist/utils/preferences/index.js +119 -0
  205. package/dist/utils/preferences/index.js.map +1 -0
  206. package/dist/utils/projects/index.d.ts +8 -0
  207. package/dist/utils/projects/index.js +150 -0
  208. package/dist/utils/projects/index.js.map +1 -0
  209. package/dist/utils/promise.d.ts +2 -0
  210. package/dist/utils/promise.js +62 -0
  211. package/dist/utils/promise.js.map +1 -0
  212. package/dist/utils/shell.d.ts +1 -0
  213. package/dist/utils/shell.js +81 -0
  214. package/dist/utils/shell.js.map +1 -0
  215. package/package.json +10 -11
  216. package/src/apps/catenv/catenv.ts +48 -27
  217. package/src/apps/{shell/shell.ts → cli/cli.ts} +12 -2
  218. package/src/apps/{shell → cli}/commands/general/index.ts +1 -1
  219. package/src/apps/{shell → cli}/commands/general/namespaceAutoCompletion.ts +0 -0
  220. package/src/apps/{shell → cli}/commands/general/portForward.ts +1 -1
  221. package/src/apps/{shell → cli}/commands/mongodb/index.ts +1 -1
  222. package/src/apps/{shell → cli}/commands/mongodb/projectMongoDestroyMember.ts +18 -18
  223. package/src/apps/{shell → cli}/commands/mongodb/projectMongoGetShell.ts +12 -10
  224. package/src/apps/{shell → cli}/commands/mongodb/projectMongoPortForward.ts +13 -8
  225. package/src/apps/{shell → cli}/commands/mongodb/utils/index.ts +9 -8
  226. package/src/apps/{shell → cli}/commands/project/commandCloudSqlProxy.ts +23 -17
  227. package/src/apps/cli/commands/project/commandConfigSecrets.ts +204 -0
  228. package/src/apps/{shell → cli}/commands/project/commandCopyDB.ts +22 -23
  229. package/src/apps/{shell → cli}/commands/project/commandDeletePods.ts +8 -9
  230. package/src/apps/{shell → cli}/commands/project/commandDeleteProject.ts +7 -8
  231. package/src/apps/cli/commands/project/commandEnvVars.ts +15 -0
  232. package/src/apps/{shell → cli}/commands/project/commandGetMyTotalWorktime.ts +2 -2
  233. package/src/apps/{shell → cli}/commands/project/commandGetShell.ts +10 -10
  234. package/src/apps/{shell → cli}/commands/project/commandGitlabCi.ts +1 -1
  235. package/src/apps/cli/commands/project/commandInitGitlab.ts +203 -0
  236. package/src/apps/{shell → cli}/commands/project/commandInitProject.ts +14 -6
  237. package/src/apps/cli/commands/project/commandListPods.ts +18 -0
  238. package/src/apps/{shell → cli}/commands/project/commandMigrateHelm3.ts +16 -7
  239. package/src/apps/cli/commands/project/commandNamespace.ts +14 -0
  240. package/src/apps/{shell → cli}/commands/project/commandOpenCostDashboard.ts +10 -7
  241. package/src/apps/cli/commands/project/commandOpenDashboard.ts +45 -0
  242. package/src/apps/cli/commands/project/commandOpenEnv.ts +22 -0
  243. package/src/apps/{shell → cli}/commands/project/commandOpenGit.ts +1 -1
  244. package/src/apps/{shell → cli}/commands/project/commandOpenGrafana.ts +7 -7
  245. package/src/apps/{shell → cli}/commands/project/commandOpenGrafanaPod.ts +9 -10
  246. package/src/apps/{shell → cli}/commands/project/commandOpenLogs.ts +7 -7
  247. package/src/apps/{shell → cli}/commands/project/commandPauseProject.ts +9 -7
  248. package/src/apps/{shell → cli}/commands/project/commandPortForward.ts +8 -8
  249. package/src/apps/cli/commands/project/commandReloadConfig.ts +12 -0
  250. package/src/apps/{shell → cli}/commands/project/commandTriggerCronjob.ts +7 -7
  251. package/src/apps/{shell → cli}/commands/project/index.ts +4 -3
  252. package/src/apps/cli/commands/project/utils/autocompletions.ts +26 -0
  253. package/src/apps/cli/commands/project/utils/ensureCluster.ts +37 -0
  254. package/src/apps/{shell → cli}/commands/project/utils/ensureNamespace.ts +2 -3
  255. package/src/apps/cli/commands/project/utils/showProjectBanner.ts +11 -0
  256. package/src/apps/{shell → cli}/commands/shared/index.ts +0 -0
  257. package/src/apps/{shell → cli}/commands/theStuffThatReallyMatters/index.ts +11 -11
  258. package/src/apps/cli/config/writeConfig.ts +69 -0
  259. package/src/apps/{shell → cli}/utils/getGoogleAuthUserNumber.ts +0 -0
  260. package/src/apps/cli/verify/index.ts +34 -0
  261. package/src/apps/cli/verify/migration/fromv2.ts +242 -0
  262. package/src/apps/cli/verify/migration/migrateSecrets.ts +37 -0
  263. package/src/apps/cli/verify/migration/oldGitlabCi.ts +43 -0
  264. package/src/catenv.ts +3 -0
  265. package/src/cli.ts +8 -0
  266. package/src/config/getProjectConfig.ts +118 -0
  267. package/src/types/types.ts +0 -2
  268. package/src/utils/cluster.ts +15 -2
  269. package/src/utils/editAsFile.ts +31 -0
  270. package/src/utils/files.ts +6 -2
  271. package/src/utils/gitlab.ts +126 -32
  272. package/src/utils/passwordstore/index.ts +19 -21
  273. package/src/utils/preferences/index.ts +6 -3
  274. package/src/utils/projects/index.ts +14 -134
  275. package/tsconfig.json +3 -7
  276. package/bin/catenv.sh +0 -1
  277. package/src/apps/shell/commands/project/commandConfigSecrets.ts +0 -245
  278. package/src/apps/shell/commands/project/commandEnvVars.ts +0 -17
  279. package/src/apps/shell/commands/project/commandInitGitlab.ts +0 -157
  280. package/src/apps/shell/commands/project/commandListPods.ts +0 -21
  281. package/src/apps/shell/commands/project/commandNamespace.ts +0 -12
  282. package/src/apps/shell/commands/project/commandOpenDashboard.ts +0 -27
  283. package/src/apps/shell/commands/project/commandOpenEnv.ts +0 -18
  284. package/src/apps/shell/commands/project/commandVariables.ts +0 -13
  285. package/src/apps/shell/commands/project/utils/autocompletions.ts +0 -7
  286. package/src/apps/shell/commands/project/utils/ensureCluster.ts +0 -31
  287. package/src/apps/shell/commands/project/utils/monorepo.ts +0 -45
  288. package/src/index.ts +0 -17
@@ -0,0 +1,118 @@
1
+ import {
2
+ readConfigSync,
3
+ getAllEnvs,
4
+ getEnvironment as _getEnvironment,
5
+ createContext,
6
+ } from "@catladder/pipeline";
7
+
8
+ import { CommandInstance } from "vorpal";
9
+ import { getAllVariables } from "../utils/gitlab";
10
+ import memoizee from "memoizee";
11
+ import { getGitRoot } from "../utils/projects";
12
+ import { readYaml } from "../utils/files";
13
+ // currently cant change
14
+
15
+ export const getProjectConfig = memoizee(
16
+ async () => {
17
+ try {
18
+ const gitRoot = await getGitRoot();
19
+ return readConfigSync(gitRoot);
20
+ } catch (e) {
21
+ // ignore
22
+ return null;
23
+ }
24
+ },
25
+ { promise: true }
26
+ );
27
+
28
+ export const reloadConfig = () => getProjectConfig.clear();
29
+
30
+ export const getGitlabCiFilePath = async () => {
31
+ const gitRoot = await getGitRoot();
32
+ return gitRoot + "/.gitlab-ci.yml";
33
+ };
34
+ export const getGitlabCi = async <T = Record<string, any>>() => {
35
+ try {
36
+ return readYaml(await getGitlabCiFilePath()) as Promise<T>;
37
+ } catch (e) {
38
+ // ignore
39
+ return null;
40
+ }
41
+ };
42
+
43
+ export const getProjectComponents = async () => {
44
+ const config = await getProjectConfig();
45
+ if (!config) return [];
46
+ return Object.keys(config.components);
47
+ };
48
+
49
+ export const parseChoice = (envComponent: string) => {
50
+ const [env, componentName] = envComponent.split(":");
51
+ return { env, componentName };
52
+ };
53
+
54
+ export const getPipelineContextByChoice = async (
55
+ env: string,
56
+ componentName: string
57
+ ) => {
58
+ const config = await getProjectConfig();
59
+ return createContext(config, componentName, env);
60
+ };
61
+ export const getAllComponentsWithAllEnvs = async () => {
62
+ const config = await getProjectConfig();
63
+ if (!config) {
64
+ return [];
65
+ }
66
+ return Promise.all(
67
+ Object.keys(config.components).flatMap((componentName) =>
68
+ getAllEnvs(config, componentName).map((env) => ({ env, componentName }))
69
+ )
70
+ );
71
+ };
72
+
73
+ export const getAllPipelineContexts = async () => {
74
+ return Promise.all(
75
+ (await getAllComponentsWithAllEnvs()).map(({ env, componentName }) =>
76
+ getPipelineContextByChoice(env, componentName)
77
+ )
78
+ );
79
+ };
80
+
81
+ export const getEnvironment = async (env: string, componentName: string) => {
82
+ const config = await getProjectConfig();
83
+ return _getEnvironment(config, componentName, env);
84
+ };
85
+
86
+ const resolveSecrets = async (
87
+ vorpal: CommandInstance,
88
+ allEnvVars: Record<string, string>
89
+ ) => {
90
+ const allVariablesInGitlab = await getAllVariables(vorpal);
91
+
92
+ return Object.fromEntries(
93
+ Object.entries(allEnvVars).map(([key, value]) => {
94
+ const isSecret = value?.startsWith?.("$CL_");
95
+ if (isSecret) {
96
+ // secrets have CL_XXXX structure
97
+ const found = allVariablesInGitlab.find((v) => "$" + v.key === value);
98
+
99
+ if (found) {
100
+ return [key, found.value];
101
+ } else {
102
+ return [key, ""];
103
+ }
104
+ }
105
+ return [key, value];
106
+ })
107
+ );
108
+ };
109
+
110
+ export const getEnvVars = async (
111
+ vorpal: CommandInstance,
112
+ env: string,
113
+ componentName: string
114
+ ) => {
115
+ const envionment = await getEnvironment(env, componentName);
116
+
117
+ return resolveSecrets(vorpal, envionment.envVars);
118
+ };
@@ -1,5 +1,3 @@
1
- export type Env = "dev-local" | "prod" | "dev" | "stage" | "review";
2
-
3
1
  export type KubernetesSecretName = string;
4
2
  export interface ISecrets {
5
3
  [key: string]: KubernetesSecretName;
@@ -9,8 +9,21 @@ export const getCurrentConnectedClusterName = async () => {
9
9
  return findKey(clusters, { fullName: currentContext });
10
10
  };
11
11
 
12
- export const getClusterByName = (name: string) => {
13
- return clusters[name];
12
+ export const getClusterByFullName = (fullName: string) => {
13
+ const found = Object.entries(getAllClusters()).find(
14
+ ([, config]) => config.fullName === fullName
15
+ );
16
+ if (found) {
17
+ return { name: found[0], cluster: found[1] };
18
+ } else {
19
+ return null;
20
+ }
21
+ };
22
+
23
+ export const getClusterByName = (name: string) => getAllClusters()[name];
24
+
25
+ export const getAllClusters = () => {
26
+ return clusters;
14
27
  };
15
28
 
16
29
  export const getAllClusterNames = () => Object.keys(clusters);
@@ -0,0 +1,31 @@
1
+ import { withFile } from "tmp-promise";
2
+ import { dump, load } from "js-yaml";
3
+
4
+ import { readFile, writeFile } from "fs-extra";
5
+ import getEditor from "./getEditor";
6
+
7
+ export const editAsFile = async <T>(
8
+ inObject: T,
9
+ preamble?: string
10
+ ): Promise<T> => {
11
+ const fullPreamble = preamble
12
+ ? `#
13
+ # ${preamble.split("\n").join("\n# ")}
14
+ #
15
+
16
+ `
17
+ : "\n";
18
+ const asString = fullPreamble + dump(inObject, { noRefs: true });
19
+ let newContent: T;
20
+
21
+ await withFile(
22
+ async ({ path: tmpFilePath }) => {
23
+ await writeFile(tmpFilePath, asString);
24
+ await (await getEditor()).open(tmpFilePath);
25
+ newContent = load((await readFile(tmpFilePath)).toString("utf-8")) as T;
26
+ },
27
+ { postfix: ".yml" }
28
+ );
29
+
30
+ return newContent;
31
+ };
@@ -13,6 +13,10 @@ export const readFileOrError = async (filePath: string) => {
13
13
  }
14
14
  };
15
15
 
16
- export const readYaml = async (filename: string) => {
17
- return yaml.load(await readFile(filename));
16
+ export const readYaml = async <T = Record<string, any>>(filename: string) => {
17
+ try {
18
+ return yaml.load(await readFile(filename)) as T;
19
+ } catch (e) {
20
+ return null;
21
+ }
18
22
  };
@@ -1,52 +1,68 @@
1
1
  import { exec } from "child-process-promise";
2
+ import { getSecretVarName } from "@catladder/pipeline";
3
+ import { isObject } from "lodash";
4
+ import memoizee from "memoizee";
2
5
  import fetch from "node-fetch";
3
6
  import open from "open";
4
7
  import { CommandInstance } from "vorpal";
5
8
  import { getPreference, hasPreference, setPreference } from "./preferences";
6
9
 
7
10
  const TOKEN_KEY = "gitlab-personal-access-token";
8
- export const getGitlabToken = async (vorpal: CommandInstance) => {
9
- if (!(await hasPreference(TOKEN_KEY))) {
10
- vorpal.log("");
11
- vorpal.log(
12
- "☝ in order to access the api, we need a personal access token"
13
- );
14
- vorpal.log("Its best to create one specifically for catladder");
15
- vorpal.log("");
16
- vorpal.log("☝ we open up the settings page for you!");
17
- vorpal.log("");
18
- const { shouldContinue } = await vorpal.prompt({
19
- default: true,
20
- message: "Ok",
21
- name: "shouldContinue",
22
- type: "prompt",
23
- });
24
11
 
25
- open("https://git.panter.ch/-/profile/personal_access_tokens");
12
+ export const hasGitlabToken = async () => await hasPreference(TOKEN_KEY);
13
+ export const setupGitlabToken = async (vorpal: CommandInstance) => {
14
+ vorpal.log("");
15
+ vorpal.log("☝ in order to access the api, we need a personal access token");
16
+ vorpal.log("Its best to create one specifically for catladder");
17
+ vorpal.log("");
18
+ vorpal.log("☝ we open up the settings page for you!");
19
+ vorpal.log("");
20
+ const { shouldContinue } = await vorpal.prompt({
21
+ default: true,
22
+ message: "Ok",
23
+ name: "shouldContinue",
24
+ type: "prompt",
25
+ });
26
+
27
+ open("https://git.panter.ch/-/profile/personal_access_tokens");
26
28
 
27
- vorpal.log("Please type in gitlab's personal access token");
29
+ vorpal.log("Please type in gitlab's personal access token");
28
30
 
29
- const { personalToken } = await vorpal.prompt({
30
- type: "string",
31
- name: "personalToken",
32
- default: "",
33
- message: "Your personal access token ",
34
- });
35
- if (personalToken) {
36
- await setPreference(TOKEN_KEY, personalToken);
31
+ const { personalToken } = await vorpal.prompt({
32
+ type: "string",
33
+ name: "personalToken",
34
+ default: "",
35
+ message: "Your personal access token ",
36
+ });
37
+ if (personalToken) {
38
+ await setPreference(TOKEN_KEY, personalToken);
39
+ }
40
+ };
41
+ export const getGitlabToken = async (vorpal: CommandInstance) => {
42
+ if (!(await hasGitlabToken())) {
43
+ if (!vorpal) {
44
+ console.error(
45
+ "⚠️ gitlab token missing, please run catladder to set it up"
46
+ );
47
+ process.exit(1);
37
48
  }
49
+ await setupGitlabToken(vorpal);
38
50
  }
39
51
  return getPreference(TOKEN_KEY);
40
52
  };
41
53
 
42
- export const doGitlabRequest = async (
54
+ export const doGitlabRequest = async <T = any>(
43
55
  vorpal: CommandInstance,
44
56
  path: string,
45
- data?: any
46
- ) => {
57
+ data: any = undefined,
58
+ update?: boolean
59
+ ): Promise<T> => {
47
60
  const rootToken = await getGitlabToken(vorpal);
61
+
62
+ const method = data ? (update ? "PUT" : "POST") : "GET";
63
+
48
64
  const result = await fetch(`https://git.panter.ch/api/v4/${path}`, {
49
- method: data ? "POST" : "GET",
65
+ method,
50
66
  headers: {
51
67
  "Content-Type": "application/json",
52
68
  "Private-Token": rootToken,
@@ -59,13 +75,15 @@ export const doGitlabRequest = async (
59
75
  }
60
76
 
61
77
  throw new Error(
62
- `Could not send request to gitlab api: ${result.status} "${
78
+ `Could not send request to gitlab api ${path}: ${result.status} "${
63
79
  result.statusText
64
80
  }".\nResponse: ${JSON.stringify(await result.json(), null, 2)}`
65
81
  );
66
82
  };
67
83
 
68
- export const getProjectInfo = async (vorpal: CommandInstance): Promise<any> => {
84
+ export const getProjectInfo = async (
85
+ vorpal: CommandInstance
86
+ ): Promise<{ id: string; web_url: string }> => {
69
87
  const gitRemoteOriginUrl = (
70
88
  await exec("git config --get remote.origin.url")
71
89
  ).stdout.trim();
@@ -78,3 +96,79 @@ export const getProjectInfo = async (vorpal: CommandInstance): Promise<any> => {
78
96
  );
79
97
  return project;
80
98
  };
99
+
100
+ type GitlabVariable = {
101
+ variable_type: string;
102
+ key: string;
103
+ value: string;
104
+ protected: boolean;
105
+ masked: boolean;
106
+ environment_scope: string;
107
+ };
108
+ export const getAllVariables = memoizee(
109
+ async (vorpal: CommandInstance): Promise<Array<GitlabVariable>> => {
110
+ const { id } = await getProjectInfo(vorpal);
111
+ let all: Array<GitlabVariable> = [];
112
+ let result: Array<GitlabVariable>;
113
+ let page = 1;
114
+ do {
115
+ result = await doGitlabRequest(
116
+ vorpal,
117
+ // 100 is max page size
118
+ `projects/${id}/variables?per_page=100&page=${page}`
119
+ );
120
+ page++;
121
+ all = [...all, ...result];
122
+ } while (result?.length > 0);
123
+ return all;
124
+ },
125
+ { promise: true }
126
+ );
127
+
128
+ const createVariable = async (
129
+ vorpal: CommandInstance,
130
+ projectId: string,
131
+ key: string,
132
+ value: string
133
+ ) => {
134
+ return await doGitlabRequest(vorpal, `projects/${projectId}/variables`, {
135
+ key,
136
+ value,
137
+ });
138
+ };
139
+
140
+ const updateVariable = async (
141
+ vorpal: CommandInstance,
142
+ projectId: string,
143
+ key: string,
144
+ value: string
145
+ ) => {
146
+ return await doGitlabRequest(
147
+ vorpal,
148
+ `projects/${projectId}/variables/${key}`,
149
+ {
150
+ value,
151
+ },
152
+ true
153
+ );
154
+ };
155
+ export const upsertAllVariables = async (
156
+ vorpal: CommandInstance,
157
+ variables: Record<string, any>,
158
+ env: string,
159
+ componentName: string
160
+ ): Promise<void> => {
161
+ const { id } = await getProjectInfo(vorpal);
162
+
163
+ for (const [key, value] of Object.entries(variables ?? {})) {
164
+ const fullKey = getSecretVarName(env, componentName, key);
165
+ const valueSanitized = isObject(value) ? JSON.stringify(value) : `${value}`;
166
+ try {
167
+ await updateVariable(vorpal, id, fullKey, valueSanitized);
168
+ } catch (e) {
169
+ await createVariable(vorpal, id, fullKey, valueSanitized);
170
+ } finally {
171
+ getAllVariables.clear();
172
+ }
173
+ }
174
+ };
@@ -1,11 +1,8 @@
1
1
  import { exec, spawn } from "child-process-promise";
2
2
  import commandExists from "command-exists-promise";
3
3
  import dayjs from "dayjs";
4
-
5
4
  import { readFile, writeFile } from "fs-extra";
6
- import yaml from "js-yaml";
7
5
  import { withFile } from "tmp-promise";
8
- import formatEnvVars from "../formatEnvVars";
9
6
  import getEditor from "../getEditor";
10
7
  import { getPreference, hasPreference, setPreference } from "../preferences";
11
8
 
@@ -78,9 +75,7 @@ const execBitwardenCommand = async (command: string): Promise<any> => {
78
75
  await loginBitwarden();
79
76
  return execBitwardenCommand(command);
80
77
  } else {
81
- console.error(e);
82
-
83
- console.log("wooops", e.message);
78
+ throw e;
84
79
  }
85
80
  }
86
81
  };
@@ -169,24 +164,27 @@ const share = async (itemId: string) =>
169
164
  ])}`
170
165
  );
171
166
 
172
- export const editPass = async (path: string) => {
167
+ export const trashItem = async (path: string) => {
173
168
  const item = await getItem(path);
174
169
 
175
- await withFile(async ({ path: tmpFilePath }) => {
176
- await writeFile(tmpFilePath, item.notes);
177
- await (await getEditor()).open(tmpFilePath);
178
- const newContent = (await readFile(tmpFilePath)).toString("utf-8");
170
+ const result = await execBitwardenCommand(`delete item ${item.id}`);
179
171
 
180
- await update("item", item.id, {
181
- ...item,
182
- notes: newContent,
183
- });
184
- }, { postfix: ".yml" });
172
+ return result;
185
173
  };
174
+ export const editPass = async (path: string) => {
175
+ const item = await getItem(path);
186
176
 
187
- export const readPassEnvVars = async (path: string) => {
188
- // make sure that you have pulled pass beforehand
189
- const yamlstring = await readPass(path);
190
- // if a value is an object, we convert it to strings
191
- return formatEnvVars(yaml.load(yamlstring));
177
+ await withFile(
178
+ async ({ path: tmpFilePath }) => {
179
+ await writeFile(tmpFilePath, item.notes);
180
+ await (await getEditor()).open(tmpFilePath);
181
+ const newContent = (await readFile(tmpFilePath)).toString("utf-8");
182
+
183
+ await update("item", item.id, {
184
+ ...item,
185
+ notes: newContent,
186
+ });
187
+ },
188
+ { postfix: ".yml" }
189
+ );
192
190
  };
@@ -1,7 +1,7 @@
1
1
  import fs from "fs-extra";
2
2
  import { homedir } from "os";
3
3
 
4
- import yaml from "js-yaml";
4
+ import { load, dump } from "js-yaml";
5
5
  const directory = `${homedir()}/.catladder`;
6
6
  const file = `${directory}/preferences.yml`;
7
7
 
@@ -9,7 +9,10 @@ const getPreferences = async () => {
9
9
  if (!(await fs.pathExists(file))) {
10
10
  await fs.createFile(file);
11
11
  }
12
- return yaml.load(await fs.readFile(file, { encoding: "utf-8" })) ?? {};
12
+ return (load(await fs.readFile(file, { encoding: "utf-8" })) ?? {}) as Record<
13
+ string,
14
+ string
15
+ >;
13
16
  };
14
17
 
15
18
  export const hasPreference = async (key: string) => {
@@ -29,5 +32,5 @@ export const setPreference = async (key: string, value: string | number) => {
29
32
  [key]: value,
30
33
  };
31
34
 
32
- await fs.writeFile(file, yaml.safeDump(newPreferences));
35
+ await fs.writeFile(file, dump(newPreferences));
33
36
  };
@@ -1,18 +1,11 @@
1
1
  import { exec } from "child-process-promise";
2
+
2
3
  import { join } from "path";
4
+ import { getProjectConfig, parseChoice } from "../../config/getProjectConfig";
3
5
  import k8sApi from "../../k8sApi";
4
- import { Env, ISecrets, IValueFile } from "../../types/types";
5
- import { readFileOrError, readYaml } from "../files";
6
- import formatEnvVars from "../formatEnvVars";
7
- import { hasBitwarden, readPassEnvVars, syncBitwarden } from "../passwordstore";
8
- import { filter } from "../promise";
9
-
10
- import { merge } from "lodash";
6
+ import { readFileOrError } from "../files";
11
7
 
12
- // eslint-disable-next-line @typescript-eslint/no-var-requires
13
- const YAWN = require("yawn-yaml/cjs");
14
-
15
- export const getGitRoot = async () => {
8
+ export const getGitRoot = async (): Promise<string> => {
16
9
  return (await exec("git rev-parse --show-toplevel")).stdout?.trim();
17
10
  };
18
11
 
@@ -31,141 +24,28 @@ export const hasGitlabCiFile = async () => {
31
24
  }
32
25
  return true;
33
26
  };
34
- export const getLocalProjectVariables = async () => {
35
- const [error, file] = await readRootGitlabCiFile();
36
- if (error) {
37
- throw new Error("there is no '.gitlab-ci.yml' in the current project");
38
- }
39
- // yawn allows to modify yaml while keeping comments!
40
- const yawn = new YAWN(file);
41
- const { variables } = yawn.json;
42
- if (!variables) {
43
- throw new Error("your '.gitlab-ci.yml' does not define `variables`");
44
- }
45
- const defaults = {
46
- CLUSTER_NAME: "production",
47
- };
48
- return {
49
- ...defaults,
50
- ...variables,
51
- };
52
- };
53
27
 
54
- export const getProjectNamespace = async (env: Env) => {
55
- const { CUSTOMER_NAME, APP_NAME } = await getLocalProjectVariables();
56
- return `${CUSTOMER_NAME}-${APP_NAME}-${env}`;
28
+ export const getProjectNamespace = async (envComponent: string) => {
29
+ const { env } = parseChoice(envComponent);
30
+ const config = await getProjectConfig();
31
+ return `${config.customerName}-${config.appName}-${env}`;
57
32
  };
58
33
 
59
- export const getProjectHelmReleaseName = async (env: Env) => {
60
- // can't properly get the release name for review as it contains an additional branch slug
61
- if (env === "review" || env === "dev-local") {
62
- throw new Error(`can't get helm release name for ${env}`);
63
- }
64
- const {
65
- CUSTOMER_NAME,
66
- APP_NAME,
67
- COMPONENT_NAME = "web",
68
- } = await getLocalProjectVariables();
69
- return `${CUSTOMER_NAME}-${APP_NAME}-${env}-${COMPONENT_NAME}`;
70
- };
71
- export const getProjectPods = async (env: Env) => {
72
- const namespace = await getProjectNamespace(env);
34
+ export const getProjectPods = async (envComponent: string) => {
35
+ const namespace = await getProjectNamespace(envComponent);
73
36
  const res = await k8sApi.listNamespacedPod(namespace);
74
37
 
75
38
  return res.body.items;
76
39
  };
77
40
 
78
- export const getProjectPvcs = async (env: Env) => {
79
- const namespace = await getProjectNamespace(env);
41
+ export const getProjectPvcs = async (envComponent: string) => {
42
+ const namespace = await getProjectNamespace(envComponent);
80
43
  const res = await k8sApi.listNamespacedPersistentVolumeClaim(namespace);
81
44
 
82
45
  return res.body.items;
83
46
  };
84
47
 
85
- export const getProjectPodNames = async (env: Env) => {
86
- const pods = await getProjectPods(env);
48
+ export const getProjectPodNames = async (envComponent: string) => {
49
+ const pods = await getProjectPods(envComponent);
87
50
  return pods.map((n) => n.metadata.name);
88
51
  };
89
-
90
- export const getPassPath = async (env: Env) => {
91
- const { CUSTOMER_NAME, APP_NAME } = await getLocalProjectVariables();
92
- return `${CUSTOMER_NAME}/${APP_NAME}/${env}/secrets.yml`;
93
- };
94
-
95
- export const getProjectValuesFiles = async (env: Env, subApp?: string) => {
96
- const gitRoot = await getGitRoot();
97
- const possibleFiles = ["values.yml", `values-${env}.yml`].map((file) =>
98
- subApp ? join(gitRoot, subApp, file) : join(gitRoot, file)
99
- );
100
- return filter(possibleFiles, async (file) => {
101
- const [error] = await readFileOrError(file);
102
- return !error;
103
- });
104
- };
105
-
106
- export const getAllValues = async (env: Env, subApp?: string) => {
107
- const valuesFilePaths = await getProjectValuesFiles(env, subApp);
108
- return Promise.all(
109
- valuesFilePaths.map(async (file) => (await readYaml(file)) as IValueFile)
110
- );
111
- };
112
-
113
- export const getProjectValues = async (env: Env, subApp?: string) => {
114
- const values = await getAllValues(env, subApp);
115
- return merge({}, ...values) as IValueFile;
116
- };
117
-
118
- export const getAllPublicEnvVars = async (env: Env, subApp?: string) => {
119
- return formatEnvVars(
120
- (await getAllValues(env, subApp)).reduce<ISecrets>((acc, value) => {
121
- if (value.env && value.env.public) {
122
- return {
123
- ...acc,
124
- ...value.env.public,
125
- };
126
- }
127
- return acc;
128
- }, {})
129
- );
130
- };
131
- export const getAllSecretsEnvVarsMapping = async (
132
- env: Env,
133
- subApp?: string
134
- ) => {
135
- return (await getAllValues(env, subApp)).reduce<ISecrets>((acc, value) => {
136
- if (value.env && value.env.secret) {
137
- return {
138
- ...acc,
139
- ...value.env.secret,
140
- };
141
- }
142
- return acc;
143
- }, {});
144
- };
145
-
146
- export const hasSecrets = async (env: Env, subApp?: string) => {
147
- return Object.keys(await getAllSecretsEnvVarsMapping(env, subApp)).length > 0;
148
- };
149
-
150
- export const getAllEnvVars = async (
151
- env: Env,
152
- subApp?: string
153
- ): Promise<Record<string, string>> => {
154
- return {
155
- ...(await getAllPublicEnvVars(env, subApp)),
156
- ...(await getAllSecretEnvVars(env, subApp)),
157
- };
158
- };
159
-
160
- export const getAllSecretEnvVars = async (env: Env, subApp?: string) => {
161
- if (!(await hasSecrets(env, subApp))) {
162
- return {};
163
- }
164
- if (await hasBitwarden()) {
165
- await syncBitwarden(false /* do not force sync */);
166
- const passPath = await getPassPath(env);
167
- return readPassEnvVars(passPath);
168
- } else {
169
- return {};
170
- }
171
- };
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "extends": "@tsconfig/node14/tsconfig.json",
3
2
  "compilerOptions": {
3
+ "lib": ["es2020", "DOM"],
4
4
  "module": "CommonJS",
5
5
  "declaration": true,
6
6
  "noImplicitAny": true,
@@ -9,12 +9,8 @@
9
9
  "sourceMap": true,
10
10
  "outDir": "dist",
11
11
  "strict": false,
12
- "baseUrl": ".",
13
12
  "incremental": true,
14
- "resolveJsonModule": true,
15
- "paths": {
16
- "*": ["node_modules/*", "src/types/*"]
17
- }
13
+ "resolveJsonModule": true
18
14
  },
19
- "include": ["src/**/*"]
15
+ "include": ["./src/**/*"]
20
16
  }
package/bin/catenv.sh DELETED
@@ -1 +0,0 @@
1
- eval $(catladder --catenv )