-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
52 lines (48 loc) · 1.42 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { execSync } from "child_process";
import { existsSync } from "fs";
const getCliPath = function () {
if (existsSync(__dirname + "/bin/cli.js")) {
return "node " + __dirname + "/bin/cli.js";
} else {
return "npx ssm-sync";
}
// if (process.env.NODE_ENV == "test") {
//
// } else {
// }
};
const getParameters = function (options: SSMLoaderGetParametersOptions): SSMParameters {
if (options.path && options.path != "/") {
let flagStr = Object.keys(options)
.map((k) => "--" + k.toLowerCase() + ' "' + options[k] + '"')
.join(" ");
try {
let result = execSync(`${getCliPath()} ` + flagStr).toString("utf-8");
let resultObj: any = JSON.parse(result);
if (resultObj && !resultObj.error) {
return resultObj;
} else {
console.error("ssm-sync error", resultObj);
return {};
}
} catch (e) {
if (e.output) {
console.error(e.output.toString("utf-8"));
}
return {};
}
} else {
throw new Error("No param path specified");
}
};
export { getParameters };
export default getParameters;
export interface SSMLoaderGetParametersOptions {
path: string;
key?: string;
secret?: string;
region?: string;
}
export interface SSMParameters {
[key: string]: string;
}