@catladder/cli 0.0.0-test7 → 0.0.0-waitfor-deploy-e64a33ba
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.
- package/.nvmrc +1 -1
- package/README.md +6 -3
- package/bin/catenv +3 -0
- package/bin/catladder +1 -1
- package/dist/apps/catenv/catenv.d.ts +5 -0
- package/dist/apps/catenv/catenv.js +143 -0
- package/dist/apps/catenv/catenv.js.map +1 -0
- package/dist/apps/cli/cli.d.ts +2 -0
- package/dist/apps/cli/cli.js +81 -0
- package/dist/apps/cli/cli.js.map +1 -0
- package/dist/apps/cli/commands/general/index.d.ts +4 -0
- package/dist/apps/cli/commands/general/index.js +216 -0
- package/dist/apps/cli/commands/general/index.js.map +1 -0
- package/dist/apps/cli/commands/general/namespaceAutoCompletion.d.ts +3 -0
- package/dist/apps/cli/commands/general/namespaceAutoCompletion.js +56 -0
- package/dist/apps/cli/commands/general/namespaceAutoCompletion.js.map +1 -0
- package/dist/apps/cli/commands/general/portForward.d.ts +3 -0
- package/dist/apps/cli/commands/general/portForward.js +97 -0
- package/dist/apps/cli/commands/general/portForward.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/index.d.ts +3 -0
- package/dist/apps/cli/commands/mongodb/index.js +53 -0
- package/dist/apps/cli/commands/mongodb/index.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.d.ts +3 -0
- package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js +190 -0
- package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/projectMongoGetShell.d.ts +3 -0
- package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js +96 -0
- package/dist/apps/cli/commands/mongodb/projectMongoGetShell.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/projectMongoPortForward.d.ts +3 -0
- package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js +105 -0
- package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js.map +1 -0
- package/dist/apps/cli/commands/mongodb/utils/index.d.ts +13 -0
- package/dist/apps/cli/commands/mongodb/utils/index.js +167 -0
- package/dist/apps/cli/commands/mongodb/utils/index.js.map +1 -0
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.js +137 -0
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -0
- package/dist/apps/cli/commands/project/commandConfigSecrets.d.ts +4 -0
- package/dist/apps/cli/commands/project/commandConfigSecrets.js +320 -0
- package/dist/apps/cli/commands/project/commandConfigSecrets.js.map +1 -0
- package/dist/apps/cli/commands/project/commandCopyDB.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandCopyDB.js +102 -0
- package/dist/apps/cli/commands/project/commandCopyDB.js.map +1 -0
- package/dist/apps/cli/commands/project/commandDeletePods.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandDeletePods.js +120 -0
- package/dist/apps/cli/commands/project/commandDeletePods.js.map +1 -0
- package/dist/apps/cli/commands/project/commandDeleteProject.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandDeleteProject.js +97 -0
- package/dist/apps/cli/commands/project/commandDeleteProject.js.map +1 -0
- package/dist/apps/cli/commands/project/commandEnvVars.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandEnvVars.js +74 -0
- package/dist/apps/cli/commands/project/commandEnvVars.js.map +1 -0
- package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js +58 -0
- package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js.map +1 -0
- package/dist/apps/cli/commands/project/commandGetShell.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandGetShell.js +92 -0
- package/dist/apps/cli/commands/project/commandGetShell.js.map +1 -0
- package/dist/apps/cli/commands/project/commandGitlabCi.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandGitlabCi.js +185 -0
- package/dist/apps/cli/commands/project/commandGitlabCi.js.map +1 -0
- package/dist/apps/cli/commands/project/commandInitProject.old.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandInitProject.old.js +345 -0
- package/dist/apps/cli/commands/project/commandInitProject.old.js.map +1 -0
- package/dist/apps/cli/commands/project/commandListPods.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandListPods.js +78 -0
- package/dist/apps/cli/commands/project/commandListPods.js.map +1 -0
- package/dist/apps/cli/commands/project/commandMigrateHelm3.d.ts +7 -0
- package/dist/apps/cli/commands/project/commandMigrateHelm3.js +113 -0
- package/dist/apps/cli/commands/project/commandMigrateHelm3.js.map +1 -0
- package/dist/apps/cli/commands/project/commandNamespace.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandNamespace.js +70 -0
- package/dist/apps/cli/commands/project/commandNamespace.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenCostDashboard.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenCostDashboard.js +83 -0
- package/dist/apps/cli/commands/project/commandOpenCostDashboard.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenDashboard.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenDashboard.js +85 -0
- package/dist/apps/cli/commands/project/commandOpenDashboard.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenEnv.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenEnv.js +80 -0
- package/dist/apps/cli/commands/project/commandOpenEnv.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenGit.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenGit.js +61 -0
- package/dist/apps/cli/commands/project/commandOpenGit.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenGrafana.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenGrafana.js +83 -0
- package/dist/apps/cli/commands/project/commandOpenGrafana.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenGrafanaPod.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js +99 -0
- package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js.map +1 -0
- package/dist/apps/cli/commands/project/commandOpenLogs.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandOpenLogs.js +87 -0
- package/dist/apps/cli/commands/project/commandOpenLogs.js.map +1 -0
- package/dist/apps/cli/commands/project/commandPauseProject.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandPauseProject.js +97 -0
- package/dist/apps/cli/commands/project/commandPauseProject.js.map +1 -0
- package/dist/apps/cli/commands/project/commandPortForward.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandPortForward.js +106 -0
- package/dist/apps/cli/commands/project/commandPortForward.js.map +1 -0
- package/dist/apps/cli/commands/project/commandSetup.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandSetup.js +58 -0
- package/dist/apps/cli/commands/project/commandSetup.js.map +1 -0
- package/dist/apps/cli/commands/project/commandTriggerCronjob.d.ts +3 -0
- package/dist/apps/cli/commands/project/commandTriggerCronjob.js +144 -0
- package/dist/apps/cli/commands/project/commandTriggerCronjob.js.map +1 -0
- package/dist/apps/cli/commands/project/index.d.ts +3 -0
- package/dist/apps/cli/commands/project/index.js +94 -0
- package/dist/apps/cli/commands/project/index.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/index.d.ts +2 -0
- package/dist/apps/cli/commands/project/setup/index.js +103 -0
- package/dist/apps/cli/commands/project/setup/index.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.d.ts +2 -0
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.js +115 -0
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupContext.d.ts +3 -0
- package/dist/apps/cli/commands/project/setup/setupContext.js +74 -0
- package/dist/apps/cli/commands/project/setup/setupContext.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupKubernetes.d.ts +3 -0
- package/dist/apps/cli/commands/project/setup/setupKubernetes.js +132 -0
- package/dist/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -0
- package/dist/apps/cli/commands/project/utils/autocompletions.d.ts +3 -0
- package/dist/apps/cli/commands/project/utils/autocompletions.js +96 -0
- package/dist/apps/cli/commands/project/utils/autocompletions.js.map +1 -0
- package/dist/apps/cli/commands/project/utils/ensureCluster.d.ts +1 -0
- package/dist/apps/cli/commands/project/utils/ensureCluster.js +84 -0
- package/dist/apps/cli/commands/project/utils/ensureCluster.js.map +1 -0
- package/dist/apps/cli/commands/project/utils/ensureNamespace.d.ts +2 -0
- package/dist/apps/cli/commands/project/utils/ensureNamespace.js +104 -0
- package/dist/apps/cli/commands/project/utils/ensureNamespace.js.map +1 -0
- package/dist/apps/cli/commands/project/utils/showProjectBanner.d.ts +2 -0
- package/dist/apps/cli/commands/project/utils/showProjectBanner.js +58 -0
- package/dist/apps/cli/commands/project/utils/showProjectBanner.js.map +1 -0
- package/dist/apps/cli/commands/shared/index.d.ts +3 -0
- package/dist/apps/cli/commands/shared/index.js +70 -0
- package/dist/apps/cli/commands/shared/index.js.map +1 -0
- package/dist/apps/cli/commands/theStuffThatReallyMatters/index.d.ts +3 -0
- package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js +101 -0
- package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js.map +1 -0
- package/dist/apps/cli/config/writeConfig.d.ts +5 -0
- package/dist/apps/cli/config/writeConfig.js +106 -0
- package/dist/apps/cli/config/writeConfig.js.map +1 -0
- package/dist/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -0
- package/dist/apps/cli/utils/getGoogleAuthUserNumber.js +69 -0
- package/dist/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -0
- package/dist/apps/cli/verify/index.d.ts +2 -0
- package/dist/apps/cli/verify/index.js +94 -0
- package/dist/apps/cli/verify/index.js.map +1 -0
- package/dist/apps/cli/verify/migration/fromv2.d.ts +4 -0
- package/dist/apps/cli/verify/migration/fromv2.js +347 -0
- package/dist/apps/cli/verify/migration/fromv2.js.map +1 -0
- package/dist/apps/cli/verify/migration/migrateSecrets.d.ts +4 -0
- package/dist/apps/cli/verify/migration/migrateSecrets.js +88 -0
- package/dist/apps/cli/verify/migration/migrateSecrets.js.map +1 -0
- package/dist/apps/cli/verify/migration/oldGitlabCi.d.ts +18 -0
- package/dist/apps/cli/verify/migration/oldGitlabCi.js +30 -0
- package/dist/apps/cli/verify/migration/oldGitlabCi.js.map +1 -0
- package/dist/catenv.d.ts +1 -0
- package/dist/catenv.js +15 -0
- package/dist/catenv.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +15 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/constants.d.ts +3 -0
- package/dist/config/constants.js +7 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/config/getProjectConfig.d.ts +24 -0
- package/dist/config/getProjectConfig.js +259 -0
- package/dist/config/getProjectConfig.js.map +1 -0
- package/dist/k8sApi/index.d.ts +8 -0
- package/dist/k8sApi/index.js +29 -0
- package/dist/k8sApi/index.js.map +1 -0
- package/dist/packageInfos.d.ts +2 -0
- package/dist/packageInfos.js +6 -0
- package/dist/packageInfos.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types.d.ts +18 -0
- package/dist/types/types.js +3 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/cluster.d.ts +3 -0
- package/dist/utils/cluster.js +73 -0
- package/dist/utils/cluster.js.map +1 -0
- package/dist/utils/editAsFile.d.ts +1 -0
- package/dist/utils/editAsFile.js +85 -0
- package/dist/utils/editAsFile.js.map +1 -0
- package/dist/utils/files.d.ts +2 -0
- package/dist/utils/files.js +83 -0
- package/dist/utils/files.js.map +1 -0
- package/dist/utils/getEditor.d.ts +4 -0
- package/dist/utils/getEditor.js +70 -0
- package/dist/utils/getEditor.js.map +1 -0
- package/dist/utils/gitlab.d.ts +22 -0
- package/dist/utils/gitlab.js +278 -0
- package/dist/utils/gitlab.js.map +1 -0
- package/dist/utils/log.d.ts +1 -0
- package/dist/utils/log.js +14 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/passwordstore/index.d.ts +8 -0
- package/dist/utils/passwordstore/index.js +378 -0
- package/dist/utils/passwordstore/index.js.map +1 -0
- package/dist/utils/portForward.d.ts +4 -0
- package/dist/utils/portForward.js +116 -0
- package/dist/utils/portForward.js.map +1 -0
- package/dist/utils/preferences/index.d.ts +3 -0
- package/dist/utils/preferences/index.js +119 -0
- package/dist/utils/preferences/index.js.map +1 -0
- package/dist/utils/projects/index.d.ts +8 -0
- package/dist/utils/projects/index.js +153 -0
- package/dist/utils/projects/index.js.map +1 -0
- package/dist/utils/promise.d.ts +2 -0
- package/dist/utils/promise.js +62 -0
- package/dist/utils/promise.js.map +1 -0
- package/dist/utils/shell.d.ts +1 -0
- package/dist/utils/shell.js +81 -0
- package/dist/utils/shell.js.map +1 -0
- package/package.json +16 -21
- package/src/apps/catenv/catenv.ts +55 -27
- package/src/apps/{shell/shell.ts → cli/cli.ts} +10 -2
- package/src/apps/{shell → cli}/commands/general/index.ts +7 -46
- package/src/apps/{shell → cli}/commands/general/namespaceAutoCompletion.ts +0 -0
- package/src/apps/{shell → cli}/commands/general/portForward.ts +3 -2
- package/src/apps/{shell → cli}/commands/mongodb/index.ts +1 -1
- package/src/apps/{shell → cli}/commands/mongodb/projectMongoDestroyMember.ts +18 -18
- package/src/apps/{shell → cli}/commands/mongodb/projectMongoGetShell.ts +12 -10
- package/src/apps/{shell → cli}/commands/mongodb/projectMongoPortForward.ts +13 -8
- package/src/apps/{shell → cli}/commands/mongodb/utils/index.ts +9 -8
- package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +88 -0
- package/src/apps/cli/commands/project/commandConfigSecrets.ts +220 -0
- package/src/apps/{shell → cli}/commands/project/commandCopyDB.ts +24 -26
- package/src/apps/{shell → cli}/commands/project/commandDeletePods.ts +10 -10
- package/src/apps/{shell → cli}/commands/project/commandDeleteProject.ts +7 -8
- package/src/apps/cli/commands/project/commandEnvVars.ts +15 -0
- package/src/apps/{shell → cli}/commands/project/commandGetMyTotalWorktime.ts +2 -2
- package/src/apps/{shell → cli}/commands/project/commandGetShell.ts +10 -10
- package/src/apps/{shell → cli}/commands/project/commandGitlabCi.ts +1 -1
- package/src/apps/{shell/commands/project/commandInitProject.ts → cli/commands/project/commandInitProject.old.ts} +14 -6
- package/src/apps/cli/commands/project/commandListPods.ts +18 -0
- package/src/apps/{shell → cli}/commands/project/commandMigrateHelm3.ts +16 -7
- package/src/apps/cli/commands/project/commandNamespace.ts +14 -0
- package/src/apps/{shell → cli}/commands/project/commandOpenCostDashboard.ts +10 -7
- package/src/apps/cli/commands/project/commandOpenDashboard.ts +48 -0
- package/src/apps/cli/commands/project/commandOpenEnv.ts +22 -0
- package/src/apps/{shell → cli}/commands/project/commandOpenGit.ts +3 -3
- package/src/apps/{shell → cli}/commands/project/commandOpenGrafana.ts +7 -7
- package/src/apps/{shell → cli}/commands/project/commandOpenGrafanaPod.ts +9 -10
- package/src/apps/cli/commands/project/commandOpenLogs.ts +52 -0
- package/src/apps/{shell → cli}/commands/project/commandPauseProject.ts +9 -7
- package/src/apps/{shell → cli}/commands/project/commandPortForward.ts +8 -8
- package/src/apps/cli/commands/project/commandSetup.ts +12 -0
- package/src/apps/{shell → cli}/commands/project/commandTriggerCronjob.ts +10 -10
- package/src/apps/{shell → cli}/commands/project/index.ts +6 -7
- package/src/apps/cli/commands/project/setup/index.ts +42 -0
- package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +72 -0
- package/src/apps/cli/commands/project/setup/setupContext.ts +37 -0
- package/src/apps/cli/commands/project/setup/setupKubernetes.ts +112 -0
- package/src/apps/cli/commands/project/utils/autocompletions.ts +26 -0
- package/src/apps/cli/commands/project/utils/ensureCluster.ts +42 -0
- package/src/apps/cli/commands/project/utils/ensureNamespace.ts +56 -0
- package/src/apps/cli/commands/project/utils/showProjectBanner.ts +11 -0
- package/src/apps/cli/commands/shared/index.ts +36 -0
- package/src/apps/{shell → cli}/commands/theStuffThatReallyMatters/index.ts +7 -26
- package/src/apps/cli/config/writeConfig.ts +71 -0
- package/src/apps/{shell → cli}/utils/getGoogleAuthUserNumber.ts +0 -0
- package/src/apps/cli/verify/index.ts +30 -0
- package/src/apps/cli/verify/migration/fromv2.ts +264 -0
- package/src/apps/cli/verify/migration/migrateSecrets.ts +37 -0
- package/src/apps/cli/verify/migration/oldGitlabCi.ts +48 -0
- package/src/catenv.ts +11 -0
- package/src/cli.ts +9 -0
- package/src/config/constants.ts +0 -1
- package/src/config/getProjectConfig.ts +160 -0
- package/src/k8sApi/index.ts +22 -6
- package/src/types/types.ts +0 -2
- package/src/utils/cluster.ts +6 -15
- package/src/utils/editAsFile.ts +31 -0
- package/src/utils/files.ts +6 -2
- package/src/utils/gitlab.ts +144 -34
- package/src/utils/passwordstore/index.ts +19 -21
- package/src/utils/preferences/index.ts +6 -3
- package/src/utils/projects/index.ts +18 -137
- package/tsconfig.json +3 -7
- package/bin/catenv.sh +0 -1
- package/src/apps/shell/commands/project/commandCloudSqlProxy.ts +0 -65
- package/src/apps/shell/commands/project/commandConfigSecrets.ts +0 -245
- package/src/apps/shell/commands/project/commandEnvVars.ts +0 -17
- package/src/apps/shell/commands/project/commandInitGitlab.ts +0 -157
- package/src/apps/shell/commands/project/commandListPods.ts +0 -21
- package/src/apps/shell/commands/project/commandNamespace.ts +0 -12
- package/src/apps/shell/commands/project/commandOpenDashboard.ts +0 -27
- package/src/apps/shell/commands/project/commandOpenEnv.ts +0 -18
- package/src/apps/shell/commands/project/commandOpenLogs.ts +0 -23
- package/src/apps/shell/commands/project/commandVariables.ts +0 -13
- package/src/apps/shell/commands/project/utils/autocompletions.ts +0 -7
- package/src/apps/shell/commands/project/utils/ensureCluster.ts +0 -31
- package/src/apps/shell/commands/project/utils/ensureNamespace.ts +0 -32
- package/src/apps/shell/commands/project/utils/monorepo.ts +0 -45
- package/src/apps/shell/commands/shared/index.ts +0 -31
- package/src/config/clusters.ts +0 -45
- package/src/index.ts +0 -17
- package/src/types/git-repo-name.d.ts +0 -1
- package/src/types/yawn-yaml.d.ts +0 -1
- package/src/utils/dashboardToken.ts +0 -20
- package/src/utils/formatEnvVars.ts +0 -7
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import memoizee from "memoizee";
|
|
2
2
|
import Vorpal from "vorpal";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
connectToCluster,
|
|
6
|
-
getAllClusterNames,
|
|
7
|
-
getCurrentConnectedClusterName,
|
|
8
|
-
getCurrentContext,
|
|
9
|
-
} from "../../../../utils/cluster";
|
|
3
|
+
import { getk8sApi } from "../../../../k8sApi";
|
|
4
|
+
import { getCurrentContext } from "../../../../utils/cluster";
|
|
10
5
|
import { logError } from "../../../../utils/log";
|
|
11
6
|
import { syncBitwarden } from "../../../../utils/passwordstore";
|
|
12
7
|
import {
|
|
@@ -14,16 +9,12 @@ import {
|
|
|
14
9
|
stopPortForward,
|
|
15
10
|
} from "../../../../utils/portForward";
|
|
16
11
|
import { getShell } from "../../../../utils/shell";
|
|
17
|
-
import { getGoogleAuthUserNumber } from "../../utils/getGoogleAuthUserNumber";
|
|
18
|
-
import {
|
|
19
|
-
openGoogleCloudKubernetesDashboard,
|
|
20
|
-
openGoogleCloudLogs,
|
|
21
|
-
} from "../shared";
|
|
22
12
|
import { namespaceAutoCompletion } from "./namespaceAutoCompletion";
|
|
23
13
|
import portForward from "./portForward";
|
|
24
14
|
|
|
25
15
|
const getAllNamespaces = memoizee(
|
|
26
16
|
async () => {
|
|
17
|
+
const k8sApi = getk8sApi();
|
|
27
18
|
const res = await k8sApi.listNamespace();
|
|
28
19
|
return res.body.items;
|
|
29
20
|
},
|
|
@@ -34,14 +25,7 @@ export const getAllNamespacesNames = async () => {
|
|
|
34
25
|
const namespaces = await getAllNamespaces();
|
|
35
26
|
return namespaces.map((n) => n.metadata.name);
|
|
36
27
|
};
|
|
37
|
-
export default (vorpal: Vorpal) => {
|
|
38
|
-
vorpal
|
|
39
|
-
.command("connect-cluster <clustername>")
|
|
40
|
-
.autocomplete(getAllClusterNames())
|
|
41
|
-
.action(async function ({ clustername }) {
|
|
42
|
-
this.log(`connecting to ${clustername}`);
|
|
43
|
-
await connectToCluster(clustername);
|
|
44
|
-
});
|
|
28
|
+
export default async (vorpal: Vorpal) => {
|
|
45
29
|
vorpal.command("current-context").action(async function () {
|
|
46
30
|
this.log(await getCurrentContext());
|
|
47
31
|
});
|
|
@@ -57,6 +41,7 @@ export default (vorpal: Vorpal) => {
|
|
|
57
41
|
.command("list-secrets <namespace>", "show secrets")
|
|
58
42
|
.autocomplete(namespaceAutoCompletion)
|
|
59
43
|
.action(async function ({ namespace }) {
|
|
44
|
+
const k8sApi = getk8sApi();
|
|
60
45
|
const res = await k8sApi.listNamespacedSecret(namespace);
|
|
61
46
|
|
|
62
47
|
this.log(res.body.items.map((n) => n.metadata.name).join("\n"));
|
|
@@ -71,6 +56,7 @@ export default (vorpal: Vorpal) => {
|
|
|
71
56
|
.command("list-pods <namespace>", "list all pods of namespace")
|
|
72
57
|
.autocomplete(namespaceAutoCompletion)
|
|
73
58
|
.action(async function ({ namespace }) {
|
|
59
|
+
const k8sApi = getk8sApi();
|
|
74
60
|
const res = await k8sApi.listNamespacedPod(namespace);
|
|
75
61
|
this.log(res.body.items.map((n) => n.metadata.name).join("\n"));
|
|
76
62
|
});
|
|
@@ -82,36 +68,11 @@ export default (vorpal: Vorpal) => {
|
|
|
82
68
|
stopPortForward(name.trim());
|
|
83
69
|
});
|
|
84
70
|
|
|
85
|
-
vorpal
|
|
86
|
-
.command("open-dashboard <namespace>", "open kubernetes dashboard")
|
|
87
|
-
.autocomplete(namespaceAutoCompletion)
|
|
88
|
-
.action(async function ({ namespace }) {
|
|
89
|
-
const clustername = await getCurrentConnectedClusterName();
|
|
90
|
-
const authGoogleNumber = await getGoogleAuthUserNumber.call(this, vorpal);
|
|
91
|
-
|
|
92
|
-
await openGoogleCloudKubernetesDashboard(
|
|
93
|
-
authGoogleNumber,
|
|
94
|
-
clustername,
|
|
95
|
-
namespace
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
vorpal
|
|
99
|
-
.command(
|
|
100
|
-
"open-logs <namespace>",
|
|
101
|
-
"open google cloud logs (stackdriver stuff)"
|
|
102
|
-
)
|
|
103
|
-
.autocomplete(namespaceAutoCompletion)
|
|
104
|
-
.action(async function ({ namespace }) {
|
|
105
|
-
const clustername = await getCurrentConnectedClusterName();
|
|
106
|
-
const authGoogleNumber = await getGoogleAuthUserNumber.call(this, vorpal);
|
|
107
|
-
|
|
108
|
-
await openGoogleCloudLogs(authGoogleNumber, clustername, namespace);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
71
|
vorpal
|
|
112
72
|
.command("get-shell <namespace>", "get a shell to a pod in the environment")
|
|
113
73
|
.autocomplete(namespaceAutoCompletion)
|
|
114
74
|
.action(async function ({ namespace }) {
|
|
75
|
+
const k8sApi = getk8sApi();
|
|
115
76
|
const res = await k8sApi.listNamespacedPod(namespace);
|
|
116
77
|
if (res.body.items.length === 0) {
|
|
117
78
|
logError(this, "sorry, no pods found");
|
|
File without changes
|
|
@@ -3,14 +3,15 @@ import { logError } from "../../../../utils/log";
|
|
|
3
3
|
|
|
4
4
|
import { startPortForward } from "../../../../utils/portForward";
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { getk8sApi } from "../../../../k8sApi";
|
|
7
7
|
import { namespaceAutoCompletion } from "./namespaceAutoCompletion";
|
|
8
8
|
|
|
9
|
-
export default (vorpal: Vorpal) =>
|
|
9
|
+
export default async (vorpal: Vorpal) =>
|
|
10
10
|
vorpal
|
|
11
11
|
.command("port-forward <namespace>", "start port-forwarding")
|
|
12
12
|
.autocomplete(namespaceAutoCompletion)
|
|
13
13
|
.action(async function ({ namespace }) {
|
|
14
|
+
const k8sApi = getk8sApi();
|
|
14
15
|
const res = await k8sApi.listNamespacedPod(namespace);
|
|
15
16
|
if (res.body.items.length === 0) {
|
|
16
17
|
logError(this, "sorry, no pods found");
|
|
@@ -3,7 +3,7 @@ import projectMongoDestroyMember from "./projectMongoDestroyMember";
|
|
|
3
3
|
import projectMongoGetShell from "./projectMongoGetShell";
|
|
4
4
|
import projectMongoPortForward from "./projectMongoPortForward";
|
|
5
5
|
|
|
6
|
-
export default (vorpal: Vorpal) => {
|
|
6
|
+
export default async (vorpal: Vorpal) => {
|
|
7
7
|
projectMongoGetShell(vorpal);
|
|
8
8
|
projectMongoPortForward(vorpal);
|
|
9
9
|
projectMongoDestroyMember(vorpal);
|
|
@@ -3,9 +3,9 @@ import Vorpal from "vorpal";
|
|
|
3
3
|
import { logError } from "../../../../utils/log";
|
|
4
4
|
import {
|
|
5
5
|
getProjectNamespace,
|
|
6
|
-
getProjectPvcs
|
|
6
|
+
getProjectPvcs,
|
|
7
7
|
} from "../../../../utils/projects";
|
|
8
|
-
import {
|
|
8
|
+
import { envAndComponents } from "../project/utils/autocompletions";
|
|
9
9
|
import ensureCluster from "../project/utils/ensureCluster";
|
|
10
10
|
import { getMongoDbPodsWithReplInfo } from "./utils";
|
|
11
11
|
|
|
@@ -31,18 +31,18 @@ const removeFinalizerAndDelete = async (
|
|
|
31
31
|
) => {
|
|
32
32
|
return Promise.all([
|
|
33
33
|
removeFinalizer(namespace, type, name),
|
|
34
|
-
await deleteResource(namespace, type, name)
|
|
34
|
+
await deleteResource(namespace, type, name),
|
|
35
35
|
]);
|
|
36
36
|
};
|
|
37
|
-
export default (vorpal: Vorpal) =>
|
|
37
|
+
export default async (vorpal: Vorpal) =>
|
|
38
38
|
vorpal
|
|
39
39
|
.command(
|
|
40
|
-
"project-mongo-destroy-member <
|
|
40
|
+
"project-mongo-destroy-member <envComponent>",
|
|
41
41
|
"DESTROY a member of a replicaset in order to reinitialize it"
|
|
42
42
|
)
|
|
43
|
-
.autocomplete(
|
|
44
|
-
.action(async function({
|
|
45
|
-
await ensureCluster.call(this);
|
|
43
|
+
.autocomplete(await envAndComponents())
|
|
44
|
+
.action(async function ({ envComponent }) {
|
|
45
|
+
await ensureCluster.call(this, envComponent);
|
|
46
46
|
this.log(
|
|
47
47
|
"this command tries to delete a (secondary) member of the replicaset, it's persistent volume claim (pvc) and the volume"
|
|
48
48
|
);
|
|
@@ -67,18 +67,18 @@ export default (vorpal: Vorpal) =>
|
|
|
67
67
|
default: true,
|
|
68
68
|
message: "DO YOU UNDERSTAND?",
|
|
69
69
|
name: "understood",
|
|
70
|
-
type: "confirm"
|
|
70
|
+
type: "confirm",
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
if (!understood) {
|
|
74
74
|
throw new Error("abort");
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
const namespace = await getProjectNamespace(
|
|
78
|
-
const mongodbPods = await getMongoDbPodsWithReplInfo(
|
|
77
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
78
|
+
const mongodbPods = await getMongoDbPodsWithReplInfo(envComponent);
|
|
79
79
|
|
|
80
|
-
const pvcs = await getProjectPvcs(
|
|
81
|
-
const secondaries = mongodbPods.filter(pod => !pod.isMaster);
|
|
80
|
+
const pvcs = await getProjectPvcs(envComponent);
|
|
81
|
+
const secondaries = mongodbPods.filter((pod) => !pod.isMaster);
|
|
82
82
|
|
|
83
83
|
if (secondaries.length === 0) {
|
|
84
84
|
logError(this, "sorry, no pods found");
|
|
@@ -89,16 +89,16 @@ export default (vorpal: Vorpal) =>
|
|
|
89
89
|
await this.prompt({
|
|
90
90
|
type: "list",
|
|
91
91
|
name: "podName",
|
|
92
|
-
choices: secondaries.map(p => ({
|
|
92
|
+
choices: secondaries.map((p) => ({
|
|
93
93
|
name: `[ secondary ] ${p.podName}`,
|
|
94
|
-
value: p.podName
|
|
94
|
+
value: p.podName,
|
|
95
95
|
})),
|
|
96
|
-
message: "Which pod? 🤔"
|
|
96
|
+
message: "Which pod? 🤔",
|
|
97
97
|
})
|
|
98
98
|
).podName;
|
|
99
99
|
|
|
100
100
|
const thePvc = pvcs.find(
|
|
101
|
-
pvc => pvc.metadata.name === `datadir-${podName}`
|
|
101
|
+
(pvc) => pvc.metadata.name === `datadir-${podName}`
|
|
102
102
|
);
|
|
103
103
|
if (!thePvc) {
|
|
104
104
|
logError(this, `sorry, no pvc found for ${podName}`);
|
|
@@ -109,7 +109,7 @@ export default (vorpal: Vorpal) =>
|
|
|
109
109
|
message:
|
|
110
110
|
"THIS WILL DESTROY THE POD, ITS VOLUME AND ALL ITS DATA 🙀🙀🙀!!! continue? 🤔",
|
|
111
111
|
name: "shouldContinue",
|
|
112
|
-
type: "confirm"
|
|
112
|
+
type: "confirm",
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
if (!shouldContinue) {
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import Vorpal from "vorpal";
|
|
2
2
|
import { logError } from "../../../../utils/log";
|
|
3
3
|
import { getProjectNamespace } from "../../../../utils/projects";
|
|
4
|
-
import {
|
|
4
|
+
import { envAndComponents } from "../project/utils/autocompletions";
|
|
5
5
|
import ensureCluster from "../project/utils/ensureCluster";
|
|
6
6
|
import {
|
|
7
7
|
getMongodbShell,
|
|
8
|
-
getProjectMongodbAllPodsSortedWithLabel
|
|
8
|
+
getProjectMongodbAllPodsSortedWithLabel,
|
|
9
9
|
} from "./utils";
|
|
10
10
|
|
|
11
|
-
export default (vorpal: Vorpal) =>
|
|
11
|
+
export default async (vorpal: Vorpal) =>
|
|
12
12
|
vorpal
|
|
13
13
|
.command(
|
|
14
|
-
"project-mongo-get-shell <
|
|
14
|
+
"project-mongo-get-shell <envComponent>",
|
|
15
15
|
"get a shell to a mongodb in the environment"
|
|
16
16
|
)
|
|
17
|
-
.autocomplete(
|
|
18
|
-
.action(async function({
|
|
19
|
-
await ensureCluster.call(this);
|
|
20
|
-
const namespace = await getProjectNamespace(
|
|
21
|
-
const podNames = await getProjectMongodbAllPodsSortedWithLabel(
|
|
17
|
+
.autocomplete(await envAndComponents())
|
|
18
|
+
.action(async function ({ envComponent }) {
|
|
19
|
+
await ensureCluster.call(this, envComponent);
|
|
20
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
21
|
+
const podNames = await getProjectMongodbAllPodsSortedWithLabel(
|
|
22
|
+
envComponent
|
|
23
|
+
);
|
|
22
24
|
if (podNames.length === 0) {
|
|
23
25
|
logError(this, "sorry, no pods found");
|
|
24
26
|
return;
|
|
@@ -32,7 +34,7 @@ export default (vorpal: Vorpal) =>
|
|
|
32
34
|
type: "list",
|
|
33
35
|
name: "podName",
|
|
34
36
|
choices: podNames,
|
|
35
|
-
message: "Which pod? 🤔"
|
|
37
|
+
message: "Which pod? 🤔",
|
|
36
38
|
})
|
|
37
39
|
).podName;
|
|
38
40
|
}
|
|
@@ -2,18 +2,23 @@ import Vorpal from "vorpal";
|
|
|
2
2
|
import { logError } from "../../../../utils/log";
|
|
3
3
|
import { startPortForward } from "../../../../utils/portForward";
|
|
4
4
|
import { getProjectNamespace } from "../../../../utils/projects";
|
|
5
|
-
import {
|
|
5
|
+
import { envAndComponents } from "../project/utils/autocompletions";
|
|
6
6
|
import ensureCluster from "../project/utils/ensureCluster";
|
|
7
7
|
import { getProjectMongodbAllPodsSortedWithLabel } from "./utils";
|
|
8
8
|
|
|
9
|
-
export default (vorpal: Vorpal) =>
|
|
9
|
+
export default async (vorpal: Vorpal) =>
|
|
10
10
|
vorpal
|
|
11
|
-
.command(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
.command(
|
|
12
|
+
"project-mongo-port-forward <envComponent>",
|
|
13
|
+
"port foward to a mongodb"
|
|
14
|
+
)
|
|
15
|
+
.autocomplete(await envAndComponents())
|
|
16
|
+
.action(async function ({ envComponent }) {
|
|
17
|
+
await ensureCluster.call(this, envComponent);
|
|
18
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
19
|
+
const podNames = await getProjectMongodbAllPodsSortedWithLabel(
|
|
20
|
+
envComponent
|
|
21
|
+
);
|
|
17
22
|
if (podNames.length === 0) {
|
|
18
23
|
logError(this, "sorry, no pods found");
|
|
19
24
|
return;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { exec, spawn } from "child-process-promise";
|
|
2
|
-
import { Env } from "../../../../../types/types";
|
|
3
2
|
import {
|
|
4
3
|
getProjectNamespace,
|
|
5
4
|
getProjectPodNames,
|
|
@@ -8,8 +7,8 @@ import {
|
|
|
8
7
|
const filterMongoDbs = (podNames: string[]) =>
|
|
9
8
|
podNames.filter((name) => name.includes("mongodb-replicaset"));
|
|
10
9
|
|
|
11
|
-
export const getProjectMongodbAllPods = async (
|
|
12
|
-
filterMongoDbs(await getProjectPodNames(
|
|
10
|
+
export const getProjectMongodbAllPods = async (envComponent: string) =>
|
|
11
|
+
filterMongoDbs(await getProjectPodNames(envComponent));
|
|
13
12
|
|
|
14
13
|
export const getMongodbShell = async (namespace: string, podName: string) => {
|
|
15
14
|
const command = `kubectl exec -it ${podName} --namespace ${namespace} mongo`;
|
|
@@ -55,12 +54,12 @@ export const podIsMaster = async (namespace: string, podName: string) => {
|
|
|
55
54
|
|
|
56
55
|
const spaces = (n: number) => " ".repeat(n);
|
|
57
56
|
|
|
58
|
-
export const getMongoDbPodsWithReplInfo = async (
|
|
59
|
-
const namespace = await getProjectNamespace(
|
|
57
|
+
export const getMongoDbPodsWithReplInfo = async (envComponent: string) => {
|
|
58
|
+
const namespace = await getProjectNamespace(envComponent);
|
|
60
59
|
return (
|
|
61
60
|
await Promise.all(
|
|
62
61
|
(
|
|
63
|
-
await getProjectMongodbAllPods(
|
|
62
|
+
await getProjectMongodbAllPods(envComponent)
|
|
64
63
|
).map(async (podName) => ({
|
|
65
64
|
podName,
|
|
66
65
|
componentName: podName.replace(/-mongodb-replicaset-[0-9]+/, ""),
|
|
@@ -70,8 +69,10 @@ export const getMongoDbPodsWithReplInfo = async (env: Env) => {
|
|
|
70
69
|
).sort((podA, podB) => (podA.isMaster ? (podB.isMaster ? 0 : -1) : 1));
|
|
71
70
|
};
|
|
72
71
|
|
|
73
|
-
export const getProjectMongodbAllPodsSortedWithLabel = async (
|
|
74
|
-
|
|
72
|
+
export const getProjectMongodbAllPodsSortedWithLabel = async (
|
|
73
|
+
envComponent: string
|
|
74
|
+
) => {
|
|
75
|
+
const pods = await getMongoDbPodsWithReplInfo(envComponent);
|
|
75
76
|
const maxComponentNameLength = Math.max(
|
|
76
77
|
...pods.map((c) => c.componentName.length)
|
|
77
78
|
);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { isOfDeployType } from "@catladder/pipeline";
|
|
2
|
+
import { spawn } from "child-process-promise";
|
|
3
|
+
import { writeFile } from "fs-extra";
|
|
4
|
+
import { withFile } from "tmp-promise";
|
|
5
|
+
import Vorpal from "vorpal";
|
|
6
|
+
import {
|
|
7
|
+
getEnvVars,
|
|
8
|
+
getGitlabVar,
|
|
9
|
+
getPipelineContextByChoice,
|
|
10
|
+
getProjectConfig,
|
|
11
|
+
parseChoice,
|
|
12
|
+
} from "../../../../config/getProjectConfig";
|
|
13
|
+
import { envAndComponents } from "./utils/autocompletions";
|
|
14
|
+
|
|
15
|
+
export default async (vorpal: Vorpal) =>
|
|
16
|
+
vorpal
|
|
17
|
+
.command("project-cloud-sql-proxy <envComponent>", "proxy to cloud sql db")
|
|
18
|
+
.autocomplete(await envAndComponents())
|
|
19
|
+
.action(async function ({ envComponent }) {
|
|
20
|
+
const { env, componentName } = parseChoice(envComponent);
|
|
21
|
+
|
|
22
|
+
const config = await getProjectConfig();
|
|
23
|
+
// skynet-164509:europe-west6:pvl-cyclomania-review=tcp:5432
|
|
24
|
+
|
|
25
|
+
const { localPort } = await this.prompt({
|
|
26
|
+
type: "number",
|
|
27
|
+
name: "localPort",
|
|
28
|
+
default: "54320",
|
|
29
|
+
message: "Local port: ",
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const envVars = await getEnvVars(this, env, componentName);
|
|
33
|
+
const POSTGRESQL_PASSWORD = envVars?.POSTGRESQL_PASSWORD;
|
|
34
|
+
|
|
35
|
+
const context = await getPipelineContextByChoice(env, componentName);
|
|
36
|
+
if (!isOfDeployType(context.componentConfig.deploy, "kubernetes")) {
|
|
37
|
+
throw new Error("currently only supported for kubernetes deployment");
|
|
38
|
+
}
|
|
39
|
+
this.log("");
|
|
40
|
+
this.log(`postgres-PW: ${POSTGRESQL_PASSWORD}`);
|
|
41
|
+
this.log("");
|
|
42
|
+
this.log(
|
|
43
|
+
`POSTGRESQL_URL=postgresql://postgres:${POSTGRESQL_PASSWORD}@localhost:${localPort}/${context.environment.envVars.KUBE_APP_NAME}?schema=public`
|
|
44
|
+
);
|
|
45
|
+
this.log("");
|
|
46
|
+
|
|
47
|
+
const values = context.componentConfig.deploy.values;
|
|
48
|
+
|
|
49
|
+
const projectId =
|
|
50
|
+
values?.cloudsql?.projectId ||
|
|
51
|
+
context.componentConfig.deploy.cluster?.projectId;
|
|
52
|
+
|
|
53
|
+
const defaultInstanceId = `${config.customerName}-${config.appName}-${env}`;
|
|
54
|
+
const instanceId = values?.cloudsql?.instanceId || defaultInstanceId;
|
|
55
|
+
|
|
56
|
+
const defaultRegion = "europe-west6"; // currently hardcoded
|
|
57
|
+
const region = values?.cloudsql?.region || defaultRegion;
|
|
58
|
+
|
|
59
|
+
const instanceName = `${projectId}:${region}:${instanceId}=tcp:${localPort}`;
|
|
60
|
+
|
|
61
|
+
const cloudsqlProxyCredentials = await getGitlabVar(
|
|
62
|
+
this,
|
|
63
|
+
env,
|
|
64
|
+
componentName,
|
|
65
|
+
"cloudsqlProxyCredentials"
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (!cloudsqlProxyCredentials) {
|
|
69
|
+
// we store cloudsqlProxyCredentials on gitlab, but its currently get pushed via bitwarden due to legacy reasons
|
|
70
|
+
// this will be fixed with when https://git.panter.ch/catladder/catladder/-/merge_requests/32/ is merged
|
|
71
|
+
this.log(
|
|
72
|
+
"cloudsqlProxyCredentials env var missing in gitlab. Please contact gilde-ci-cd about that."
|
|
73
|
+
);
|
|
74
|
+
throw new Error("cloudsqlProxyCredentials missing in secrets");
|
|
75
|
+
}
|
|
76
|
+
await withFile(async ({ path: tmpFilePath }) => {
|
|
77
|
+
await writeFile(tmpFilePath, cloudsqlProxyCredentials);
|
|
78
|
+
|
|
79
|
+
await spawn(
|
|
80
|
+
"cloud_sql_proxy",
|
|
81
|
+
["-instances", instanceName, "-credential_file", tmpFilePath],
|
|
82
|
+
{
|
|
83
|
+
stdio: "inherit",
|
|
84
|
+
shell: true,
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/* eslint-disable no-constant-condition */
|
|
2
|
+
import { stripIndents } from "common-tags";
|
|
3
|
+
import { difference } from "lodash";
|
|
4
|
+
import Vorpal, { CommandInstance } from "vorpal";
|
|
5
|
+
import { GOOGLE_CLOUD_SQL_PASS_PATH } from "../../../../config/constants";
|
|
6
|
+
import {
|
|
7
|
+
getAllComponentsWithAllEnvsHierarchical,
|
|
8
|
+
getEnvironment,
|
|
9
|
+
getEnvVars,
|
|
10
|
+
getPipelineContextByChoice,
|
|
11
|
+
getProjectComponents,
|
|
12
|
+
parseChoice,
|
|
13
|
+
} from "../../../../config/getProjectConfig";
|
|
14
|
+
import { editAsFile } from "../../../../utils/editAsFile";
|
|
15
|
+
import { upsertAllVariables } from "../../../../utils/gitlab";
|
|
16
|
+
import { hasBitwarden, readPass } from "../../../../utils/passwordstore";
|
|
17
|
+
import { delay } from "../../../../utils/promise";
|
|
18
|
+
import { allEnvsAndAllComponents } from "./utils/autocompletions";
|
|
19
|
+
|
|
20
|
+
type Vars = {
|
|
21
|
+
[env: string]: {
|
|
22
|
+
[componentName: string]: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/* for convenience, parse json objects. that makes it easier to edit secrets that are object */
|
|
26
|
+
const resolveJson = (v: Vars) =>
|
|
27
|
+
Object.fromEntries(
|
|
28
|
+
Object.entries(v).map(([componentName, envs]) => {
|
|
29
|
+
return [
|
|
30
|
+
componentName,
|
|
31
|
+
Object.fromEntries(
|
|
32
|
+
Object.entries(envs).map(([env, secrets]) => [
|
|
33
|
+
env,
|
|
34
|
+
Object.fromEntries(
|
|
35
|
+
Object.entries(secrets).map(([key, value]) => {
|
|
36
|
+
try {
|
|
37
|
+
return [key, JSON.parse(value)];
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return [key, value];
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
),
|
|
43
|
+
])
|
|
44
|
+
),
|
|
45
|
+
];
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
const getEnvVarsToEdit = async (
|
|
49
|
+
instance: CommandInstance,
|
|
50
|
+
env: string,
|
|
51
|
+
componentName: string
|
|
52
|
+
) => {
|
|
53
|
+
const { secretEnvVarKeys } = await getEnvironment(env, componentName);
|
|
54
|
+
|
|
55
|
+
const allEnvVars = await getEnvVars(instance, env, componentName);
|
|
56
|
+
return Object.fromEntries(
|
|
57
|
+
secretEnvVarKeys.map((key) => [key, allEnvVars[key]])
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
const doItFor = async (
|
|
61
|
+
instance: CommandInstance,
|
|
62
|
+
envAndComponents: {
|
|
63
|
+
[componentName: string]: string[];
|
|
64
|
+
}
|
|
65
|
+
) => {
|
|
66
|
+
let valuesToEdit: Vars = Object.fromEntries(
|
|
67
|
+
await Promise.all(
|
|
68
|
+
Object.entries(envAndComponents).map(async ([componentName, envs]) => [
|
|
69
|
+
componentName,
|
|
70
|
+
Object.fromEntries(
|
|
71
|
+
await Promise.all(
|
|
72
|
+
envs.map(async (env) => [
|
|
73
|
+
env,
|
|
74
|
+
await getEnvVarsToEdit(instance, env, componentName),
|
|
75
|
+
])
|
|
76
|
+
)
|
|
77
|
+
),
|
|
78
|
+
])
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
let hasErrors = true;
|
|
82
|
+
while (hasErrors) {
|
|
83
|
+
valuesToEdit = await editAsFile(
|
|
84
|
+
resolveJson(valuesToEdit),
|
|
85
|
+
stripIndents`
|
|
86
|
+
Please fill in all secrets for:
|
|
87
|
+
|
|
88
|
+
${Object.entries(envAndComponents)
|
|
89
|
+
.map(
|
|
90
|
+
([componentName, envs]) => `- ${componentName}: ${envs.join(", ")}`
|
|
91
|
+
)
|
|
92
|
+
.join("\n")}
|
|
93
|
+
|
|
94
|
+
`
|
|
95
|
+
);
|
|
96
|
+
// check for errors
|
|
97
|
+
hasErrors = false;
|
|
98
|
+
for (const [componentName, envs] of Object.entries(envAndComponents)) {
|
|
99
|
+
for (const env of envs) {
|
|
100
|
+
const usedKeys = valuesToEdit[componentName][env]
|
|
101
|
+
? Object.keys(valuesToEdit[componentName][env])
|
|
102
|
+
: [];
|
|
103
|
+
// check whether newValues have the exact number of keys
|
|
104
|
+
const { secretEnvVarKeys } = await getEnvironment(env, componentName);
|
|
105
|
+
const extranous = difference(usedKeys, secretEnvVarKeys);
|
|
106
|
+
const missing = difference(secretEnvVarKeys, usedKeys);
|
|
107
|
+
|
|
108
|
+
if (extranous.length > 0 || missing.length > 0) {
|
|
109
|
+
instance.log("");
|
|
110
|
+
instance.log(
|
|
111
|
+
`😿 Oh no! There is something wrong with "${componentName}"`
|
|
112
|
+
);
|
|
113
|
+
instance.log("");
|
|
114
|
+
if (extranous.length > 0) {
|
|
115
|
+
instance.log("these secrets are not declared in the config");
|
|
116
|
+
extranous.forEach((key) => instance.log(key));
|
|
117
|
+
instance.log("");
|
|
118
|
+
}
|
|
119
|
+
if (missing.length > 0) {
|
|
120
|
+
instance.log("these secrets have not been provided:");
|
|
121
|
+
missing.forEach((key) => instance.log(key));
|
|
122
|
+
instance.log("");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
await delay(1000);
|
|
126
|
+
const { shouldContinue } = await instance.prompt({
|
|
127
|
+
default: true,
|
|
128
|
+
message: "Try again? 🤔",
|
|
129
|
+
name: "shouldContinue",
|
|
130
|
+
type: "confirm",
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (!shouldContinue) {
|
|
134
|
+
throw new Error("abort");
|
|
135
|
+
}
|
|
136
|
+
hasErrors = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
instance.log("upserting all variables, please wait...");
|
|
142
|
+
instance.log("");
|
|
143
|
+
for (const [componentName, envs] of Object.entries(envAndComponents)) {
|
|
144
|
+
for (const env of envs) {
|
|
145
|
+
await upsertAllVariables(
|
|
146
|
+
instance,
|
|
147
|
+
valuesToEdit[componentName][env],
|
|
148
|
+
env,
|
|
149
|
+
componentName
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
if (hasBitwarden()) {
|
|
153
|
+
// add cloud sql secret if needed.
|
|
154
|
+
// TODO: this is legacy, in the future we want to have one service account per app
|
|
155
|
+
try {
|
|
156
|
+
const context = await getPipelineContextByChoice(env, componentName);
|
|
157
|
+
if (
|
|
158
|
+
context.componentConfig.deploy &&
|
|
159
|
+
context.componentConfig.deploy.type === "kubernetes" &&
|
|
160
|
+
context.componentConfig.deploy.values?.cloudsql?.enabled
|
|
161
|
+
) {
|
|
162
|
+
await upsertAllVariables(
|
|
163
|
+
instance,
|
|
164
|
+
{
|
|
165
|
+
cloudsqlProxyCredentials: await readPass(
|
|
166
|
+
GOOGLE_CLOUD_SQL_PASS_PATH
|
|
167
|
+
),
|
|
168
|
+
},
|
|
169
|
+
env,
|
|
170
|
+
componentName
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
} catch (e) {
|
|
174
|
+
// ignore atm
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
instance.log("✅ " + env + ":" + componentName);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
instance.log("done! 😻");
|
|
181
|
+
instance.log("");
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export const projectConfigSecrets = async (
|
|
185
|
+
vorpal: CommandInstance,
|
|
186
|
+
envComponent?: string
|
|
187
|
+
) => {
|
|
188
|
+
if (!envComponent) {
|
|
189
|
+
const allEnvAndcomponents = await getAllComponentsWithAllEnvsHierarchical();
|
|
190
|
+
await doItFor(vorpal, allEnvAndcomponents);
|
|
191
|
+
} else {
|
|
192
|
+
const { env, componentName } = parseChoice(envComponent);
|
|
193
|
+
|
|
194
|
+
// componentName can be null. in this case, iterate over all components
|
|
195
|
+
if (!componentName) {
|
|
196
|
+
const components = await getProjectComponents();
|
|
197
|
+
await doItFor(
|
|
198
|
+
vorpal,
|
|
199
|
+
Object.fromEntries(components.map((c) => [c, [env]]))
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
if (componentName) {
|
|
203
|
+
await doItFor(vorpal, {
|
|
204
|
+
[componentName]: [env],
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export default async (vorpal: Vorpal) => {
|
|
211
|
+
vorpal
|
|
212
|
+
.command(
|
|
213
|
+
"project-config-secrets [envComponent]",
|
|
214
|
+
"setup/update secrets stored in pass"
|
|
215
|
+
)
|
|
216
|
+
.autocomplete(await allEnvsAndAllComponents())
|
|
217
|
+
.action(async function ({ envComponent }) {
|
|
218
|
+
return await projectConfigSecrets(this, envComponent);
|
|
219
|
+
});
|
|
220
|
+
};
|