@varius.io/framework 13.12.3 → 13.12.5
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/vatom-vault-env.mjs +30 -2
- package/package.json +1 -1
package/bin/vatom-vault-env.mjs
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { spawn } from "child_process";
|
|
4
4
|
import fsp from "node:fs/promises";
|
|
5
|
-
import { format } from "node:util";
|
|
5
|
+
import { format, debuglog } from "node:util";
|
|
6
|
+
|
|
7
|
+
const debug = debuglog("vatom-vault-env");
|
|
6
8
|
|
|
7
9
|
const vaultApiBase = process.env.VAULT_ENV_VAULT_API_BASE;
|
|
8
10
|
|
|
@@ -56,6 +58,8 @@ async function fetchSecret(secretPath) {
|
|
|
56
58
|
);
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
debug("fetched secret, secretPath=%j", secretPath);
|
|
62
|
+
|
|
59
63
|
const resBody = await res.json();
|
|
60
64
|
return resBody.data;
|
|
61
65
|
}
|
|
@@ -83,6 +87,16 @@ export async function resolveEnv() {
|
|
|
83
87
|
for (const envVar of secretEnvVars) {
|
|
84
88
|
const secret = resolvedSecrets.get(envVar.secretPath);
|
|
85
89
|
const secretPropertyValue = secret.data[envVar.secretPropertyName];
|
|
90
|
+
|
|
91
|
+
if (secretPropertyValue === undefined) {
|
|
92
|
+
console.error(
|
|
93
|
+
"vatom-vault-env: no value in vault for requested secret property, secretPath=%j, propertyName=%j",
|
|
94
|
+
envVar.secretPath,
|
|
95
|
+
envVar.secretPropertyName
|
|
96
|
+
);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
|
|
86
100
|
newEnv[envVar.envKey] = secretPropertyValue;
|
|
87
101
|
}
|
|
88
102
|
|
|
@@ -100,6 +114,13 @@ function spawnChildProcess() {
|
|
|
100
114
|
|
|
101
115
|
const childCommand = process.argv.shift();
|
|
102
116
|
|
|
117
|
+
debug(
|
|
118
|
+
"spawning child process, command=%j, argv=%j, cwd=%j",
|
|
119
|
+
childCommand,
|
|
120
|
+
process.argv,
|
|
121
|
+
process.cwd()
|
|
122
|
+
);
|
|
123
|
+
|
|
103
124
|
const child = spawn(childCommand, process.argv, {
|
|
104
125
|
cwd: process.cwd(),
|
|
105
126
|
env: process.env,
|
|
@@ -112,14 +133,21 @@ function spawnChildProcess() {
|
|
|
112
133
|
}
|
|
113
134
|
|
|
114
135
|
async function main() {
|
|
136
|
+
debug("starting");
|
|
137
|
+
|
|
115
138
|
// need to temporarily allow self-signed certs
|
|
116
139
|
const oldRejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
|
117
140
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
118
141
|
|
|
119
142
|
const resolvedEnv = await resolveEnv();
|
|
143
|
+
debug("resolved env vars, names=%j", Object.keys(resolvedEnv).join(" "));
|
|
120
144
|
|
|
121
145
|
// reset self-signed cert permission, for the child process
|
|
122
|
-
|
|
146
|
+
if (oldRejectUnauthorized === undefined) {
|
|
147
|
+
delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
|
148
|
+
} else {
|
|
149
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = oldRejectUnauthorized;
|
|
150
|
+
}
|
|
123
151
|
|
|
124
152
|
process.env = { ...process.env, ...resolvedEnv };
|
|
125
153
|
|