@catladder/cli 0.0.0-node16-ddfae617 ā 0.0.0-prettier-cbceeed9
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/bin/catenv +1 -1
- package/bin/catenv-dev +3 -0
- package/bin/catladder +1 -1
- package/bin/catladder-dev +3 -0
- package/dist/apps/catenv/catenv.d.ts +4 -1
- package/dist/apps/catenv/catenv.js +28 -20
- package/dist/apps/catenv/catenv.js.map +1 -1
- package/dist/apps/cli/cli.js +4 -2
- package/dist/apps/cli/cli.js.map +1 -1
- package/dist/apps/cli/commands/{project/commandCopyDB.d.ts ā cloudSQL/commandRestoreDb.d.ts} +1 -1
- package/dist/apps/cli/commands/cloudSQL/commandRestoreDb.js +192 -0
- package/dist/apps/cli/commands/cloudSQL/commandRestoreDb.js.map +1 -0
- package/dist/apps/cli/commands/cloudSQL/index.d.ts +3 -0
- package/dist/apps/cli/commands/cloudSQL/index.js +50 -0
- package/dist/apps/cli/commands/cloudSQL/index.js.map +1 -0
- package/dist/apps/cli/commands/general/index.d.ts +1 -1
- package/dist/apps/cli/commands/general/index.js +11 -11
- package/dist/apps/cli/commands/general/index.js.map +1 -1
- package/dist/apps/cli/commands/general/portForward.d.ts +1 -1
- package/dist/apps/cli/commands/general/portForward.js +3 -3
- package/dist/apps/cli/commands/general/portForward.js.map +1 -1
- package/dist/apps/cli/commands/mongodb/index.d.ts +1 -1
- package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.d.ts +1 -1
- package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js +2 -1
- package/dist/apps/cli/commands/mongodb/projectMongoDestroyMember.js.map +1 -1
- package/dist/apps/cli/commands/mongodb/projectMongoGetShell.d.ts +1 -1
- package/dist/apps/cli/commands/mongodb/projectMongoPortForward.d.ts +1 -1
- package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js +27 -11
- package/dist/apps/cli/commands/mongodb/projectMongoPortForward.js.map +1 -1
- package/dist/apps/cli/commands/mongodb/utils/index.js +16 -4
- package/dist/apps/cli/commands/mongodb/utils/index.js.map +1 -1
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.js +109 -45
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -1
- package/dist/apps/cli/commands/project/commandConfigSecrets.d.ts +2 -1
- package/dist/apps/cli/commands/project/commandConfigSecrets.js +29 -51
- package/dist/apps/cli/commands/project/commandConfigSecrets.js.map +1 -1
- package/dist/apps/cli/commands/project/commandDeletePods.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandDeletePods.js +2 -1
- package/dist/apps/cli/commands/project/commandDeletePods.js.map +1 -1
- package/dist/apps/cli/commands/project/commandDeleteProject.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandEnvVars.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js +1 -1
- package/dist/apps/cli/commands/project/commandGetMyTotalWorktime.js.map +1 -1
- package/dist/apps/cli/commands/project/commandGetShell.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandGetShell.js +2 -1
- package/dist/apps/cli/commands/project/commandGetShell.js.map +1 -1
- package/dist/apps/cli/commands/project/commandGitlabCi.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandGitlabCi.js.map +1 -1
- package/dist/apps/cli/commands/project/commandInitProject.old.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandListPods.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandListPods.js +2 -2
- package/dist/apps/cli/commands/project/commandListPods.js.map +1 -1
- package/dist/apps/cli/commands/project/commandMigrateHelm3.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandMigrateHelm3.js +1 -2
- package/dist/apps/cli/commands/project/commandMigrateHelm3.js.map +1 -1
- package/dist/apps/cli/commands/project/commandNamespace.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandOpenCostDashboard.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandOpenCostDashboard.js +2 -2
- package/dist/apps/cli/commands/project/commandOpenCostDashboard.js.map +1 -1
- package/dist/apps/cli/commands/project/commandOpenDashboard.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandOpenDashboard.js +19 -20
- package/dist/apps/cli/commands/project/commandOpenDashboard.js.map +1 -1
- package/dist/apps/cli/commands/project/commandOpenEnv.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandOpenGit.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandOpenGit.js +2 -7
- package/dist/apps/cli/commands/project/commandOpenGit.js.map +1 -1
- package/dist/apps/cli/commands/project/commandOpenGrafana.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandOpenGrafana.js +2 -2
- package/dist/apps/cli/commands/project/commandOpenGrafana.js.map +1 -1
- package/dist/apps/cli/commands/project/commandOpenGrafanaPod.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js +4 -3
- package/dist/apps/cli/commands/project/commandOpenGrafanaPod.js.map +1 -1
- package/dist/apps/cli/commands/project/commandOpenLogs.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandOpenLogs.js +7 -20
- package/dist/apps/cli/commands/project/commandOpenLogs.js.map +1 -1
- package/dist/apps/cli/commands/project/commandPauseProject.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandPortForward.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandPortForward.js +98 -36
- package/dist/apps/cli/commands/project/commandPortForward.js.map +1 -1
- package/dist/apps/cli/commands/project/commandSecretsClearBackups.d.ts +5 -0
- package/dist/apps/cli/commands/project/commandSecretsClearBackups.js +90 -0
- package/dist/apps/cli/commands/project/commandSecretsClearBackups.js.map +1 -0
- package/dist/apps/cli/commands/project/commandSetup.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandTriggerCronjob.d.ts +1 -1
- package/dist/apps/cli/commands/project/commandTriggerCronjob.js.map +1 -1
- package/dist/apps/cli/commands/project/index.d.ts +1 -1
- package/dist/apps/cli/commands/project/index.js +2 -2
- package/dist/apps/cli/commands/project/index.js.map +1 -1
- package/dist/apps/cli/commands/project/setup/index.d.ts +1 -1
- package/dist/apps/cli/commands/project/setup/index.js +11 -7
- package/dist/apps/cli/commands/project/setup/index.js.map +1 -1
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.d.ts +1 -1
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.js +5 -4
- package/dist/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -1
- package/dist/apps/cli/commands/project/setup/setupCloudRun.d.ts +3 -0
- package/dist/apps/cli/commands/project/setup/setupCloudRun.js +118 -0
- package/dist/apps/cli/commands/project/setup/setupCloudRun.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupCloudSQL.d.ts +3 -0
- package/dist/apps/cli/commands/project/setup/setupCloudSQL.js +56 -0
- package/dist/apps/cli/commands/project/setup/setupCloudSQL.js.map +1 -0
- package/dist/apps/cli/commands/project/setup/setupContext.d.ts +2 -2
- package/dist/apps/cli/commands/project/setup/setupContext.js +17 -3
- package/dist/apps/cli/commands/project/setup/setupContext.js.map +1 -1
- package/dist/apps/cli/commands/project/setup/setupKubernetes.d.ts +2 -2
- package/dist/apps/cli/commands/project/setup/setupKubernetes.js +12 -16
- package/dist/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -1
- package/dist/apps/cli/commands/project/setup/setupTopic.d.ts +2 -0
- package/dist/apps/cli/commands/project/setup/setupTopic.js +69 -0
- package/dist/apps/cli/commands/project/setup/setupTopic.js.map +1 -0
- package/dist/apps/cli/commands/project/utils/ensureNamespace.d.ts +1 -1
- package/dist/apps/cli/commands/project/utils/ensureNamespace.js.map +1 -1
- package/dist/apps/cli/commands/project/utils/showProjectBanner.d.ts +1 -1
- package/dist/apps/cli/commands/theStuffThatReallyMatters/index.d.ts +1 -1
- package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js +1 -1
- package/dist/apps/cli/commands/theStuffThatReallyMatters/index.js.map +1 -1
- package/dist/apps/cli/config/writeConfig.d.ts +2 -2
- package/dist/apps/cli/verify/index.d.ts +1 -1
- package/dist/apps/cli/verify/migration/fromv2.d.ts +1 -1
- package/dist/apps/cli/verify/migration/fromv2.js +2 -0
- package/dist/apps/cli/verify/migration/fromv2.js.map +1 -1
- package/dist/apps/cli/verify/migration/migrateSecrets.d.ts +3 -3
- package/dist/apps/cli/verify/migration/migrateSecrets.js +4 -3
- package/dist/apps/cli/verify/migration/migrateSecrets.js.map +1 -1
- package/dist/apps/cli/verify/migration/oldGitlabCi.d.ts +1 -1
- package/dist/apps/cli/verify/migration/oldGitlabCi.js +1 -1
- package/dist/apps/cli/verify/migration/oldGitlabCi.js.map +1 -1
- package/dist/bundles/catenv/index.js +44895 -0
- package/dist/bundles/catenv/xdg-open +1066 -0
- package/dist/bundles/cli/clipboard_i686.exe +0 -0
- package/dist/bundles/cli/clipboard_x86_64.exe +0 -0
- package/dist/bundles/cli/exec-child.js +39 -0
- package/dist/bundles/cli/index.js +358730 -0
- package/dist/bundles/cli/xdg-open +1066 -0
- package/dist/bundles/cli/xsel +0 -0
- package/dist/catenv.js +3 -3
- package/dist/catenv.js.map +1 -1
- package/dist/cli.js +0 -7
- package/dist/cli.js.map +1 -1
- package/dist/config/constants.d.ts +0 -1
- package/dist/config/constants.js +1 -2
- package/dist/config/constants.js.map +1 -1
- package/dist/config/getProjectConfig.d.ts +4 -7
- package/dist/config/getProjectConfig.js +21 -9
- package/dist/config/getProjectConfig.js.map +1 -1
- package/dist/config/parseChoice.d.ts +4 -0
- package/dist/config/parseChoice.js +9 -0
- package/dist/config/parseChoice.js.map +1 -0
- package/dist/gcloud/artifactsRegistry.d.ts +5 -0
- package/dist/gcloud/artifactsRegistry.js +59 -0
- package/dist/gcloud/artifactsRegistry.js.map +1 -0
- package/dist/gcloud/cloudRun/getCloudRunDomainSuffix.d.ts +2 -0
- package/dist/gcloud/cloudRun/getCloudRunDomainSuffix.js +67 -0
- package/dist/gcloud/cloudRun/getCloudRunDomainSuffix.js.map +1 -0
- package/dist/gcloud/cloudRun/openCloudRunDashboards.d.ts +3 -0
- package/dist/gcloud/cloudRun/openCloudRunDashboards.js +62 -0
- package/dist/gcloud/cloudRun/openCloudRunDashboards.js.map +1 -0
- package/dist/gcloud/enableServices.d.ts +3 -0
- package/dist/gcloud/enableServices.js +63 -0
- package/dist/gcloud/enableServices.js.map +1 -0
- package/dist/gcloud/openDashboard.d.ts +2 -0
- package/dist/{apps/cli/commands/shared/index.js ā gcloud/openDashboard.js} +23 -27
- package/dist/gcloud/openDashboard.js.map +1 -0
- package/dist/gcloud/serviceAccounts.d.ts +12 -0
- package/dist/gcloud/serviceAccounts.js +144 -0
- package/dist/gcloud/serviceAccounts.js.map +1 -0
- package/dist/kubernetes/index.d.ts +3 -0
- package/dist/kubernetes/index.js +88 -0
- package/dist/kubernetes/index.js.map +1 -0
- package/dist/kubernetes/openKubernetesDashboards.d.ts +4 -0
- package/dist/kubernetes/openKubernetesDashboards.js +94 -0
- package/dist/kubernetes/openKubernetesDashboards.js.map +1 -0
- package/dist/kubernetes/portForward.d.ts +1 -0
- package/dist/kubernetes/portForward.js +55 -0
- package/dist/kubernetes/portForward.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/cluster.js +3 -8
- package/dist/utils/cluster.js.map +1 -1
- package/dist/utils/gitlab.d.ts +5 -3
- package/dist/utils/gitlab.js +165 -46
- package/dist/utils/gitlab.js.map +1 -1
- package/dist/utils/passwordstore/index.d.ts +0 -1
- package/dist/utils/passwordstore/index.js +1 -64
- package/dist/utils/passwordstore/index.js.map +1 -1
- package/dist/utils/portForwards.d.ts +12 -0
- package/dist/utils/{portForward.js ā portForwards.js} +20 -16
- package/dist/utils/portForwards.js.map +1 -0
- package/dist/utils/projects/index.d.ts +0 -3
- package/dist/utils/projects/index.js +3 -53
- package/dist/utils/projects/index.js.map +1 -1
- package/package.json +24 -22
- package/scripts/bundle +4 -0
- package/src/apps/catenv/catenv.ts +15 -8
- package/src/apps/cli/cli.ts +3 -1
- package/src/apps/cli/commands/cloudSQL/commandRestoreDb.ts +169 -0
- package/src/apps/cli/commands/cloudSQL/index.ts +8 -0
- package/src/apps/cli/commands/general/index.ts +11 -8
- package/src/apps/cli/commands/general/portForward.ts +4 -4
- package/src/apps/cli/commands/mongodb/index.ts +1 -1
- package/src/apps/cli/commands/mongodb/projectMongoDestroyMember.ts +3 -5
- package/src/apps/cli/commands/mongodb/projectMongoGetShell.ts +1 -1
- package/src/apps/cli/commands/mongodb/projectMongoPortForward.ts +18 -3
- package/src/apps/cli/commands/mongodb/utils/index.ts +19 -11
- package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +110 -37
- package/src/apps/cli/commands/project/commandConfigSecrets.ts +12 -31
- package/src/apps/cli/commands/project/commandDeletePods.ts +3 -5
- package/src/apps/cli/commands/project/commandDeleteProject.ts +1 -1
- package/src/apps/cli/commands/project/commandEnvVars.ts +1 -1
- package/src/apps/cli/commands/project/commandGetMyTotalWorktime.ts +2 -2
- package/src/apps/cli/commands/project/commandGetShell.ts +3 -5
- package/src/apps/cli/commands/project/commandGitlabCi.ts +2 -1
- package/src/apps/cli/commands/project/commandInitProject.old.ts +1 -1
- package/src/apps/cli/commands/project/commandListPods.ts +2 -2
- package/src/apps/cli/commands/project/commandMigrateHelm3.ts +4 -3
- package/src/apps/cli/commands/project/commandNamespace.ts +1 -1
- package/src/apps/cli/commands/project/commandOpenCostDashboard.ts +3 -3
- package/src/apps/cli/commands/project/commandOpenDashboard.ts +12 -32
- package/src/apps/cli/commands/project/commandOpenEnv.ts +1 -1
- package/src/apps/cli/commands/project/commandOpenGit.ts +3 -3
- package/src/apps/cli/commands/project/commandOpenGrafana.ts +3 -3
- package/src/apps/cli/commands/project/commandOpenGrafanaPod.ts +5 -7
- package/src/apps/cli/commands/project/commandOpenLogs.ts +4 -35
- package/src/apps/cli/commands/project/commandPauseProject.ts +1 -1
- package/src/apps/cli/commands/project/commandPortForward.ts +75 -34
- package/src/apps/cli/commands/project/commandSecretsClearBackups.ts +27 -0
- package/src/apps/cli/commands/project/commandSetup.ts +1 -1
- package/src/apps/cli/commands/project/commandTriggerCronjob.ts +3 -2
- package/src/apps/cli/commands/project/index.ts +4 -3
- package/src/apps/cli/commands/project/setup/index.ts +3 -1
- package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +23 -11
- package/src/apps/cli/commands/project/setup/setupCloudRun.ts +84 -0
- package/src/apps/cli/commands/project/setup/setupCloudSQL.ts +22 -0
- package/src/apps/cli/commands/project/setup/setupContext.ts +12 -2
- package/src/apps/cli/commands/project/setup/setupKubernetes.ts +34 -27
- package/src/apps/cli/commands/project/setup/setupTopic.ts +22 -0
- package/src/apps/cli/commands/project/utils/ensureNamespace.ts +4 -2
- package/src/apps/cli/commands/project/utils/showProjectBanner.ts +1 -1
- package/src/apps/cli/commands/theStuffThatReallyMatters/index.ts +2 -2
- package/src/apps/cli/config/writeConfig.ts +2 -2
- package/src/apps/cli/verify/index.ts +1 -1
- package/src/apps/cli/verify/migration/fromv2.ts +5 -7
- package/src/apps/cli/verify/migration/migrateSecrets.ts +9 -4
- package/src/apps/cli/verify/migration/oldGitlabCi.ts +2 -2
- package/src/catenv.ts +6 -3
- package/src/cli.ts +1 -7
- package/src/config/constants.ts +0 -2
- package/src/config/getProjectConfig.ts +14 -12
- package/src/config/parseChoice.ts +4 -0
- package/src/gcloud/artifactsRegistry.ts +16 -0
- package/src/gcloud/cloudRun/getCloudRunDomainSuffix.ts +35 -0
- package/src/gcloud/cloudRun/openCloudRunDashboards.ts +22 -0
- package/src/gcloud/enableServices.ts +14 -0
- package/src/gcloud/openDashboard.ts +19 -0
- package/src/gcloud/serviceAccounts.ts +101 -0
- package/src/kubernetes/index.ts +27 -0
- package/src/kubernetes/openKubernetesDashboards.ts +52 -0
- package/src/kubernetes/portForward.ts +15 -0
- package/src/types/child-process-promise.d.ts +36 -1
- package/src/utils/cluster.ts +3 -3
- package/src/utils/gitlab.ts +137 -26
- package/src/utils/passwordstore/index.ts +2 -30
- package/src/utils/{portForward.ts ā portForwards.ts} +27 -22
- package/src/utils/projects/index.ts +3 -24
- package/dist/apps/cli/commands/project/commandCopyDB.js +0 -102
- package/dist/apps/cli/commands/project/commandCopyDB.js.map +0 -1
- package/dist/apps/cli/commands/shared/index.d.ts +0 -3
- package/dist/apps/cli/commands/shared/index.js.map +0 -1
- package/dist/utils/portForward.d.ts +0 -4
- package/dist/utils/portForward.js.map +0 -1
- package/src/apps/cli/commands/project/commandCopyDB.ts +0 -91
- package/src/apps/cli/commands/shared/index.ts +0 -36
package/src/utils/gitlab.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { exec } from "child-process-promise";
|
|
2
1
|
import { getSecretVarName } from "@catladder/pipeline";
|
|
3
|
-
import {
|
|
2
|
+
import { exec } from "child-process-promise";
|
|
3
|
+
import { has, isObject } from "lodash";
|
|
4
4
|
import memoizee from "memoizee";
|
|
5
5
|
import fetch from "node-fetch";
|
|
6
6
|
import open from "open";
|
|
7
|
-
import { CommandInstance } from "vorpal";
|
|
7
|
+
import type { CommandInstance } from "vorpal";
|
|
8
8
|
import { getPreference, hasPreference, setPreference } from "./preferences";
|
|
9
9
|
|
|
10
10
|
const TOKEN_KEY = "gitlab-personal-access-token";
|
|
@@ -51,15 +51,16 @@ export const getGitlabToken = async (vorpal: CommandInstance) => {
|
|
|
51
51
|
return getPreference(TOKEN_KEY);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
type Method = "GET" | "PUT" | "POST" | "DELETE";
|
|
54
55
|
export const doGitlabRequest = async <T = any>(
|
|
55
56
|
vorpal: CommandInstance,
|
|
56
57
|
path: string,
|
|
57
58
|
data: any = undefined,
|
|
58
|
-
|
|
59
|
+
method: Method = "GET"
|
|
59
60
|
): Promise<T> => {
|
|
60
61
|
const rootToken = await getGitlabToken(vorpal);
|
|
61
62
|
|
|
62
|
-
const method = data ? (update ? "PUT" : "POST") : "GET";
|
|
63
|
+
//const method = data ? (update ? "PUT" : "POST") : "GET";
|
|
63
64
|
|
|
64
65
|
const result = await fetch(`https://git.panter.ch/api/v4/${path}`, {
|
|
65
66
|
method,
|
|
@@ -67,11 +68,14 @@ export const doGitlabRequest = async <T = any>(
|
|
|
67
68
|
"Content-Type": "application/json",
|
|
68
69
|
"Private-Token": rootToken,
|
|
69
70
|
},
|
|
70
|
-
body: JSON.stringify(data),
|
|
71
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
71
72
|
});
|
|
72
73
|
|
|
73
74
|
if (result.status >= 200 && result.status < 400) {
|
|
74
|
-
|
|
75
|
+
if (result.headers.get("content-type") === "application/json") {
|
|
76
|
+
return result.json();
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
75
79
|
}
|
|
76
80
|
if (result.status === 404) {
|
|
77
81
|
throw new Error("not found");
|
|
@@ -90,9 +94,10 @@ export const getProjectInfo = async (
|
|
|
90
94
|
const gitRemoteOriginUrl = (
|
|
91
95
|
await exec("git config --get remote.origin.url")
|
|
92
96
|
).stdout.trim();
|
|
93
|
-
const projectPath =
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
const projectPath =
|
|
98
|
+
/(https:\/\/|git@)git\.panter\.ch[:/]([^.]*)(\.git)?/g.exec(
|
|
99
|
+
gitRemoteOriginUrl
|
|
100
|
+
);
|
|
96
101
|
const project = await doGitlabRequest(
|
|
97
102
|
vorpal,
|
|
98
103
|
`projects/${encodeURIComponent(projectPath[2])}`
|
|
@@ -143,48 +148,154 @@ const createVariable = async (
|
|
|
143
148
|
vorpal: CommandInstance,
|
|
144
149
|
projectId: string,
|
|
145
150
|
key: string,
|
|
146
|
-
value: string
|
|
151
|
+
value: string,
|
|
152
|
+
masked = true,
|
|
153
|
+
environment_scope = "*"
|
|
147
154
|
) => {
|
|
148
|
-
return await doGitlabRequest(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
return await doGitlabRequest(
|
|
156
|
+
vorpal,
|
|
157
|
+
`projects/${projectId}/variables`,
|
|
158
|
+
{
|
|
159
|
+
key,
|
|
160
|
+
value,
|
|
161
|
+
masked: masked && isMaskable(value),
|
|
162
|
+
environment_scope,
|
|
163
|
+
},
|
|
164
|
+
"POST"
|
|
165
|
+
);
|
|
153
166
|
};
|
|
154
167
|
|
|
155
168
|
const updateVariable = async (
|
|
156
169
|
vorpal: CommandInstance,
|
|
157
170
|
projectId: string,
|
|
158
171
|
key: string,
|
|
159
|
-
value: string
|
|
172
|
+
value: string,
|
|
173
|
+
masked = true
|
|
160
174
|
) => {
|
|
161
175
|
return await doGitlabRequest(
|
|
162
176
|
vorpal,
|
|
163
177
|
`projects/${projectId}/variables/${key}`,
|
|
164
178
|
{
|
|
165
179
|
value,
|
|
166
|
-
masked: isMaskable(value),
|
|
180
|
+
masked: masked && isMaskable(value),
|
|
167
181
|
},
|
|
168
|
-
|
|
182
|
+
"PUT"
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const deleteVariable = async (
|
|
187
|
+
vorpal: CommandInstance,
|
|
188
|
+
projectId: string,
|
|
189
|
+
key: string
|
|
190
|
+
) => {
|
|
191
|
+
return await doGitlabRequest(
|
|
192
|
+
vorpal,
|
|
193
|
+
`projects/${projectId}/variables/${key}`,
|
|
194
|
+
undefined,
|
|
195
|
+
"DELETE"
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const getAllCatladderEnvVarsInGitlab = async (vorpal: CommandInstance) => {
|
|
200
|
+
const allVariables = await getAllVariables(vorpal).then((v) =>
|
|
201
|
+
v.reduce<{
|
|
202
|
+
[key: string]: {
|
|
203
|
+
value?: string;
|
|
204
|
+
backups: number[];
|
|
205
|
+
};
|
|
206
|
+
}>((acc, variable) => {
|
|
207
|
+
const { key } = variable;
|
|
208
|
+
|
|
209
|
+
if (key.startsWith("CL_")) {
|
|
210
|
+
const matchBackup = key.match(/(CL_.*)_backup_([0-9]+)/);
|
|
211
|
+
|
|
212
|
+
if (matchBackup) {
|
|
213
|
+
const key = matchBackup[1];
|
|
214
|
+
const timestamp = Number(matchBackup[2]);
|
|
215
|
+
const backups = [...(acc[key]?.backups ?? []), timestamp];
|
|
216
|
+
return {
|
|
217
|
+
...acc,
|
|
218
|
+
[key]: {
|
|
219
|
+
...(acc[key] ?? {}), // add value
|
|
220
|
+
backups,
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
...acc,
|
|
227
|
+
[key]: {
|
|
228
|
+
backups: [],
|
|
229
|
+
...(acc[key] ?? {}), // may add backups
|
|
230
|
+
value: variable.value,
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return acc;
|
|
236
|
+
}, {})
|
|
169
237
|
);
|
|
238
|
+
return allVariables;
|
|
170
239
|
};
|
|
240
|
+
|
|
241
|
+
const getBackupKey = (fullKey: string, timestamp: number) =>
|
|
242
|
+
`${fullKey}_backup_${timestamp}`;
|
|
243
|
+
export const clearBackups = async (vorpal: CommandInstance, keep: number) => {
|
|
244
|
+
const existingVariables = await getAllCatladderEnvVarsInGitlab(vorpal);
|
|
245
|
+
const { id } = await getProjectInfo(vorpal);
|
|
246
|
+
for (const [key, { backups }] of Object.entries(existingVariables)) {
|
|
247
|
+
const backupsSorted = backups.sort((a, b) => b - a);
|
|
248
|
+
//const toKeep = backupsSorted.slice(0, keep);
|
|
249
|
+
const toDelete = backupsSorted.slice(keep);
|
|
250
|
+
|
|
251
|
+
for (const timestamp of toDelete) {
|
|
252
|
+
await deleteVariable(vorpal, id, getBackupKey(key, timestamp));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
171
257
|
export const upsertAllVariables = async (
|
|
172
258
|
vorpal: CommandInstance,
|
|
173
259
|
variables: Record<string, any>,
|
|
174
260
|
env: string,
|
|
175
|
-
componentName: string
|
|
261
|
+
componentName: string,
|
|
262
|
+
backup = true,
|
|
263
|
+
masked = true // FIXME: would be better to have this per variable
|
|
176
264
|
): Promise<void> => {
|
|
177
265
|
const { id } = await getProjectInfo(vorpal);
|
|
178
266
|
|
|
267
|
+
// we list all existing variables. We also gather backup versions, but its currently unused
|
|
268
|
+
const existingVariables = await getAllCatladderEnvVarsInGitlab(vorpal);
|
|
179
269
|
for (const [key, value] of Object.entries(variables ?? {})) {
|
|
180
270
|
const fullKey = getSecretVarName(env, componentName, key);
|
|
181
271
|
const valueSanitized = isObject(value) ? JSON.stringify(value) : `${value}`;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
272
|
+
|
|
273
|
+
const exists = has(existingVariables, fullKey);
|
|
274
|
+
const oldValue = existingVariables[fullKey]?.value;
|
|
275
|
+
const changed = oldValue !== valueSanitized;
|
|
276
|
+
if (changed) {
|
|
277
|
+
if (exists) {
|
|
278
|
+
vorpal.log(`changed: ${key}`);
|
|
279
|
+
|
|
280
|
+
await updateVariable(vorpal, id, fullKey, valueSanitized, masked);
|
|
281
|
+
// write backup
|
|
282
|
+
if (backup) {
|
|
283
|
+
await createVariable(
|
|
284
|
+
vorpal,
|
|
285
|
+
id,
|
|
286
|
+
getBackupKey(fullKey, new Date().getTime()),
|
|
287
|
+
oldValue,
|
|
288
|
+
masked,
|
|
289
|
+
"_backup"
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
} else {
|
|
293
|
+
vorpal.log(`new : ${key}`);
|
|
294
|
+
await createVariable(vorpal, id, fullKey, valueSanitized, masked);
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
vorpal.log(`skip : ${key}`);
|
|
188
298
|
}
|
|
189
299
|
}
|
|
300
|
+
getAllVariables.clear();
|
|
190
301
|
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { exec, spawn } from "child-process-promise";
|
|
2
2
|
import commandExists from "command-exists-promise";
|
|
3
3
|
import dayjs from "dayjs";
|
|
4
|
-
import { readFile, writeFile } from "fs-extra";
|
|
5
|
-
import { withFile } from "tmp-promise";
|
|
6
|
-
import getEditor from "../getEditor";
|
|
7
4
|
import { getPreference, hasPreference, setPreference } from "../preferences";
|
|
8
5
|
|
|
9
6
|
const DEBUG = false;
|
|
@@ -18,7 +15,7 @@ const unlockBitwarden = async () => {
|
|
|
18
15
|
let session = null;
|
|
19
16
|
promise.childProcess.stdout.on(
|
|
20
17
|
"data",
|
|
21
|
-
(d
|
|
18
|
+
(d) => (session = d.toString("utf-8"))
|
|
22
19
|
);
|
|
23
20
|
await promise;
|
|
24
21
|
await setPreference("bwsession", session);
|
|
@@ -33,7 +30,7 @@ const loginBitwarden = async () => {
|
|
|
33
30
|
let session = null;
|
|
34
31
|
promise.childProcess.stdout.on(
|
|
35
32
|
"data",
|
|
36
|
-
(d
|
|
33
|
+
(d) => (session = d.toString("utf-8"))
|
|
37
34
|
);
|
|
38
35
|
await promise;
|
|
39
36
|
await setPreference("bwsession", session);
|
|
@@ -120,14 +117,6 @@ export const readPass = async (path: string) => {
|
|
|
120
117
|
return result.notes || result.login?.password;
|
|
121
118
|
};
|
|
122
119
|
|
|
123
|
-
const update = async (type: string, itemId: string, value: any) => {
|
|
124
|
-
const result = await execBitwardenCommand(
|
|
125
|
-
`edit ${type} ${itemId} ${encode(value)}`
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
return result;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
120
|
const MAX_SYNC_AGE_IN_MINUTES = 30;
|
|
132
121
|
export const syncBitwarden = async (force = true) => {
|
|
133
122
|
const lastSync = (await hasPreference("bwLastSync"))
|
|
@@ -171,20 +160,3 @@ export const trashItem = async (path: string) => {
|
|
|
171
160
|
|
|
172
161
|
return result;
|
|
173
162
|
};
|
|
174
|
-
export const editPass = async (path: string) => {
|
|
175
|
-
const item = await getItem(path);
|
|
176
|
-
|
|
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
|
-
);
|
|
190
|
-
};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { spawn } from "child-process-promise";
|
|
2
|
+
import type { ReadStream } from "fs-extra";
|
|
3
|
+
import open from "open";
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
export type PortForward = Promise<unknown> & {
|
|
6
|
+
childProcess: {
|
|
7
|
+
stdout: ReadStream;
|
|
8
|
+
kill: () => any;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
const portForwards = new Map<string, PortForward>();
|
|
4
12
|
|
|
5
13
|
export const stopPortForward = async (name: string) => {
|
|
6
14
|
const old = portForwards.get(name);
|
|
@@ -19,32 +27,29 @@ export const stopPortForward = async (name: string) => {
|
|
|
19
27
|
export const getAllRunningPortForwards = () => {
|
|
20
28
|
return Array.from(portForwards.keys());
|
|
21
29
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
|
|
31
|
+
const addPortForward = (name: string, portForward: PortForward) => {
|
|
32
|
+
portForwards.set(name, portForward);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const startPortForwardCommand = async (
|
|
36
|
+
name: string,
|
|
37
|
+
command: string
|
|
27
38
|
) => {
|
|
28
|
-
const name = `${namespace}/${podname}/${localPort}:${remotePort}`;
|
|
29
39
|
// stop if already there
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const promise = spawn(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
portForwards.set(name, promise);
|
|
40
|
+
await stopPortForward(name);
|
|
41
|
+
const [cmd, ...args] = command.split(" ");
|
|
42
|
+
|
|
43
|
+
const promise = spawn(cmd, args, {
|
|
44
|
+
env: {
|
|
45
|
+
...process.env,
|
|
46
|
+
DEBUG: "",
|
|
47
|
+
},
|
|
48
|
+
}) as PortForward;
|
|
49
|
+
addPortForward(name, promise);
|
|
44
50
|
// wait a moment so that is surley started, unfortunatly we don't know that
|
|
45
51
|
await new Promise((r) => setTimeout(r, 1000));
|
|
46
52
|
};
|
|
47
|
-
|
|
48
53
|
export const stopAllPortForwards = async () => {
|
|
49
54
|
getAllRunningPortForwards().forEach((name) => {
|
|
50
55
|
stopPortForward(name);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { $ } from "zx";
|
|
2
1
|
import { join } from "path";
|
|
3
2
|
import { getProjectConfig, parseChoice } from "../../config/getProjectConfig";
|
|
4
|
-
|
|
3
|
+
|
|
5
4
|
import { readFileOrError } from "../files";
|
|
5
|
+
import { exec } from "child-process-promise";
|
|
6
6
|
|
|
7
7
|
export const getGitRoot = async (): Promise<string> => {
|
|
8
|
-
return (await
|
|
8
|
+
return (await exec(`git rev-parse --show-toplevel`)).stdout.trim();
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const getRootGitlabCiFile = async () => {
|
|
@@ -29,24 +29,3 @@ export const getProjectNamespace = async (envComponent: string) => {
|
|
|
29
29
|
const config = await getProjectConfig();
|
|
30
30
|
return `${config.customerName}-${config.appName}-${env}`;
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
export const getProjectPods = async (envComponent: string) => {
|
|
34
|
-
const namespace = await getProjectNamespace(envComponent);
|
|
35
|
-
const k8sApi = getk8sApi();
|
|
36
|
-
const res = await k8sApi.listNamespacedPod(namespace);
|
|
37
|
-
|
|
38
|
-
return res.body.items;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const getProjectPvcs = async (envComponent: string) => {
|
|
42
|
-
const namespace = await getProjectNamespace(envComponent);
|
|
43
|
-
const k8sApi = getk8sApi();
|
|
44
|
-
const res = await k8sApi.listNamespacedPersistentVolumeClaim(namespace);
|
|
45
|
-
|
|
46
|
-
return res.body.items;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const getProjectPodNames = async (envComponent: string) => {
|
|
50
|
-
const pods = await getProjectPods(envComponent);
|
|
51
|
-
return pods.map((n) => n.metadata.name);
|
|
52
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.__esModule = true;
|
|
39
|
-
var child_process_promise_1 = require("child-process-promise");
|
|
40
|
-
var constants_1 = require("../../../../config/constants");
|
|
41
|
-
var getProjectConfig_1 = require("../../../../config/getProjectConfig");
|
|
42
|
-
var passwordstore_1 = require("../../../../utils/passwordstore");
|
|
43
|
-
var autocompletions_1 = require("./utils/autocompletions");
|
|
44
|
-
exports["default"] = (function (vorpal) { return __awaiter(void 0, void 0, void 0, function () {
|
|
45
|
-
var _a, _b;
|
|
46
|
-
return __generator(this, function (_c) {
|
|
47
|
-
switch (_c.label) {
|
|
48
|
-
case 0:
|
|
49
|
-
_b = (_a = vorpal
|
|
50
|
-
.command("copy-db <envComponent>", "replace local db with the one from an env"))
|
|
51
|
-
.autocomplete;
|
|
52
|
-
return [4 /*yield*/, (0, autocompletions_1.envAndComponents)()];
|
|
53
|
-
case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])
|
|
54
|
-
.action(function copyDB(_a) {
|
|
55
|
-
var envComponent = _a.envComponent;
|
|
56
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
-
var _b, env, componentName, _c, customerName, appName, shouldContinue, GOOGLE_CLOUD_SQL_REGION, POSTGRESQL_PASSWORD, LOCAL_PORT, instanceName, cloudsqlCredentials, POSTGRESQL_URL, matches, localDBName, copyDBScript;
|
|
58
|
-
return __generator(this, function (_d) {
|
|
59
|
-
switch (_d.label) {
|
|
60
|
-
case 0:
|
|
61
|
-
_b = (0, getProjectConfig_1.parseChoice)(envComponent), env = _b.env, componentName = _b.componentName;
|
|
62
|
-
return [4 /*yield*/, (0, getProjectConfig_1.getProjectConfig)()];
|
|
63
|
-
case 1:
|
|
64
|
-
_c = _d.sent(), customerName = _c.customerName, appName = _c.appName;
|
|
65
|
-
return [4 /*yield*/, this.prompt({
|
|
66
|
-
type: "confirm",
|
|
67
|
-
name: "shouldContinue",
|
|
68
|
-
message: "This will drop your local database and replace it with the remote one. Continue? š¤ "
|
|
69
|
-
})];
|
|
70
|
-
case 2:
|
|
71
|
-
shouldContinue = (_d.sent()).shouldContinue;
|
|
72
|
-
if (!shouldContinue) {
|
|
73
|
-
return [2 /*return*/];
|
|
74
|
-
}
|
|
75
|
-
// TODO: reimpleent with new config
|
|
76
|
-
throw new Error("needs reimplementation with new config");
|
|
77
|
-
case 3:
|
|
78
|
-
POSTGRESQL_PASSWORD = (_d.sent()).POSTGRESQL_PASSWORD;
|
|
79
|
-
LOCAL_PORT = 54321;
|
|
80
|
-
instanceName = "".concat("xxxxxx reimplement shoulld be project id", ":").concat(GOOGLE_CLOUD_SQL_REGION, ":").concat(customerName, "-").concat(appName, "-").concat(env, "=tcp:").concat(LOCAL_PORT);
|
|
81
|
-
return [4 /*yield*/, (0, passwordstore_1.readPass)(constants_1.GOOGLE_CLOUD_SQL_PASS_PATH)];
|
|
82
|
-
case 4:
|
|
83
|
-
cloudsqlCredentials = _d.sent();
|
|
84
|
-
POSTGRESQL_URL = process.env.POSTGRESQL_URL;
|
|
85
|
-
matches = new RegExp(/\w+:\/\/.*@.*\/(\w*)()/g).exec(POSTGRESQL_URL);
|
|
86
|
-
if (!matches) {
|
|
87
|
-
throw new Error("Could not determine db name.");
|
|
88
|
-
}
|
|
89
|
-
localDBName = matches[1];
|
|
90
|
-
copyDBScript = "\n set -e\n credtmp=$(mktemp /tmp/cred.XXXXXX)\n echo '".concat(cloudsqlCredentials, "' > $credtmp\n echo \"Opening connection...\"\n cloud_sql_proxy -instances ").concat(instanceName, " -credential_file $credtmp &> /dev/null &\n PROXY_PID=$!\n\n echo -n \"Waiting for proxy\"\n until echo > /dev/tcp/localhost/").concat(LOCAL_PORT, "; do\n sleep 0.2\n echo -n \".\"\n done 2>/dev/null\n echo\n\n dumptmp=$(mktemp /tmp/dump.XXXXXX)\n\n echo \"Dumping file to $dumptmp\"\n pg_dump --dbname=postgres://postgres:").concat(POSTGRESQL_PASSWORD, "@localhost:").concat(LOCAL_PORT, "/").concat(componentName, " --no-owner --no-privileges > $dumptmp\n psql -q -c \"drop database ").concat(localDBName, "\" 1> /dev/null\n psql -q -c \"create database ").concat(localDBName, "\" 1> /dev/null\n echo \"Restoring dump...\"\n psql -q ").concat(localDBName, " < $dumptmp 1> /dev/null\n\n echo \"Clean up...\"\n set +e\n kill -9 $PROXY_PID\n wait $PROXY_PID 2> /dev/null\n rm $credtmp\n rm $dumptmp\n echo \"\n\uD83D\uDC31 Done!\"\n ");
|
|
91
|
-
return [4 /*yield*/, (0, child_process_promise_1.spawn)(copyDBScript, [], { shell: "bash", stdio: "inherit" })];
|
|
92
|
-
case 5:
|
|
93
|
-
_d.sent();
|
|
94
|
-
return [2 /*return*/];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
})];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}); });
|
|
102
|
-
//# sourceMappingURL=commandCopyDB.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commandCopyDB.js","sourceRoot":"","sources":["../../../../../src/apps/cli/commands/project/commandCopyDB.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA8C;AAE9C,0DAA0E;AAC1E,wEAI6C;AAC7C,iEAA2D;AAC3D,2DAA2D;AAE3D,sBAAe,UAAO,MAAc;;;;;gBAClC,KAAA,CAAA,KAAA,MAAM;qBACH,OAAO,CACN,wBAAwB,EACxB,2CAA2C,CAC5C,CAAA;qBACA,YAAY,CAAA;gBAAC,qBAAM,IAAA,kCAAgB,GAAE,EAAA;oBALxC,sBAAA,cAKgB,SAAwB,EAAC;qBACtC,MAAM,CAAC,SAAe,MAAM,CAAC,EAAgB;wBAAd,YAAY,kBAAA;;;;;;oCACpC,KAAyB,IAAA,8BAAW,EAAC,YAAY,CAAC,EAAhD,GAAG,SAAA,EAAE,aAAa,mBAAA,CAA+B;oCACvB,qBAAM,IAAA,mCAAgB,GAAE,EAAA;;oCAApD,KAA4B,SAAwB,EAAlD,YAAY,kBAAA,EAAE,OAAO,aAAA;oCAEF,qBAAM,IAAI,CAAC,MAAM,CAAC;4CAC3C,IAAI,EAAE,SAAS;4CACf,IAAI,EAAE,gBAAgB;4CACtB,OAAO,EACL,sFAAsF;yCACzF,CAAC,EAAA;;oCALM,cAAc,GAAK,CAAA,SAKzB,CAAA,eALoB;oCAOtB,IAAI,CAAC,cAAc,EAAE;wCACnB,sBAAO;qCACR;oCAED,mCAAmC;oCACnC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;;oCAElD,mBAAmB,GAAK,CAAA,SAI/B,CAAA,oBAJ0B;oCAMrB,UAAU,GAAG,KAAK,CAAC;oCAEnB,YAAY,GAAG,UAAG,0CAA0C,cAAI,uBAAuB,cAAI,YAAY,cAAI,OAAO,cAAI,GAAG,kBAAQ,UAAU,CAAE,CAAC;oCACxH,qBAAM,IAAA,wBAAQ,EAAC,sCAA0B,CAAC,EAAA;;oCAAhE,mBAAmB,GAAG,SAA0C;oCAE9D,cAAc,GAAK,OAAO,CAAC,GAAG,eAAhB,CAAiB;oCACjC,OAAO,GAAG,IAAI,MAAM,CAAC,yBAAyB,CAAC,CAAC,IAAI,CACxD,cAAc,CACf,CAAC;oCACF,IAAI,CAAC,OAAO,EAAE;wCACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;qCACjD;oCACK,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;oCAEzB,YAAY,GAAG,gFAGb,mBAAmB,kGAEE,YAAY,yJAIP,UAAU,mOASL,mBAAmB,wBAAc,UAAU,cAAI,aAAa,sFACvE,WAAW,iEACT,WAAW,8EAE/B,WAAW,0NASpB,CAAC;oCAEF,qBAAM,IAAA,6BAAK,EAAC,YAAY,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAA;;oCAAlE,SAAkE,CAAC;;;;;iBACpE,CAAC,EAAA;;;KAAA,EAAC"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { DeployConfigKubernetesCluster } from "@catladder/pipeline";
|
|
2
|
-
export declare const openGoogleCloudLogs: (cluster?: DeployConfigKubernetesCluster, namespace?: string, googleAuthUserNumber?: number) => Promise<void>;
|
|
3
|
-
export declare const openGoogleCloudKubernetesDashboard: (cluster: DeployConfigKubernetesCluster, namespace: string, googleAuthUserNumber?: number) => Promise<void>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/apps/cli/commands/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,8CAAwB;AAEjB,IAAM,mBAAmB,GAAG,UACjC,OAAuC,EACvC,SAAkB,EAClB,oBAAwB;IAAxB,qCAAA,EAAA,wBAAwB;;;;YAElB,QAAQ,GAAG,qCAA8B,OAAO,CAAC,IAAI,SACzD,SAAS,CAAC,CAAC,CAAC,0BAAmB,SAAS,CAAE,CAAC,CAAC,CAAC,EAAE,CAC/C,CAAC;YAEG,GAAG,GAAG,+DACV,OAAO,CAAC,SAAS,SAEjB,QAAQ,CAAC,CAAC,CAAC,oBAAa,kBAAkB,CAAC,QAAQ,CAAC,CAAE,CAAC,CAAC,CAAC,EAAE,uBAChD,oBAAoB,CAAE,CAAC;YACpC,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC;;;;CACX,CAAC;AAfW,QAAA,mBAAmB,uBAe9B;AAEK,IAAM,kCAAkC,GAAG,UAChD,OAAsC,EACtC,SAAiB,EACjB,oBAAwB;IAAxB,qCAAA,EAAA,wBAAwB;;;;YAMlB,SAAS,GAAG,wCAA4B,OAAO,CAAC,MAAM,cAAI,OAAO,CAAC,IAAI,0BAAY,SAAS,qDAA6C,CAAC;YACzI,GAAG,GAAG,wEAAiE,oBAAoB,sBAC/F,OAAO,CAAC,SAAS,wBACL,kBAAkB,CAAC,SAAS,CAAC,CAAE,CAAC;YAE9C,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC;;;;CACX,CAAC;AAfW,QAAA,kCAAkC,sCAe7C"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const stopPortForward: (name: string) => Promise<void>;
|
|
2
|
-
export declare const getAllRunningPortForwards: () => any[];
|
|
3
|
-
export declare const startPortForward: (podname: string, localPort: number, remotePort: number, namespace: string) => Promise<void>;
|
|
4
|
-
export declare const stopAllPortForwards: () => Promise<void>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"portForward.js","sourceRoot":"","sources":["../../src/utils/portForward.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA8C;AAE9C,IAAM,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;AAExB,IAAM,eAAe,GAAG,UAAO,IAAY;;;;;gBAC1C,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;qBAE/B,GAAG,EAAH,wBAAG;;;;gBAEH,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;gBACxB,qBAAM,GAAG,EAAA;;gBAAT,SAAS,CAAC;;;;;;gBAIZ,YAAY,CAAC,QAAM,CAAA,CAAC,IAAI,CAAC,CAAC;;;;;KAE7B,CAAC;AAZW,QAAA,eAAe,mBAY1B;AAEK,IAAM,yBAAyB,GAAG;IACvC,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC,CAAC;AAFW,QAAA,yBAAyB,6BAEpC;AACK,IAAM,gBAAgB,GAAG,UAC9B,OAAe,EACf,SAAiB,EACjB,UAAkB,EAClB,SAAiB;;;;;gBAEX,IAAI,GAAG,UAAG,SAAS,cAAI,OAAO,cAAI,SAAS,cAAI,UAAU,CAAE,CAAC;gBAClE,wBAAwB;gBACxB,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;oBAC1B,IAAA,uBAAe,EAAC,IAAI,CAAC,CAAC;iBACvB;gBACK,OAAO,GAAG,IAAA,6BAAK,EACnB,SAAS,EACT,CAAC,cAAc,EAAE,OAAO,EAAE,UAAG,SAAS,cAAI,UAAU,CAAE,EAAE,IAAI,EAAE,SAAS,CAAC,EACxE;oBACE,GAAG,wBACE,OAAO,CAAC,GAAG,KACd,KAAK,EAAE,EAAE,GACV;iBACF,CACF,CAAC;gBACF,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAChC,2EAA2E;gBAC3E,qBAAM,IAAI,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,EAAnB,CAAmB,CAAC,EAAA;;gBAD7C,2EAA2E;gBAC3E,SAA6C,CAAC;;;;KAC/C,CAAC;AAxBW,QAAA,gBAAgB,oBAwB3B;AAEK,IAAM,mBAAmB,GAAG;;QACjC,IAAA,iCAAyB,GAAE,CAAC,OAAO,CAAC,UAAC,IAAI;YACvC,IAAA,uBAAe,EAAC,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;;;KACJ,CAAC;AAJW,QAAA,mBAAmB,uBAI9B"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { spawn } from "child-process-promise";
|
|
2
|
-
import Vorpal from "vorpal";
|
|
3
|
-
import { GOOGLE_CLOUD_SQL_PASS_PATH } from "../../../../config/constants";
|
|
4
|
-
import {
|
|
5
|
-
getEnvVars,
|
|
6
|
-
getProjectConfig,
|
|
7
|
-
parseChoice,
|
|
8
|
-
} from "../../../../config/getProjectConfig";
|
|
9
|
-
import { readPass } from "../../../../utils/passwordstore";
|
|
10
|
-
import { envAndComponents } from "./utils/autocompletions";
|
|
11
|
-
|
|
12
|
-
export default async (vorpal: Vorpal) =>
|
|
13
|
-
vorpal
|
|
14
|
-
.command(
|
|
15
|
-
"copy-db <envComponent>",
|
|
16
|
-
"replace local db with the one from an env"
|
|
17
|
-
)
|
|
18
|
-
.autocomplete(await envAndComponents())
|
|
19
|
-
.action(async function copyDB({ envComponent }) {
|
|
20
|
-
const { env, componentName } = parseChoice(envComponent);
|
|
21
|
-
const { customerName, appName } = await getProjectConfig();
|
|
22
|
-
|
|
23
|
-
const { shouldContinue } = await this.prompt({
|
|
24
|
-
type: "confirm",
|
|
25
|
-
name: "shouldContinue",
|
|
26
|
-
message:
|
|
27
|
-
"This will drop your local database and replace it with the remote one. Continue? š¤ ",
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (!shouldContinue) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// TODO: reimpleent with new config
|
|
35
|
-
throw new Error("needs reimplementation with new config");
|
|
36
|
-
const GOOGLE_CLOUD_SQL_REGION = "europe-west6"; // currently hardcoded
|
|
37
|
-
const { POSTGRESQL_PASSWORD } = await getEnvVars(
|
|
38
|
-
this,
|
|
39
|
-
env,
|
|
40
|
-
componentName
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const LOCAL_PORT = 54321;
|
|
44
|
-
|
|
45
|
-
const instanceName = `${"xxxxxx reimplement shoulld be project id"}:${GOOGLE_CLOUD_SQL_REGION}:${customerName}-${appName}-${env}=tcp:${LOCAL_PORT}`;
|
|
46
|
-
const cloudsqlCredentials = await readPass(GOOGLE_CLOUD_SQL_PASS_PATH);
|
|
47
|
-
|
|
48
|
-
const { POSTGRESQL_URL } = process.env;
|
|
49
|
-
const matches = new RegExp(/\w+:\/\/.*@.*\/(\w*)()/g).exec(
|
|
50
|
-
POSTGRESQL_URL
|
|
51
|
-
);
|
|
52
|
-
if (!matches) {
|
|
53
|
-
throw new Error("Could not determine db name.");
|
|
54
|
-
}
|
|
55
|
-
const localDBName = matches[1];
|
|
56
|
-
|
|
57
|
-
const copyDBScript = `
|
|
58
|
-
set -e
|
|
59
|
-
credtmp=$(mktemp /tmp/cred.XXXXXX)
|
|
60
|
-
echo '${cloudsqlCredentials}' > $credtmp
|
|
61
|
-
echo "Opening connection..."
|
|
62
|
-
cloud_sql_proxy -instances ${instanceName} -credential_file $credtmp &> /dev/null &
|
|
63
|
-
PROXY_PID=$!
|
|
64
|
-
|
|
65
|
-
echo -n "Waiting for proxy"
|
|
66
|
-
until echo > /dev/tcp/localhost/${LOCAL_PORT}; do
|
|
67
|
-
sleep 0.2
|
|
68
|
-
echo -n "."
|
|
69
|
-
done 2>/dev/null
|
|
70
|
-
echo
|
|
71
|
-
|
|
72
|
-
dumptmp=$(mktemp /tmp/dump.XXXXXX)
|
|
73
|
-
|
|
74
|
-
echo "Dumping file to $dumptmp"
|
|
75
|
-
pg_dump --dbname=postgres://postgres:${POSTGRESQL_PASSWORD}@localhost:${LOCAL_PORT}/${componentName} --no-owner --no-privileges > $dumptmp
|
|
76
|
-
psql -q -c "drop database ${localDBName}" 1> /dev/null
|
|
77
|
-
psql -q -c "create database ${localDBName}" 1> /dev/null
|
|
78
|
-
echo "Restoring dump..."
|
|
79
|
-
psql -q ${localDBName} < $dumptmp 1> /dev/null
|
|
80
|
-
|
|
81
|
-
echo "Clean up..."
|
|
82
|
-
set +e
|
|
83
|
-
kill -9 $PROXY_PID
|
|
84
|
-
wait $PROXY_PID 2> /dev/null
|
|
85
|
-
rm $credtmp
|
|
86
|
-
rm $dumptmp
|
|
87
|
-
echo "\nš± Done!"
|
|
88
|
-
`;
|
|
89
|
-
|
|
90
|
-
await spawn(copyDBScript, [], { shell: "bash", stdio: "inherit" });
|
|
91
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { DeployConfigKubernetesCluster } from "@catladder/pipeline";
|
|
2
|
-
import open from "open";
|
|
3
|
-
|
|
4
|
-
export const openGoogleCloudLogs = async (
|
|
5
|
-
cluster?: DeployConfigKubernetesCluster,
|
|
6
|
-
namespace?: string,
|
|
7
|
-
googleAuthUserNumber = 0
|
|
8
|
-
) => {
|
|
9
|
-
const resource = `k8s_container/cluster_name/${cluster.name}${
|
|
10
|
-
namespace ? `/namespace_name/${namespace}` : ""
|
|
11
|
-
}`;
|
|
12
|
-
|
|
13
|
-
const url = `https://console.cloud.google.com/logs/viewer?project=${
|
|
14
|
-
cluster.projectId
|
|
15
|
-
}${
|
|
16
|
-
resource ? `&resource=${encodeURIComponent(resource)}` : ""
|
|
17
|
-
}&authuser=${googleAuthUserNumber}`;
|
|
18
|
-
open(url);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const openGoogleCloudKubernetesDashboard = async (
|
|
22
|
-
cluster: DeployConfigKubernetesCluster,
|
|
23
|
-
namespace: string,
|
|
24
|
-
googleAuthUserNumber = 0
|
|
25
|
-
) => {
|
|
26
|
-
//gke_skynet-164509_europe-west1-d_production
|
|
27
|
-
// ?authuser=1&project=skynet-swiss&pageState=pageState%3D(%22savedViews%22:(%22c%22:%5B%22gke%2Feurope-west6-a%2Fch-production%22%5D,%22n%22:%5B%22pvl-bike2school-review%22%5D,%22i%22:%224e42e0b9cd6147f8a4fba7516752ec48%22))
|
|
28
|
-
// ?authuser=1&project=skynet-swiss&pageState=(%22savedViews%22:(%22i%22:%2279802e2b154d46d480dff4e086e87875%22,%22c%22:%5B%22gke%2Feurope-west6-a%2Fch-production%22%5D,%22n%22:%5B%22pvl-bike2school-review%22%5D))
|
|
29
|
-
|
|
30
|
-
const pageState = `("savedViews":("c":["gke/${cluster.region}/${cluster.name}"],"n":["${namespace}"],"i":"4e42e0b9cd6147f8a4fba7516752ec48"))`;
|
|
31
|
-
const url = `https://console.cloud.google.com/kubernetes/workload?authuser=${googleAuthUserNumber}&project=${
|
|
32
|
-
cluster.projectId
|
|
33
|
-
}&pageState=${encodeURIComponent(pageState)}`;
|
|
34
|
-
|
|
35
|
-
open(url);
|
|
36
|
-
};
|