@catladder/cli 0.0.0-refactor-cli-add-improved-git-utilities-916545cc → 0.0.0-refactor-remove-rails-hosts-60f9538c
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/dist/bundles/catci/index.js +43322 -44345
- package/dist/bundles/catenv/index.js +27564 -43997
- package/dist/bundles/cli/index.js +149115 -143958
- package/dist/cli/src/apps/catenv/catenv.js +1 -1
- package/dist/cli/src/apps/catenv/catenv.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/index.js +0 -4
- package/dist/cli/src/apps/cli/commands/project/index.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.d.ts +1 -2
- package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.js +3 -11
- package/dist/cli/src/apps/cli/commands/project/setup/setupAccessTokens.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js +2 -4
- package/dist/cli/src/apps/cli/commands/project/setup/setupCloudRun.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.d.ts +1 -2
- package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js +9 -23
- package/dist/cli/src/apps/cli/commands/project/setup/setupKubernetes.js.map +1 -1
- package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.js +4 -6
- package/dist/cli/src/apps/cli/commands/project/setup/setupTopic.js.map +1 -1
- package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.d.ts +1 -1
- package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.js +4 -3
- package/dist/cli/src/apps/cli/utils/getGoogleAuthUserNumber.js.map +1 -1
- package/dist/cli/src/packageInfos.js +0 -1
- package/dist/cli/src/packageInfos.js.map +1 -1
- package/dist/cli/src/utils/gitlab.d.ts +7 -10
- package/dist/cli/src/utils/gitlab.js +45 -67
- package/dist/cli/src/utils/gitlab.js.map +1 -1
- package/dist/cli/src/utils/preferences/index.d.ts +3 -0
- package/dist/cli/src/utils/preferences/index.js +35 -0
- package/dist/cli/src/utils/preferences/index.js.map +1 -0
- package/dist/pipeline/src/build/cache/createJobCache.js +2 -2
- package/dist/pipeline/src/build/cache/createJobCache.js.map +1 -1
- package/dist/pipeline/src/build/sbom.js +2 -2
- package/dist/pipeline/src/build/sbom.js.map +1 -1
- package/dist/pipeline/src/build/types.d.ts +3 -3
- package/dist/pipeline/src/config/readConfig.js +0 -1
- package/dist/pipeline/src/config/readConfig.js.map +1 -1
- package/dist/pipeline/src/context/createComponentContext.js +1 -1
- package/dist/pipeline/src/context/createComponentContext.js.map +1 -1
- package/dist/pipeline/src/context/getEnvironmentVariables.d.ts +1 -1
- package/dist/pipeline/src/context/getEnvironmentVariables.js +1 -5
- package/dist/pipeline/src/context/getEnvironmentVariables.js.map +1 -1
- package/dist/pipeline/src/deploy/base/deploy.js +3 -3
- package/dist/pipeline/src/deploy/base/deploy.js.map +1 -1
- package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js +2 -10
- package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunJobs.js.map +1 -1
- package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunServices.js +2 -4
- package/dist/pipeline/src/deploy/cloudRun/createJobs/cloudRunServices.js.map +1 -1
- package/dist/pipeline/src/deploy/types/index.d.ts +3 -3
- package/dist/pipeline/src/pipeline/createMainPipeline.js +13 -7
- package/dist/pipeline/src/pipeline/createMainPipeline.js.map +1 -1
- package/dist/pipeline/src/pipeline/generatePipelineFiles.d.ts +7 -40
- package/dist/pipeline/src/pipeline/generatePipelineFiles.js +69 -42
- package/dist/pipeline/src/pipeline/generatePipelineFiles.js.map +1 -1
- package/dist/pipeline/src/pipeline/gitlab/createGitlabJobs.d.ts +6 -4
- package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.d.ts +0 -2
- package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.js +2 -4
- package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.js.map +1 -1
- package/dist/pipeline/src/pipeline/index.d.ts +0 -1
- package/dist/pipeline/src/pipeline/index.js +0 -1
- package/dist/pipeline/src/pipeline/index.js.map +1 -1
- package/dist/pipeline/src/types/config.d.ts +3 -3
- package/dist/pipeline/src/types/gitlab-types.d.ts +2 -1
- package/dist/pipeline/src/types/pipeline.d.ts +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -14
- package/src/apps/catenv/catenv.ts +1 -1
- package/src/apps/cli/commands/project/index.ts +1 -6
- package/src/apps/cli/commands/project/setup/setupAccessTokens.ts +6 -16
- package/src/apps/cli/commands/project/setup/setupCloudRun.ts +2 -4
- package/src/apps/cli/commands/project/setup/setupKubernetes.ts +27 -30
- package/src/apps/cli/commands/project/setup/setupTopic.ts +11 -6
- package/src/apps/cli/utils/getGoogleAuthUserNumber.ts +4 -6
- package/src/packageInfos.ts +0 -1
- package/src/utils/gitlab.ts +101 -99
- package/src/utils/preferences/index.ts +36 -0
- package/dist/cli/src/apps/cli/commands/project/commandMigrateHelm3.d.ts +0 -7
- package/dist/cli/src/apps/cli/commands/project/commandMigrateHelm3.js +0 -46
- package/dist/cli/src/apps/cli/commands/project/commandMigrateHelm3.js.map +0 -1
- package/dist/cli/src/apps/cli/commands/project/commandOpenCostDashboard.d.ts +0 -3
- package/dist/cli/src/apps/cli/commands/project/commandOpenCostDashboard.js +0 -22
- package/dist/cli/src/apps/cli/commands/project/commandOpenCostDashboard.js.map +0 -1
- package/dist/cli/src/apps/cli/commands/project/commandOpenDashboard.d.ts +0 -3
- package/dist/cli/src/apps/cli/commands/project/commandOpenDashboard.js +0 -22
- package/dist/cli/src/apps/cli/commands/project/commandOpenDashboard.js.map +0 -1
- package/dist/cli/src/git/getGitConfigVars.d.ts +0 -4
- package/dist/cli/src/git/getGitConfigVars.js +0 -14
- package/dist/cli/src/git/getGitConfigVars.js.map +0 -1
- package/dist/cli/src/git/getGitRemoteHostAndPath.d.ts +0 -9
- package/dist/cli/src/git/getGitRemoteHostAndPath.js +0 -23
- package/dist/cli/src/git/getGitRemoteHostAndPath.js.map +0 -1
- package/dist/cli/src/git/getProjectRootPath.d.ts +0 -1
- package/dist/cli/src/git/getProjectRootPath.js +0 -10
- package/dist/cli/src/git/getProjectRootPath.js.map +0 -1
- package/dist/cli/src/git/gitConfig.d.ts +0 -23
- package/dist/cli/src/git/gitConfig.js +0 -60
- package/dist/cli/src/git/gitConfig.js.map +0 -1
- package/dist/cli/src/git/index.d.ts +0 -4
- package/dist/cli/src/git/index.js +0 -21
- package/dist/cli/src/git/index.js.map +0 -1
- package/dist/cli/src/gitlab/apiClient.d.ts +0 -5
- package/dist/cli/src/gitlab/apiClient.js +0 -21
- package/dist/cli/src/gitlab/apiClient.js.map +0 -1
- package/dist/cli/src/gitlab/getGitlabProjectId.d.ts +0 -4
- package/dist/cli/src/gitlab/getGitlabProjectId.js +0 -29
- package/dist/cli/src/gitlab/getGitlabProjectId.js.map +0 -1
- package/dist/cli/src/gitlab/gitlabToken.d.ts +0 -10
- package/dist/cli/src/gitlab/gitlabToken.js +0 -42
- package/dist/cli/src/gitlab/gitlabToken.js.map +0 -1
- package/dist/cli/src/gitlab/index.d.ts +0 -3
- package/dist/cli/src/gitlab/index.js +0 -20
- package/dist/cli/src/gitlab/index.js.map +0 -1
- package/dist/cli/src/utils/preferences.d.ts +0 -15
- package/dist/cli/src/utils/preferences.js +0 -61
- package/dist/cli/src/utils/preferences.js.map +0 -1
- package/dist/cli/src/utils/projectPreferences.d.ts +0 -5
- package/dist/cli/src/utils/projectPreferences.js +0 -54
- package/dist/cli/src/utils/projectPreferences.js.map +0 -1
- package/dist/pipeline/src/pipeline/createChildPipeline.d.ts +0 -3
- package/dist/pipeline/src/pipeline/createChildPipeline.js +0 -30
- package/dist/pipeline/src/pipeline/createChildPipeline.js.map +0 -1
- package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.d.ts +0 -1
- package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js +0 -32
- package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js.map +0 -1
- package/src/apps/cli/commands/project/commandMigrateHelm3.ts +0 -63
- package/src/apps/cli/commands/project/commandOpenCostDashboard.ts +0 -32
- package/src/apps/cli/commands/project/commandOpenDashboard.ts +0 -28
- package/src/git/getGitConfigVars.ts +0 -11
- package/src/git/getGitRemoteHostAndPath.ts +0 -28
- package/src/git/getProjectRootPath.ts +0 -6
- package/src/git/gitConfig.ts +0 -86
- package/src/git/index.ts +0 -4
- package/src/gitlab/apiClient.ts +0 -23
- package/src/gitlab/getGitlabProjectId.ts +0 -32
- package/src/gitlab/gitlabToken.ts +0 -52
- package/src/gitlab/index.ts +0 -3
- package/src/utils/preferences.ts +0 -85
- package/src/utils/projectPreferences.ts +0 -78
package/package.json
CHANGED
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
}
|
|
54
54
|
],
|
|
55
55
|
"license": "MIT",
|
|
56
|
-
"version": "0.0.0-refactor-
|
|
56
|
+
"version": "0.0.0-refactor-remove-rails-hosts-60f9538c",
|
|
57
57
|
"scripts": {
|
|
58
58
|
"lint": "eslint \"src/**/*.ts\"",
|
|
59
59
|
"lint:fix": "eslint \"src/**/*.ts\" --fix",
|
|
@@ -74,41 +74,42 @@
|
|
|
74
74
|
"node": ">=18.0.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@gitbeaker/rest": "^
|
|
77
|
+
"@gitbeaker/rest": "^39.28.0",
|
|
78
78
|
"@kubernetes/client-node": "^0.16.2",
|
|
79
79
|
"@tsconfig/node14": "^1.0.1",
|
|
80
|
-
"@types/common-tags": "^1.8.
|
|
80
|
+
"@types/common-tags": "^1.8.4",
|
|
81
81
|
"@types/fs-extra": "^5.0.4",
|
|
82
|
-
"@types/lodash": "^4.
|
|
82
|
+
"@types/lodash": "^4.17.7",
|
|
83
83
|
"@types/memoizee": "^0.4.2",
|
|
84
|
-
"@types/node-fetch": "^2.
|
|
85
|
-
"@types/request": "^2.48.
|
|
84
|
+
"@types/node-fetch": "^2.6.11",
|
|
85
|
+
"@types/request": "^2.48.12",
|
|
86
86
|
"@types/tmp": "^0.2.3",
|
|
87
87
|
"@types/update-notifier": "^2.5.0",
|
|
88
88
|
"@types/vorpal": "^1.12.0",
|
|
89
89
|
"@types/websocket": "^0.0.40",
|
|
90
|
-
"@types/yargs": "^
|
|
90
|
+
"@types/yargs": "^17.0.33",
|
|
91
91
|
"child-process-promise": "^2.2.1",
|
|
92
92
|
"clipboardy": "^2.0.0",
|
|
93
93
|
"command-exists-promise": "^2.0.2",
|
|
94
|
-
"common-tags": "^1.8.
|
|
94
|
+
"common-tags": "^1.8.2",
|
|
95
95
|
"connection-string-parser": "^1.0.4",
|
|
96
|
-
"
|
|
96
|
+
"date-fns": "^3.6.0",
|
|
97
97
|
"fs-extra": "^7.0.1",
|
|
98
|
+
"gitlab": "^4.4.1",
|
|
98
99
|
"lodash": "^4.17.21",
|
|
99
|
-
"memoizee": "^0.4.
|
|
100
|
+
"memoizee": "^0.4.17",
|
|
100
101
|
"node-fetch": "^2.3.0",
|
|
101
102
|
"open": "^8.4.0",
|
|
102
|
-
"prettier": "^3.3.
|
|
103
|
+
"prettier": "^3.3.3",
|
|
103
104
|
"tmp-promise": "^2.0.2",
|
|
104
|
-
"ts-results-es": "^4.
|
|
105
|
+
"ts-results-es": "^4.2.0",
|
|
105
106
|
"tsc-alias": "^1.8.10",
|
|
106
107
|
"typescript": "^5.4.5",
|
|
107
108
|
"vorpal": "^1.12.0",
|
|
108
|
-
"yaml": "^2.
|
|
109
|
+
"yaml": "^2.5.0"
|
|
109
110
|
},
|
|
110
111
|
"dependencies": {
|
|
111
|
-
"tsx": "^4.
|
|
112
|
+
"tsx": "^4.19.0"
|
|
112
113
|
},
|
|
113
114
|
"stableVersion": "0.0.0"
|
|
114
115
|
}
|
|
@@ -12,7 +12,7 @@ export default async (choice?: Choice) => {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
await Promise.all([
|
|
15
|
-
generatePipelineFiles(config, config.pipelineType ?? "gitlab"
|
|
15
|
+
generatePipelineFiles(config, config.pipelineType ?? "gitlab"),
|
|
16
16
|
writeDotEnvFiles(config, choice),
|
|
17
17
|
|
|
18
18
|
writeDTsFiles(config, choice),
|
|
@@ -12,8 +12,7 @@ import commandSetup from "./commandSetup";
|
|
|
12
12
|
import commandRenewToken from "./commandRenewToken";
|
|
13
13
|
import commandListPods from "./commandListPods";
|
|
14
14
|
import commandNamespace from "./commandNamespace";
|
|
15
|
-
|
|
16
|
-
import commandOpenDashboard from "./commandOpenDashboard";
|
|
15
|
+
|
|
17
16
|
import commandOpenEnv from "./commandOpenEnv";
|
|
18
17
|
import commandOpenGit from "./commandOpenGit";
|
|
19
18
|
import commandOpenLogs from "./commandOpenLogs";
|
|
@@ -35,12 +34,8 @@ export default async (vorpal: Vorpal) => {
|
|
|
35
34
|
commandPauseProject(vorpal);
|
|
36
35
|
commandDeleteProject(vorpal);
|
|
37
36
|
|
|
38
|
-
commandOpenDashboard(vorpal);
|
|
39
|
-
|
|
40
37
|
commandOpenLogs(vorpal);
|
|
41
38
|
|
|
42
|
-
commandOpenCostDashboard(vorpal);
|
|
43
|
-
|
|
44
39
|
commandCloudSqlProxy(vorpal);
|
|
45
40
|
commandProjectRestoreDb(vorpal);
|
|
46
41
|
commandOpenGit(vorpal);
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import type { CommandInstance } from "vorpal";
|
|
2
|
-
import
|
|
2
|
+
import { add, format } from "date-fns";
|
|
3
3
|
import { doGitlabRequest, getProjectInfo } from "../../../../../utils/gitlab";
|
|
4
|
-
import {
|
|
5
|
-
getGitlabProjectId,
|
|
6
|
-
gitlabApiClient,
|
|
7
|
-
type GitlabRestClient,
|
|
8
|
-
} from "../../../../../gitlab";
|
|
9
4
|
|
|
10
5
|
const TOKEN_NAME = "semantic-release";
|
|
11
6
|
|
|
12
|
-
export const setupAccessTokens = async (
|
|
13
|
-
instance: CommandInstance,
|
|
14
|
-
preinit?: [number, GitlabRestClient],
|
|
15
|
-
) => {
|
|
16
|
-
const [id, gitlabApi] =
|
|
17
|
-
preinit ?? (await Promise.all([getGitlabProjectId(), gitlabApiClient()]));
|
|
7
|
+
export const setupAccessTokens = async (instance: CommandInstance) => {
|
|
18
8
|
const { id: projectId } = await getProjectInfo(instance);
|
|
19
9
|
|
|
20
10
|
const projectTokens = await doGitlabRequest(
|
|
@@ -25,10 +15,10 @@ export const setupAccessTokens = async (
|
|
|
25
15
|
(t) => t.name === TOKEN_NAME && t.active === true,
|
|
26
16
|
);
|
|
27
17
|
|
|
28
|
-
const expires_at =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
const expires_at = format(
|
|
19
|
+
add(new Date(), { years: 1, days: -1 }),
|
|
20
|
+
"yyyy-MM-dd",
|
|
21
|
+
);
|
|
32
22
|
|
|
33
23
|
const newToken = token
|
|
34
24
|
? await doGitlabRequest(
|
|
@@ -6,30 +6,27 @@ import {
|
|
|
6
6
|
import type { CommandInstance } from "vorpal";
|
|
7
7
|
import { exec } from "child-process-promise";
|
|
8
8
|
import { connectToCluster } from "../../../../../utils/cluster";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
doGitlabRequest,
|
|
11
|
+
getProjectInfo,
|
|
12
|
+
upsertAllVariables,
|
|
13
|
+
} from "../../../../../utils/gitlab";
|
|
10
14
|
import ensureNamespace from "../utils/ensureNamespace";
|
|
11
|
-
import type { GitlabRestClient } from "../../../../../gitlab";
|
|
12
|
-
import { getGitlabProjectId, gitlabApiClient } from "../../../../../gitlab";
|
|
13
15
|
|
|
14
16
|
export const setupKubernetes = async (
|
|
15
17
|
instance: CommandInstance,
|
|
16
18
|
context: ComponentContext,
|
|
17
|
-
preinit?: [number, GitlabRestClient],
|
|
18
19
|
) => {
|
|
19
20
|
const deployConfig = context.deploy?.config;
|
|
20
21
|
if (!isOfDeployType(deployConfig, "kubernetes")) {
|
|
21
22
|
throw new Error("cannot run setupKubernetes on non-kubernetes deployments");
|
|
22
23
|
}
|
|
23
|
-
const [id, gitlabApi] =
|
|
24
|
-
preinit ?? (await Promise.all([getGitlabProjectId(), gitlabApiClient()]));
|
|
25
|
-
|
|
26
|
-
const deploy_tokens = await gitlabApi.DeployTokens.all({ projectId: id });
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
const { id: projectId } = await getProjectInfo(instance);
|
|
26
|
+
const deploy_tokens = await doGitlabRequest(
|
|
27
|
+
instance,
|
|
28
|
+
`projects/${projectId}/deploy_tokens`,
|
|
29
|
+
);
|
|
33
30
|
|
|
34
31
|
if (
|
|
35
32
|
!deploy_tokens.find(
|
|
@@ -39,21 +36,17 @@ export const setupKubernetes = async (
|
|
|
39
36
|
instance.log(
|
|
40
37
|
"I will setup the 'GitLab Deploy Token', so Kubernetes can pull images from this project.",
|
|
41
38
|
);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
{
|
|
39
|
+
|
|
40
|
+
await doGitlabRequest(
|
|
41
|
+
instance,
|
|
42
|
+
`projects/${projectId}/deploy_tokens`,
|
|
43
|
+
{
|
|
44
|
+
id: projectId,
|
|
45
|
+
name: "gitlab-deploy-token",
|
|
46
|
+
scopes: ["read_registry"],
|
|
47
|
+
},
|
|
48
|
+
"POST",
|
|
46
49
|
);
|
|
47
|
-
// await doGitlabRequest(
|
|
48
|
-
// instance,
|
|
49
|
-
// `projects/${projectId}/deploy_tokens`,
|
|
50
|
-
// {
|
|
51
|
-
// id: projectId,
|
|
52
|
-
// name: "gitlab-deploy-token",
|
|
53
|
-
// scopes: ["read_registry"],
|
|
54
|
-
// },
|
|
55
|
-
// "POST",
|
|
56
|
-
// );
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
const fullName = getFullKubernetesClusterName(deployConfig.cluster);
|
|
@@ -167,8 +160,12 @@ EOF
|
|
|
167
160
|
instance.log("");
|
|
168
161
|
instance.log("pusing secrets to gitlab...");
|
|
169
162
|
|
|
170
|
-
await upsertAllVariables(
|
|
171
|
-
|
|
172
|
-
|
|
163
|
+
await upsertAllVariables(
|
|
164
|
+
instance,
|
|
165
|
+
vars,
|
|
166
|
+
context.env,
|
|
167
|
+
context.name,
|
|
168
|
+
false, // no backup
|
|
169
|
+
);
|
|
173
170
|
instance.log("done!");
|
|
174
171
|
};
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { CommandInstance } from "vorpal";
|
|
2
|
-
import {
|
|
2
|
+
import { doGitlabRequest, getProjectInfo } from "../../../../../utils/gitlab";
|
|
3
3
|
|
|
4
4
|
const catladderTopic = "catladder";
|
|
5
5
|
|
|
6
6
|
export const setupTopic = async (instance: CommandInstance) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
await
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const { id: projectId } = await getProjectInfo(instance);
|
|
8
|
+
|
|
9
|
+
const { topics } = await doGitlabRequest(instance, `projects/${projectId}`);
|
|
10
|
+
|
|
11
|
+
await doGitlabRequest(
|
|
12
|
+
instance,
|
|
13
|
+
`projects/${projectId}`,
|
|
14
|
+
{ topics: [catladderTopic, ...topics] },
|
|
15
|
+
"PUT",
|
|
16
|
+
);
|
|
12
17
|
};
|
|
@@ -4,8 +4,9 @@ import {
|
|
|
4
4
|
setPreference,
|
|
5
5
|
} from "../../../utils/preferences";
|
|
6
6
|
|
|
7
|
+
const KEY = "googleAuthUserNumber";
|
|
7
8
|
export const getGoogleAuthUserNumber = async function () {
|
|
8
|
-
if (!(await hasPreference(
|
|
9
|
+
if (!(await hasPreference(KEY))) {
|
|
9
10
|
this.log(
|
|
10
11
|
"Please type in your google auth user number (0 if you have only one google account or maybe 1 if you have multiple)",
|
|
11
12
|
);
|
|
@@ -16,10 +17,7 @@ export const getGoogleAuthUserNumber = async function () {
|
|
|
16
17
|
default: "0",
|
|
17
18
|
message: "Auth user ",
|
|
18
19
|
});
|
|
19
|
-
await setPreference(
|
|
20
|
-
"googleAuthUserNumber",
|
|
21
|
-
Number.parseInt(authUserNumber, 10),
|
|
22
|
-
);
|
|
20
|
+
await setPreference(KEY, authUserNumber);
|
|
23
21
|
}
|
|
24
|
-
return getPreference(
|
|
22
|
+
return getPreference(KEY);
|
|
25
23
|
};
|
package/src/packageInfos.ts
CHANGED
package/src/utils/gitlab.ts
CHANGED
|
@@ -5,20 +5,11 @@ import memoizee from "memoizee";
|
|
|
5
5
|
import fetch from "node-fetch";
|
|
6
6
|
import open from "open";
|
|
7
7
|
import type { CommandInstance } from "vorpal";
|
|
8
|
-
import { hasPreference } from "./preferences";
|
|
9
|
-
import {
|
|
10
|
-
setGitlabToken,
|
|
11
|
-
getGitlabToken as getGitlabTokenFromPerferences,
|
|
12
|
-
getGitlabProjectId,
|
|
13
|
-
getGitlabProjectInfo,
|
|
14
|
-
gitlabApiClient,
|
|
15
|
-
type GitlabRestClient,
|
|
16
|
-
} from "../gitlab";
|
|
17
|
-
import type { Camelize, ProjectVariableSchema } from "@gitbeaker/rest";
|
|
18
|
-
|
|
19
|
-
export const hasGitlabToken = async () =>
|
|
20
|
-
await hasPreference("gitlab-personal-access-token");
|
|
8
|
+
import { getPreference, hasPreference, setPreference } from "./preferences";
|
|
21
9
|
|
|
10
|
+
const TOKEN_KEY = "gitlab-personal-access-token";
|
|
11
|
+
|
|
12
|
+
export const hasGitlabToken = async () => await hasPreference(TOKEN_KEY);
|
|
22
13
|
export const setupGitlabToken = async (vorpal: CommandInstance) => {
|
|
23
14
|
vorpal.log("");
|
|
24
15
|
vorpal.log("☝ in order to access the api, we need a personal access token");
|
|
@@ -32,10 +23,6 @@ export const setupGitlabToken = async (vorpal: CommandInstance) => {
|
|
|
32
23
|
name: "shouldContinue",
|
|
33
24
|
type: "prompt",
|
|
34
25
|
});
|
|
35
|
-
if (!shouldContinue) {
|
|
36
|
-
console.info("Aborted by user");
|
|
37
|
-
process.exit(0);
|
|
38
|
-
}
|
|
39
26
|
|
|
40
27
|
open("https://git.panter.ch/-/profile/personal_access_tokens");
|
|
41
28
|
|
|
@@ -47,15 +34,12 @@ export const setupGitlabToken = async (vorpal: CommandInstance) => {
|
|
|
47
34
|
default: "",
|
|
48
35
|
message: "Your personal access token ",
|
|
49
36
|
});
|
|
50
|
-
if (
|
|
51
|
-
await
|
|
52
|
-
} else {
|
|
53
|
-
console.error("⚠️ no gitlab personal access token set");
|
|
37
|
+
if (personalToken) {
|
|
38
|
+
await setPreference(TOKEN_KEY, personalToken);
|
|
54
39
|
}
|
|
55
40
|
};
|
|
56
41
|
export const getGitlabToken = async (vorpal: CommandInstance | null) => {
|
|
57
|
-
|
|
58
|
-
if (!token?.length) {
|
|
42
|
+
if (!(await hasGitlabToken())) {
|
|
59
43
|
if (!vorpal) {
|
|
60
44
|
console.error(
|
|
61
45
|
"⚠️ gitlab token missing, please run catladder to set it up",
|
|
@@ -64,7 +48,7 @@ export const getGitlabToken = async (vorpal: CommandInstance | null) => {
|
|
|
64
48
|
}
|
|
65
49
|
await setupGitlabToken(vorpal);
|
|
66
50
|
}
|
|
67
|
-
return
|
|
51
|
+
return getPreference(TOKEN_KEY);
|
|
68
52
|
};
|
|
69
53
|
|
|
70
54
|
type Method = "GET" | "PUT" | "POST" | "DELETE";
|
|
@@ -75,9 +59,6 @@ export const doGitlabRequest = async <T = any>(
|
|
|
75
59
|
method: Method = "GET",
|
|
76
60
|
): Promise<T> => {
|
|
77
61
|
const rootToken = await getGitlabToken(vorpal);
|
|
78
|
-
if (typeof rootToken !== "string") {
|
|
79
|
-
throw new Error("Missing gitlab personal access token!");
|
|
80
|
-
}
|
|
81
62
|
|
|
82
63
|
//const method = data ? (update ? "PUT" : "POST") : "GET";
|
|
83
64
|
|
|
@@ -107,10 +88,24 @@ export const doGitlabRequest = async <T = any>(
|
|
|
107
88
|
);
|
|
108
89
|
};
|
|
109
90
|
|
|
110
|
-
export const getProjectInfo = async (
|
|
111
|
-
|
|
91
|
+
export const getProjectInfo = async (
|
|
92
|
+
vorpal: CommandInstance | null,
|
|
93
|
+
): Promise<{ id: string; web_url: string }> => {
|
|
94
|
+
const gitRemoteOriginUrl = (
|
|
95
|
+
await exec("git config --get remote.origin.url")
|
|
96
|
+
).stdout.trim();
|
|
97
|
+
const projectPath =
|
|
98
|
+
/(https:\/\/|git@)git\.panter\.ch[:/]([^.]*)(\.git)?/g.exec(
|
|
99
|
+
gitRemoteOriginUrl,
|
|
100
|
+
);
|
|
101
|
+
const project = await doGitlabRequest(
|
|
102
|
+
vorpal,
|
|
103
|
+
`projects/${encodeURIComponent(projectPath[2])}`,
|
|
104
|
+
);
|
|
105
|
+
return project;
|
|
106
|
+
};
|
|
112
107
|
|
|
113
|
-
|
|
108
|
+
type GitlabVariable = {
|
|
114
109
|
variable_type: string;
|
|
115
110
|
key: string;
|
|
116
111
|
value: string;
|
|
@@ -121,36 +116,25 @@ export type GitlabVariable = {
|
|
|
121
116
|
export const getAllVariables = memoizee(
|
|
122
117
|
async (
|
|
123
118
|
vorpal: CommandInstance | null,
|
|
124
|
-
|
|
125
|
-
): Promise<
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let all: (ProjectVariableSchema | Camelize<ProjectVariableSchema>)[] = [];
|
|
131
|
-
let result: (ProjectVariableSchema | Camelize<ProjectVariableSchema>)[][] =
|
|
132
|
-
[];
|
|
119
|
+
n = 5, // how many requests to do in parallel, 5 seems a good value for many projects, ideally we would do one request in parallel per component
|
|
120
|
+
): Promise<Array<GitlabVariable>> => {
|
|
121
|
+
const { id } = await getProjectInfo(vorpal);
|
|
122
|
+
|
|
123
|
+
let all: Array<GitlabVariable> = [];
|
|
124
|
+
let result: Array<Array<GitlabVariable>> = [];
|
|
133
125
|
let page = 1;
|
|
134
126
|
|
|
135
127
|
do {
|
|
136
128
|
// Create an array of promises for N pages
|
|
137
129
|
const promises = Array.from({ length: n }, (_, i) => {
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
130
|
+
return doGitlabRequest(
|
|
131
|
+
vorpal,
|
|
132
|
+
`projects/${id}/variables?per_page=100&page=${page + i}`,
|
|
133
|
+
);
|
|
142
134
|
});
|
|
143
135
|
|
|
144
136
|
// Wait for all promises to resolve
|
|
145
|
-
result = await Promise.all(
|
|
146
|
-
Array.from({ length: n }, async (_, i) => {
|
|
147
|
-
const res = await gitlabApi.ProjectVariables.all(id, {
|
|
148
|
-
page: page + i,
|
|
149
|
-
perPage: 100,
|
|
150
|
-
});
|
|
151
|
-
return res;
|
|
152
|
-
}),
|
|
153
|
-
);
|
|
137
|
+
result = await Promise.all(promises);
|
|
154
138
|
|
|
155
139
|
// Increment the page by N
|
|
156
140
|
page += n;
|
|
@@ -176,11 +160,60 @@ export const getVariableValueByRawName = async (
|
|
|
176
160
|
const maskableRegex = new RegExp("^[a-zA-Z0-9_+=/@:.~-]{8,}$"); // SEE https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/spec/frontend/ci_variable_list/components/ci_variable_modal_spec.js#L20
|
|
177
161
|
const isMaskable = (value: string): boolean => maskableRegex.test(value);
|
|
178
162
|
|
|
179
|
-
const
|
|
163
|
+
const createVariable = async (
|
|
180
164
|
vorpal: CommandInstance,
|
|
181
|
-
|
|
165
|
+
projectId: string,
|
|
166
|
+
key: string,
|
|
167
|
+
value: string,
|
|
168
|
+
masked = true,
|
|
169
|
+
environment_scope = "*",
|
|
182
170
|
) => {
|
|
183
|
-
|
|
171
|
+
return await doGitlabRequest(
|
|
172
|
+
vorpal,
|
|
173
|
+
`projects/${projectId}/variables`,
|
|
174
|
+
{
|
|
175
|
+
key,
|
|
176
|
+
value,
|
|
177
|
+
masked: masked && isMaskable(value),
|
|
178
|
+
environment_scope,
|
|
179
|
+
},
|
|
180
|
+
"POST",
|
|
181
|
+
);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const updateVariable = async (
|
|
185
|
+
vorpal: CommandInstance,
|
|
186
|
+
projectId: string,
|
|
187
|
+
key: string,
|
|
188
|
+
value: string,
|
|
189
|
+
masked = true,
|
|
190
|
+
) => {
|
|
191
|
+
return await doGitlabRequest(
|
|
192
|
+
vorpal,
|
|
193
|
+
`projects/${projectId}/variables/${key}`,
|
|
194
|
+
{
|
|
195
|
+
value,
|
|
196
|
+
masked: masked && isMaskable(value),
|
|
197
|
+
},
|
|
198
|
+
"PUT",
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const deleteVariable = async (
|
|
203
|
+
vorpal: CommandInstance,
|
|
204
|
+
projectId: string,
|
|
205
|
+
key: string,
|
|
206
|
+
) => {
|
|
207
|
+
return await doGitlabRequest(
|
|
208
|
+
vorpal,
|
|
209
|
+
`projects/${projectId}/variables/${key}`,
|
|
210
|
+
undefined,
|
|
211
|
+
"DELETE",
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const getAllCatladderEnvVarsInGitlab = async (vorpal: CommandInstance) => {
|
|
216
|
+
const allVariables = await getAllVariables(vorpal).then((v) =>
|
|
184
217
|
v.reduce<{
|
|
185
218
|
[key: string]: {
|
|
186
219
|
value?: string;
|
|
@@ -223,25 +256,16 @@ const getAllCatladderEnvVarsInGitlab = async (
|
|
|
223
256
|
|
|
224
257
|
const getBackupKey = (fullKey: string, timestamp: number) =>
|
|
225
258
|
`${fullKey}_backup_${timestamp}`;
|
|
226
|
-
|
|
227
259
|
export const clearBackups = async (vorpal: CommandInstance, keep: number) => {
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
gitlabApiClient(),
|
|
231
|
-
]);
|
|
232
|
-
const existingVariables = await getAllCatladderEnvVarsInGitlab(vorpal, [
|
|
233
|
-
id,
|
|
234
|
-
gitlabApi,
|
|
235
|
-
]);
|
|
236
|
-
// const { id } = await getProjectInfo(vorpal);
|
|
260
|
+
const existingVariables = await getAllCatladderEnvVarsInGitlab(vorpal);
|
|
261
|
+
const { id } = await getProjectInfo(vorpal);
|
|
237
262
|
for (const [key, { backups }] of Object.entries(existingVariables)) {
|
|
238
263
|
const backupsSorted = backups.sort((a, b) => b - a);
|
|
239
264
|
//const toKeep = backupsSorted.slice(0, keep);
|
|
240
265
|
const toDelete = backupsSorted.slice(keep);
|
|
241
266
|
|
|
242
267
|
for (const timestamp of toDelete) {
|
|
243
|
-
await
|
|
244
|
-
// await deleteVariable(vorpal, id, getBackupKey(key, timestamp));
|
|
268
|
+
await deleteVariable(vorpal, id, getBackupKey(key, timestamp));
|
|
245
269
|
}
|
|
246
270
|
}
|
|
247
271
|
};
|
|
@@ -251,26 +275,13 @@ export const upsertAllVariables = async (
|
|
|
251
275
|
variables: Record<string, any>,
|
|
252
276
|
env: string,
|
|
253
277
|
componentName: string,
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
masked = true,
|
|
257
|
-
preinit,
|
|
258
|
-
}: {
|
|
259
|
-
backup?: boolean;
|
|
260
|
-
// FIXME: would be better to have this per variable
|
|
261
|
-
masked?: boolean;
|
|
262
|
-
preinit?: [number, GitlabRestClient];
|
|
263
|
-
} = {},
|
|
278
|
+
backup = true,
|
|
279
|
+
masked = true, // FIXME: would be better to have this per variable
|
|
264
280
|
): Promise<void> => {
|
|
265
|
-
const
|
|
266
|
-
preinit ?? (await Promise.all([getGitlabProjectId(), gitlabApiClient()]));
|
|
267
|
-
// const { id } = await getProjectInfo(vorpal);
|
|
281
|
+
const { id } = await getProjectInfo(vorpal);
|
|
268
282
|
|
|
269
283
|
// we list all existing variables. We also gather backup versions, but its currently unused
|
|
270
|
-
const existingVariables = await getAllCatladderEnvVarsInGitlab(vorpal
|
|
271
|
-
id,
|
|
272
|
-
gitlabApi,
|
|
273
|
-
]);
|
|
284
|
+
const existingVariables = await getAllCatladderEnvVarsInGitlab(vorpal);
|
|
274
285
|
for (const [key, value] of Object.entries(variables ?? {})) {
|
|
275
286
|
const fullKey = getSecretVarName(env, componentName, key);
|
|
276
287
|
const valueSanitized = isObject(value) ? JSON.stringify(value) : `${value}`;
|
|
@@ -282,30 +293,21 @@ export const upsertAllVariables = async (
|
|
|
282
293
|
if (exists) {
|
|
283
294
|
vorpal.log(`changed: ${key}`);
|
|
284
295
|
|
|
285
|
-
await
|
|
286
|
-
filter: { environment_scope: "All (default)" },
|
|
287
|
-
masked,
|
|
288
|
-
});
|
|
289
|
-
// await updateVariable(vorpal, id, fullKey, valueSanitized, masked);
|
|
296
|
+
await updateVariable(vorpal, id, fullKey, valueSanitized, masked);
|
|
290
297
|
// write backup
|
|
291
298
|
if (backup) {
|
|
292
|
-
await
|
|
299
|
+
await createVariable(
|
|
300
|
+
vorpal,
|
|
293
301
|
id,
|
|
294
302
|
getBackupKey(fullKey, new Date().getTime()),
|
|
295
303
|
oldValue,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
masked,
|
|
299
|
-
},
|
|
304
|
+
masked,
|
|
305
|
+
"_backup",
|
|
300
306
|
);
|
|
301
307
|
}
|
|
302
308
|
} else {
|
|
303
309
|
vorpal.log(`new : ${key}`);
|
|
304
|
-
await
|
|
305
|
-
environmentScope: "All (default)",
|
|
306
|
-
masked,
|
|
307
|
-
});
|
|
308
|
-
// await createVariable(vorpal, id, fullKey, valueSanitized, masked);
|
|
310
|
+
await createVariable(vorpal, id, fullKey, valueSanitized, masked);
|
|
309
311
|
}
|
|
310
312
|
} else {
|
|
311
313
|
vorpal.log(`skip : ${key}`);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createFile, pathExists, readFile, writeFile } from "fs-extra";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
|
|
4
|
+
import { parse, stringify } from "yaml";
|
|
5
|
+
const directory = `${homedir()}/.catladder`;
|
|
6
|
+
const file = `${directory}/preferences.yml`;
|
|
7
|
+
|
|
8
|
+
const getPreferences = async () => {
|
|
9
|
+
if (!(await pathExists(file))) {
|
|
10
|
+
await createFile(file);
|
|
11
|
+
}
|
|
12
|
+
return (parse(await readFile(file, { encoding: "utf-8" })) ?? {}) as Record<
|
|
13
|
+
string,
|
|
14
|
+
string
|
|
15
|
+
>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const hasPreference = async (key: string) => {
|
|
19
|
+
const preferences = await getPreferences();
|
|
20
|
+
return key in preferences;
|
|
21
|
+
};
|
|
22
|
+
export const getPreference = async (key: string) => {
|
|
23
|
+
const preferences = await getPreferences();
|
|
24
|
+
return preferences[key];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const setPreference = async (key: string, value: string | number) => {
|
|
28
|
+
const preferences = await getPreferences();
|
|
29
|
+
|
|
30
|
+
const newPreferences = {
|
|
31
|
+
...preferences,
|
|
32
|
+
[key]: value,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
await writeFile(file, stringify(newPreferences));
|
|
36
|
+
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type Vorpal from "vorpal";
|
|
2
|
-
/**
|
|
3
|
-
* Error: rendered manifests contain a resource that already exists.
|
|
4
|
-
* Unable to continue with install: ConfigMap "web-app-env" in namespace "pvl-bike2school-dev" exists and cannot be imported into the current release: invalid ownership metadata; label validation error: missing key "app.kubernetes.io/managed-by": must be set to "Helm"; annotation validation error: missing key "meta.helm.sh/release-name": must be set to "pvl-bike2school-dev-web"; annotation validation error: missing key "meta.helm.sh/release-namespace": must be set to "pvl-bike2school-dev"
|
|
5
|
-
*/
|
|
6
|
-
declare const _default: (vorpal: Vorpal) => Promise<Vorpal.Command>;
|
|
7
|
-
export default _default;
|