@catladder/cli 0.0.0-main-d0a1e9f1 → 0.0.0-main-67fbbdf8
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/apps/cli/cli.js +8 -4
- package/dist/apps/cli/cli.js.map +1 -1
- package/dist/apps/cli/commands/project/commandConfigSecrets.js +20 -1
- package/dist/apps/cli/commands/project/commandConfigSecrets.js.map +1 -1
- package/dist/apps/cli/config/writeConfig.d.ts +5 -0
- package/dist/apps/cli/config/writeConfig.js +95 -0
- package/dist/apps/cli/config/writeConfig.js.map +1 -0
- package/dist/apps/cli/verify/index.d.ts +2 -0
- package/dist/apps/cli/verify/index.js +71 -0
- package/dist/apps/cli/verify/index.js.map +1 -0
- package/dist/apps/cli/verify/migration/fromv2.d.ts +3 -0
- package/dist/apps/cli/verify/migration/fromv2.js +240 -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 +75 -0
- package/dist/apps/cli/verify/migration/migrateSecrets.js.map +1 -0
- package/dist/apps/cli/verify/migration/oldGitlabCi.d.ts +16 -0
- package/dist/apps/cli/verify/migration/oldGitlabCi.js +24 -0
- package/dist/apps/cli/verify/migration/oldGitlabCi.js.map +1 -0
- package/dist/config/getProjectConfig.d.ts +2 -0
- package/dist/config/getProjectConfig.js +36 -3
- package/dist/config/getProjectConfig.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/files.js +6 -1
- package/dist/utils/files.js.map +1 -1
- package/dist/utils/gitlab.d.ts +1 -1
- package/dist/utils/gitlab.js +30 -6
- package/dist/utils/gitlab.js.map +1 -1
- package/dist/utils/passwordstore/index.d.ts +1 -1
- package/dist/utils/passwordstore/index.js +17 -20
- package/dist/utils/passwordstore/index.js.map +1 -1
- package/dist/utils/projects/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/apps/cli/cli.ts +5 -3
- package/src/apps/cli/commands/project/commandConfigSecrets.ts +22 -2
- package/src/apps/cli/config/writeConfig.ts +61 -0
- package/src/apps/cli/verify/index.ts +24 -0
- package/src/apps/cli/verify/migration/fromv2.ts +157 -0
- package/src/apps/cli/verify/migration/migrateSecrets.ts +32 -0
- package/src/apps/cli/verify/migration/oldGitlabCi.ts +40 -0
- package/src/config/getProjectConfig.ts +17 -1
- package/src/utils/editAsFile.ts +1 -1
- package/src/utils/files.ts +5 -1
- package/src/utils/gitlab.ts +18 -5
- package/src/utils/passwordstore/index.ts +19 -21
- package/src/utils/projects/index.ts +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BuildConfig } from "@catladder/pipeline";
|
|
2
|
+
|
|
3
|
+
export type OldGitlabCiFile = {
|
|
4
|
+
variables: {
|
|
5
|
+
CUSTOMER_NAME: string;
|
|
6
|
+
APP_NAME: string;
|
|
7
|
+
COMPONENT_NAME?: string;
|
|
8
|
+
APP_DIR?: string;
|
|
9
|
+
CLUSTER_NAME?: string;
|
|
10
|
+
};
|
|
11
|
+
include: {
|
|
12
|
+
project: string;
|
|
13
|
+
ref: string;
|
|
14
|
+
file: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const detectBuildConfig = (
|
|
19
|
+
gitlabCi: OldGitlabCiFile
|
|
20
|
+
): BuildConfig["type"] => {
|
|
21
|
+
const firstInclude = gitlabCi.include[0];
|
|
22
|
+
if (!firstInclude || gitlabCi.include[0]?.project !== "catladder/gitlab-ci") {
|
|
23
|
+
throw new Error("unsupported gitlab-ci file");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (firstInclude.file === "node-kubernetes.yml") {
|
|
27
|
+
return "node";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (firstInclude.file === "static-js-kubernetes.yml") {
|
|
31
|
+
return "node-static";
|
|
32
|
+
}
|
|
33
|
+
if (firstInclude.file === "meteor-kubernetes.yml") {
|
|
34
|
+
throw new Error("meteor is not yet implemented");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (firstInclude.file === "rails-kubernetes.yml") {
|
|
38
|
+
throw new Error("meteor is not yet implemented");
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -9,6 +9,7 @@ import { CommandInstance } from "vorpal";
|
|
|
9
9
|
import { getAllVariables } from "../utils/gitlab";
|
|
10
10
|
import memoizee from "memoizee";
|
|
11
11
|
import { getGitRoot } from "../utils/projects";
|
|
12
|
+
import { readYaml } from "../utils/files";
|
|
12
13
|
// currently cant change
|
|
13
14
|
|
|
14
15
|
export const getProjectConfig = memoizee(
|
|
@@ -18,11 +19,25 @@ export const getProjectConfig = memoizee(
|
|
|
18
19
|
return readConfigSync(gitRoot);
|
|
19
20
|
} catch (e) {
|
|
20
21
|
// ignore
|
|
22
|
+
return null;
|
|
21
23
|
}
|
|
22
24
|
},
|
|
23
25
|
{ promise: true }
|
|
24
26
|
);
|
|
25
27
|
|
|
28
|
+
export const getGitlabCiFilePath = async () => {
|
|
29
|
+
const gitRoot = await getGitRoot();
|
|
30
|
+
return gitRoot + "/.gitlab-ci.yml";
|
|
31
|
+
};
|
|
32
|
+
export const getGitlabCi = async () => {
|
|
33
|
+
try {
|
|
34
|
+
return readYaml(await getGitlabCiFilePath());
|
|
35
|
+
} catch (e) {
|
|
36
|
+
// ignore
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
26
41
|
export const getProjectComponents = async () => {
|
|
27
42
|
const config = await getProjectConfig();
|
|
28
43
|
if (!config) return [];
|
|
@@ -74,7 +89,7 @@ const resolveSecrets = async (
|
|
|
74
89
|
|
|
75
90
|
return Object.fromEntries(
|
|
76
91
|
Object.entries(allEnvVars).map(([key, value]) => {
|
|
77
|
-
const isSecret = value?.startsWith("$CL_");
|
|
92
|
+
const isSecret = value?.startsWith?.("$CL_");
|
|
78
93
|
if (isSecret) {
|
|
79
94
|
// secrets have CL_XXXX structure
|
|
80
95
|
const found = allVariablesInGitlab.find((v) => "$" + v.key === value);
|
|
@@ -96,5 +111,6 @@ export const getEnvVars = async (
|
|
|
96
111
|
componentName: string
|
|
97
112
|
) => {
|
|
98
113
|
const envionment = await getEnvironment(env, componentName);
|
|
114
|
+
|
|
99
115
|
return resolveSecrets(vorpal, envionment.envVars);
|
|
100
116
|
};
|
package/src/utils/editAsFile.ts
CHANGED
package/src/utils/files.ts
CHANGED
|
@@ -14,5 +14,9 @@ export const readFileOrError = async (filePath: string) => {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const readYaml = async (filename: string) => {
|
|
17
|
-
|
|
17
|
+
try {
|
|
18
|
+
return yaml.load(await readFile(filename));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
18
22
|
};
|
package/src/utils/gitlab.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { exec } from "child-process-promise";
|
|
2
|
+
import { isObject, result } from "lodash";
|
|
2
3
|
import memoizee from "memoizee";
|
|
3
4
|
import fetch from "node-fetch";
|
|
4
5
|
import open from "open";
|
|
@@ -99,7 +100,19 @@ type GitlabVariable = {
|
|
|
99
100
|
export const getAllVariables = memoizee(
|
|
100
101
|
async (vorpal: CommandInstance): Promise<Array<GitlabVariable>> => {
|
|
101
102
|
const { id } = await getProjectInfo(vorpal);
|
|
102
|
-
|
|
103
|
+
let all: Array<GitlabVariable> = [];
|
|
104
|
+
let result: Array<GitlabVariable>;
|
|
105
|
+
let page = 1;
|
|
106
|
+
do {
|
|
107
|
+
result = await doGitlabRequest(
|
|
108
|
+
vorpal,
|
|
109
|
+
// 100 is max page size
|
|
110
|
+
`projects/${id}/variables?per_page=100&page=${page}`
|
|
111
|
+
);
|
|
112
|
+
page++;
|
|
113
|
+
all = [...all, ...result];
|
|
114
|
+
} while (result?.length > 0);
|
|
115
|
+
return all;
|
|
103
116
|
},
|
|
104
117
|
{ promise: true }
|
|
105
118
|
);
|
|
@@ -133,7 +146,7 @@ const updateVariable = async (
|
|
|
133
146
|
};
|
|
134
147
|
export const upsertAllVariables = async (
|
|
135
148
|
vorpal: CommandInstance,
|
|
136
|
-
variables: Record<string,
|
|
149
|
+
variables: Record<string, any>,
|
|
137
150
|
env: string,
|
|
138
151
|
componentName: string
|
|
139
152
|
): Promise<void> => {
|
|
@@ -141,11 +154,11 @@ export const upsertAllVariables = async (
|
|
|
141
154
|
|
|
142
155
|
for (const [key, value] of Object.entries(variables ?? {})) {
|
|
143
156
|
const fullKey = "CL_" + env + "_" + componentName + "_" + key;
|
|
144
|
-
|
|
157
|
+
const valueSanitized = isObject(value) ? JSON.stringify(value) : `${value}`;
|
|
145
158
|
try {
|
|
146
|
-
await updateVariable(vorpal, id, fullKey,
|
|
159
|
+
await updateVariable(vorpal, id, fullKey, valueSanitized);
|
|
147
160
|
} catch (e) {
|
|
148
|
-
await createVariable(vorpal, id, fullKey,
|
|
161
|
+
await createVariable(vorpal, id, fullKey, valueSanitized);
|
|
149
162
|
} finally {
|
|
150
163
|
getAllVariables.clear();
|
|
151
164
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { exec, spawn } from "child-process-promise";
|
|
2
2
|
import commandExists from "command-exists-promise";
|
|
3
3
|
import dayjs from "dayjs";
|
|
4
|
-
|
|
5
4
|
import { readFile, writeFile } from "fs-extra";
|
|
6
|
-
import yaml from "js-yaml";
|
|
7
5
|
import { withFile } from "tmp-promise";
|
|
8
|
-
import formatEnvVars from "../formatEnvVars";
|
|
9
6
|
import getEditor from "../getEditor";
|
|
10
7
|
import { getPreference, hasPreference, setPreference } from "../preferences";
|
|
11
8
|
|
|
@@ -78,9 +75,7 @@ const execBitwardenCommand = async (command: string): Promise<any> => {
|
|
|
78
75
|
await loginBitwarden();
|
|
79
76
|
return execBitwardenCommand(command);
|
|
80
77
|
} else {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
console.log("wooops", e.message);
|
|
78
|
+
throw e;
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
81
|
};
|
|
@@ -169,24 +164,27 @@ const share = async (itemId: string) =>
|
|
|
169
164
|
])}`
|
|
170
165
|
);
|
|
171
166
|
|
|
172
|
-
export const
|
|
167
|
+
export const trashItem = async (path: string) => {
|
|
173
168
|
const item = await getItem(path);
|
|
174
169
|
|
|
175
|
-
await
|
|
176
|
-
await writeFile(tmpFilePath, item.notes);
|
|
177
|
-
await (await getEditor()).open(tmpFilePath);
|
|
178
|
-
const newContent = (await readFile(tmpFilePath)).toString("utf-8");
|
|
170
|
+
const result = await execBitwardenCommand(`delete item ${item.id}`);
|
|
179
171
|
|
|
180
|
-
|
|
181
|
-
...item,
|
|
182
|
-
notes: newContent,
|
|
183
|
-
});
|
|
184
|
-
}, { postfix: ".yml" });
|
|
172
|
+
return result;
|
|
185
173
|
};
|
|
174
|
+
export const editPass = async (path: string) => {
|
|
175
|
+
const item = await getItem(path);
|
|
186
176
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
177
|
+
await withFile(
|
|
178
|
+
async ({ path: tmpFilePath }) => {
|
|
179
|
+
await writeFile(tmpFilePath, item.notes);
|
|
180
|
+
await (await getEditor()).open(tmpFilePath);
|
|
181
|
+
const newContent = (await readFile(tmpFilePath)).toString("utf-8");
|
|
182
|
+
|
|
183
|
+
await update("item", item.id, {
|
|
184
|
+
...item,
|
|
185
|
+
notes: newContent,
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
{ postfix: ".yml" }
|
|
189
|
+
);
|
|
192
190
|
};
|
|
@@ -5,7 +5,7 @@ import { getProjectConfig, parseChoice } from "../../config/getProjectConfig";
|
|
|
5
5
|
import k8sApi from "../../k8sApi";
|
|
6
6
|
import { readFileOrError } from "../files";
|
|
7
7
|
|
|
8
|
-
export const getGitRoot = async () => {
|
|
8
|
+
export const getGitRoot = async (): Promise<string> => {
|
|
9
9
|
return (await exec("git rev-parse --show-toplevel")).stdout?.trim();
|
|
10
10
|
};
|
|
11
11
|
|