@dataformer/env-service 1.0.0
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/index.d.ts +48 -0
- package/dist/index.js +387 -0
- package/package.json +30 -0
- package/src/index.ts +440 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
declare const askQuestion: (question: string, defaultValue?: string) => Promise<string>;
|
|
2
|
+
declare function obfuscateCred(cred: string | null): string;
|
|
3
|
+
declare function getEnvVar(baseSecretKey: string): Promise<string | null>;
|
|
4
|
+
declare function getCustomSearchApiKey(): Promise<string>;
|
|
5
|
+
declare function getSearchEngineId(): Promise<string>;
|
|
6
|
+
declare function getFirestoreProjectId(): Promise<string>;
|
|
7
|
+
declare function setEnvVar(baseSecretKey: string, value: string): Promise<boolean>;
|
|
8
|
+
declare const setLogToConsole: () => Promise<void>;
|
|
9
|
+
declare const setPostgresUser: () => Promise<void>;
|
|
10
|
+
declare const setPostgresPassword: () => Promise<void>;
|
|
11
|
+
declare const setPostgresDatabase: () => Promise<void>;
|
|
12
|
+
declare const setPostgresHostName: () => Promise<void>;
|
|
13
|
+
declare const setPostgresIpType: () => Promise<void>;
|
|
14
|
+
declare const setPostgresPoolSizeMax: () => Promise<void>;
|
|
15
|
+
declare const setPostgresInstanceConnectionName: () => Promise<void>;
|
|
16
|
+
declare const setBigtableInstanceName: () => Promise<void>;
|
|
17
|
+
declare const setBigtableTableName: () => Promise<void>;
|
|
18
|
+
declare const setBigtableProjectId: () => Promise<void>;
|
|
19
|
+
declare const setJiraApiToken: () => Promise<void>;
|
|
20
|
+
declare const setJiraApiBaseUrl: () => Promise<void>;
|
|
21
|
+
declare const setJiraUserEmail: () => Promise<void>;
|
|
22
|
+
declare const setGeminiApiKey: () => Promise<void>;
|
|
23
|
+
declare const setNpmToken: () => Promise<void>;
|
|
24
|
+
declare const setCustomSearchApiKey: () => Promise<void>;
|
|
25
|
+
declare const setFirestoreProjectId: () => Promise<void>;
|
|
26
|
+
declare const getLogToConsole: () => Promise<string | null>;
|
|
27
|
+
declare const getPostgresUser: () => Promise<string | null>;
|
|
28
|
+
declare const getPostgresPassword: () => Promise<string | null>;
|
|
29
|
+
declare const getPostgresDatabase: () => Promise<string | null>;
|
|
30
|
+
declare const getPostgresHostName: () => Promise<string | null>;
|
|
31
|
+
declare const getPostgresIpType: () => Promise<string | null>;
|
|
32
|
+
declare const getPostgresPoolSizeMax: () => Promise<number | null>;
|
|
33
|
+
declare const getPostgresInstanceConnectionName: () => Promise<string | null>;
|
|
34
|
+
declare const getBigtableInstanceName: () => Promise<string | null>;
|
|
35
|
+
declare const getBigtableTableName: () => Promise<string | null>;
|
|
36
|
+
declare const getBigtableProjectId: () => Promise<string | null>;
|
|
37
|
+
declare const getJiraApiToken: () => Promise<string | null>;
|
|
38
|
+
declare const getJiraApiBaseUrl: () => Promise<string | null>;
|
|
39
|
+
declare const getJiraUserEmail: () => Promise<string | null>;
|
|
40
|
+
declare const getGeminiApiKey: () => Promise<string | null>;
|
|
41
|
+
declare const getNpmToken: () => Promise<string | null>;
|
|
42
|
+
declare const getProjectRoot: () => string;
|
|
43
|
+
declare const getGcpProjectId: () => Promise<string | null>;
|
|
44
|
+
declare const getGcpUserEmail: () => Promise<string | null>;
|
|
45
|
+
declare const printEnv: () => Promise<void>;
|
|
46
|
+
declare const run: () => Promise<void>;
|
|
47
|
+
|
|
48
|
+
export { askQuestion, getBigtableInstanceName, getBigtableProjectId, getBigtableTableName, getCustomSearchApiKey, getEnvVar, getFirestoreProjectId, getGcpProjectId, getGcpUserEmail, getGeminiApiKey, getJiraApiBaseUrl, getJiraApiToken, getJiraUserEmail, getLogToConsole, getNpmToken, getPostgresDatabase, getPostgresHostName, getPostgresInstanceConnectionName, getPostgresIpType, getPostgresPassword, getPostgresPoolSizeMax, getPostgresUser, getProjectRoot, getSearchEngineId, obfuscateCred, printEnv, run, setBigtableInstanceName, setBigtableProjectId, setBigtableTableName, setCustomSearchApiKey, setEnvVar, setFirestoreProjectId, setGeminiApiKey, setJiraApiBaseUrl, setJiraApiToken, setJiraUserEmail, setLogToConsole, setNpmToken, setPostgresDatabase, setPostgresHostName, setPostgresInstanceConnectionName, setPostgresIpType, setPostgresPassword, setPostgresPoolSizeMax, setPostgresUser };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import readline from "readline";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { createSecretManagerClient } from "@dataformer/secret-manager-client";
|
|
5
|
+
var secretManager = null;
|
|
6
|
+
var secretManagerInitialized = false;
|
|
7
|
+
async function getSecretManager() {
|
|
8
|
+
if (secretManagerInitialized) {
|
|
9
|
+
return secretManager;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
secretManager = await createSecretManagerClient();
|
|
13
|
+
secretManagerInitialized = true;
|
|
14
|
+
return secretManager;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error("[EnvService.ts] Failed to initialize SecretManagerClient:", error.message);
|
|
17
|
+
console.warn("[EnvService.ts] Secret Manager functionality will be unavailable.");
|
|
18
|
+
secretManagerInitialized = true;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
var rl = readline.createInterface({
|
|
23
|
+
input: process.stdin,
|
|
24
|
+
output: process.stdout
|
|
25
|
+
});
|
|
26
|
+
var askQuestion = (question, defaultValue = "") => {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
rl.question(question + (defaultValue ? ` [${defaultValue}]: ` : ": "), (answer) => {
|
|
29
|
+
resolve(answer || defaultValue);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
function obfuscateCred(cred) {
|
|
34
|
+
if (cred && cred.length >= 6) {
|
|
35
|
+
const start = cred.substring(0, 3);
|
|
36
|
+
const end = cred.substring(cred.length - 3);
|
|
37
|
+
return `${start}...${end}`;
|
|
38
|
+
} else {
|
|
39
|
+
return cred || "";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function getEnvVar(baseSecretKey) {
|
|
43
|
+
const sm = await getSecretManager();
|
|
44
|
+
if (!sm) {
|
|
45
|
+
console.warn(`[EnvService.ts] SecretManager not available for getEnvVar (key: ${baseSecretKey})`);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return sm.getSecret(baseSecretKey);
|
|
49
|
+
}
|
|
50
|
+
async function getCustomSearchApiKey() {
|
|
51
|
+
const apiKey = await getEnvVar("CUSTOM_SEARCH_API_KEY");
|
|
52
|
+
if (!apiKey) {
|
|
53
|
+
throw new Error("CUSTOM_SEARCH_API_KEY not found in environment variables.");
|
|
54
|
+
}
|
|
55
|
+
return apiKey;
|
|
56
|
+
}
|
|
57
|
+
async function getSearchEngineId() {
|
|
58
|
+
const searchEngineId = await getEnvVar("SEARCH_ENGINE_ID");
|
|
59
|
+
if (!searchEngineId) {
|
|
60
|
+
throw new Error("SEARCH_ENGINE_ID not found in environment variables.");
|
|
61
|
+
}
|
|
62
|
+
return searchEngineId;
|
|
63
|
+
}
|
|
64
|
+
async function getFirestoreProjectId() {
|
|
65
|
+
const projectId = await getEnvVar("FIRESTORE_PROJECT_ID");
|
|
66
|
+
if (!projectId) {
|
|
67
|
+
throw new Error("FIRESTORE_PROJECT_ID not found in environment variables.");
|
|
68
|
+
}
|
|
69
|
+
return projectId;
|
|
70
|
+
}
|
|
71
|
+
async function setEnvVar(baseSecretKey, value) {
|
|
72
|
+
const sm = await getSecretManager();
|
|
73
|
+
if (!sm) {
|
|
74
|
+
console.warn(`[EnvService.ts] SecretManager not available for setEnvVar (key: ${baseSecretKey})`);
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
return sm.setSecret(baseSecretKey, value);
|
|
78
|
+
}
|
|
79
|
+
var setLogToConsole = async () => {
|
|
80
|
+
const logToConsole = await askQuestion("Use consoleLogger to log to console? (yes, no)", "no");
|
|
81
|
+
if (logToConsole) {
|
|
82
|
+
await setEnvVar("LOG_TO_CONSOLE", logToConsole);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var setPostgresUser = async () => {
|
|
86
|
+
const user = await askQuestion("Enter PostgreSQL User", "");
|
|
87
|
+
if (user) {
|
|
88
|
+
await setEnvVar("POSTGRES_USER", user);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var setPostgresPassword = async () => {
|
|
92
|
+
const password = await askQuestion("Enter PostgreSQL Password", "");
|
|
93
|
+
if (password) {
|
|
94
|
+
await setEnvVar("POSTGRES_PASSWORD", password);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var setPostgresDatabase = async () => {
|
|
98
|
+
const database = await askQuestion("Enter PostgreSQL Database", "");
|
|
99
|
+
if (database) {
|
|
100
|
+
await setEnvVar("POSTGRES_DATABASE", database);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var setPostgresHostName = async () => {
|
|
104
|
+
const hostName = await askQuestion("Enter PostgreSQL Host name", "localhost");
|
|
105
|
+
if (hostName) {
|
|
106
|
+
await setEnvVar("POSTGRES_HOST_NAME", hostName);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var setPostgresIpType = async () => {
|
|
110
|
+
const ipType = await askQuestion("Enter PostgreSQL IP Type (PUBLIC, PRIVATE)", "PUBLIC");
|
|
111
|
+
if (ipType) {
|
|
112
|
+
await setEnvVar("POSTGRES_IP_TYPE", ipType);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var setPostgresPoolSizeMax = async () => {
|
|
116
|
+
const poolSizeMax = await askQuestion("Enter Maximum Pool Size for PostgreSQL", "10");
|
|
117
|
+
if (poolSizeMax) {
|
|
118
|
+
await setEnvVar("POSTGRES_POOL_SIZE_MAX", poolSizeMax);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var setPostgresInstanceConnectionName = async () => {
|
|
122
|
+
const instanceConnectionName = await askQuestion("Enter PostgreSQL Instance Connection Name (your-project:your-region:your-instance)", "");
|
|
123
|
+
if (instanceConnectionName) {
|
|
124
|
+
await setEnvVar("POSTGRES_INSTANCE_CONNECTION_NAME", instanceConnectionName);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var setBigtableInstanceName = async () => {
|
|
128
|
+
const btInstanceName = await askQuestion("Enter Bigtable Instance Name", "");
|
|
129
|
+
if (btInstanceName) {
|
|
130
|
+
await setEnvVar("BIGTABLE_INSTANCE_NAME", btInstanceName);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var setBigtableTableName = async () => {
|
|
134
|
+
const btTableName = await askQuestion("Enter Bigtable Table Name", "");
|
|
135
|
+
if (btTableName) {
|
|
136
|
+
await setEnvVar("BIGTABLE_TABLE_NAME", btTableName);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var setBigtableProjectId = async () => {
|
|
140
|
+
const btProjectId = await askQuestion("Enter Bigtable Google Project", "");
|
|
141
|
+
if (btProjectId) {
|
|
142
|
+
await setEnvVar("BIGTABLE_PROJECT_ID", btProjectId);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var setJiraApiToken = async () => {
|
|
146
|
+
const jiraApiToken = await askQuestion("Enter Jira API token", "");
|
|
147
|
+
if (jiraApiToken) {
|
|
148
|
+
await setEnvVar("JIRA_API_TOKEN", jiraApiToken);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var setJiraApiBaseUrl = async () => {
|
|
152
|
+
const jiraApiBaseUrl = await askQuestion("Enter Jira API Base URL", "");
|
|
153
|
+
if (jiraApiBaseUrl) {
|
|
154
|
+
await setEnvVar("JIRA_API_BASE_URL", jiraApiBaseUrl);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var setJiraUserEmail = async () => {
|
|
158
|
+
const jiraUserEmail = await askQuestion("Enter Jira user email", "you@domain.com");
|
|
159
|
+
if (jiraUserEmail) {
|
|
160
|
+
await setEnvVar("JIRA_USER_EMAIL", jiraUserEmail);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var setGeminiApiKey = async () => {
|
|
164
|
+
const apiKey = await askQuestion("Enter Gemini API key:");
|
|
165
|
+
if (apiKey) await setEnvVar("GEMINI_API_KEY", apiKey);
|
|
166
|
+
};
|
|
167
|
+
var setNpmToken = async () => {
|
|
168
|
+
const npmToken = await askQuestion("Enter NPM Token:");
|
|
169
|
+
if (npmToken) await setEnvVar("NPM_TOKEN", npmToken);
|
|
170
|
+
};
|
|
171
|
+
var setCustomSearchApiKey = async () => {
|
|
172
|
+
const customSearchApiKey = await askQuestion("Enter Custom Search API Key", "");
|
|
173
|
+
if (customSearchApiKey) {
|
|
174
|
+
await setEnvVar("CUSTOM_SEARCH_API_KEY", customSearchApiKey);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
var setFirestoreProjectId = async () => {
|
|
178
|
+
const firestoreProjectId = await askQuestion("Enter Firestore Project ID", "dataformer-prod");
|
|
179
|
+
if (firestoreProjectId) {
|
|
180
|
+
await setEnvVar("FIRESTORE_PROJECT_ID", firestoreProjectId);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var getLogToConsole = async () => await getEnvVar("LOG_TO_CONSOLE");
|
|
184
|
+
var getPostgresUser = async () => await getEnvVar("POSTGRES_USER");
|
|
185
|
+
var getPostgresPassword = async () => await getEnvVar("POSTGRES_PASSWORD");
|
|
186
|
+
var getPostgresDatabase = async () => await getEnvVar("POSTGRES_DATABASE");
|
|
187
|
+
var getPostgresHostName = async () => await getEnvVar("POSTGRES_HOST_NAME");
|
|
188
|
+
var getPostgresIpType = async () => await getEnvVar("POSTGRES_IP_TYPE");
|
|
189
|
+
var getPostgresPoolSizeMax = async () => {
|
|
190
|
+
const value = await getEnvVar("POSTGRES_POOL_SIZE_MAX");
|
|
191
|
+
return value ? parseInt(value, 10) : null;
|
|
192
|
+
};
|
|
193
|
+
var getPostgresInstanceConnectionName = async () => await getEnvVar("POSTGRES_INSTANCE_CONNECTION_NAME");
|
|
194
|
+
var getBigtableInstanceName = async () => await getEnvVar("BIGTABLE_INSTANCE_NAME");
|
|
195
|
+
var getBigtableTableName = async () => await getEnvVar("BIGTABLE_TABLE_NAME");
|
|
196
|
+
var getBigtableProjectId = async () => await getEnvVar("BIGTABLE_PROJECT_ID");
|
|
197
|
+
var _getFirestoreProjectId = async () => await getEnvVar("FIRESTORE_PROJECT_ID");
|
|
198
|
+
var getJiraApiToken = async () => await getEnvVar("JIRA_API_TOKEN");
|
|
199
|
+
var getJiraApiBaseUrl = async () => await getEnvVar("JIRA_API_BASE_URL");
|
|
200
|
+
var getJiraUserEmail = async () => await getEnvVar("JIRA_USER_EMAIL");
|
|
201
|
+
var getGeminiApiKey = async () => await getEnvVar("GEMINI_API_KEY");
|
|
202
|
+
var getNpmToken = async () => await getEnvVar("NPM_TOKEN");
|
|
203
|
+
var getProjectRoot = () => {
|
|
204
|
+
const currentDir = path.dirname(new URL(import.meta.url).pathname);
|
|
205
|
+
return path.resolve(currentDir, "../..");
|
|
206
|
+
};
|
|
207
|
+
var _getResolvedGcpProjectId = async () => {
|
|
208
|
+
const sm = await getSecretManager();
|
|
209
|
+
if (!sm) {
|
|
210
|
+
console.warn("[EnvService.ts] SecretManager not available for _getResolvedGcpProjectId");
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
return sm.getResolvedProjectId();
|
|
214
|
+
};
|
|
215
|
+
var _getResolvedGcpUserEmail = async () => {
|
|
216
|
+
const sm = await getSecretManager();
|
|
217
|
+
if (!sm) {
|
|
218
|
+
console.warn("[EnvService.ts] SecretManager not available for _getResolvedGcpUserEmail");
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
return sm.getResolvedUserEmail();
|
|
222
|
+
};
|
|
223
|
+
var getGcpProjectId = _getResolvedGcpProjectId;
|
|
224
|
+
var getGcpUserEmail = _getResolvedGcpUserEmail;
|
|
225
|
+
var printEnv = async () => {
|
|
226
|
+
const logToConsole = await getLogToConsole();
|
|
227
|
+
const postgresUser = await getPostgresUser();
|
|
228
|
+
const postgresPassword = await getPostgresPassword();
|
|
229
|
+
const postgresDatabase = await getPostgresDatabase();
|
|
230
|
+
const postgresHostName = await getPostgresHostName();
|
|
231
|
+
const postgresIpType = await getPostgresIpType();
|
|
232
|
+
const postgresPoolSizeMax = await getPostgresPoolSizeMax();
|
|
233
|
+
const postgresInstanceConnectionName = await getPostgresInstanceConnectionName();
|
|
234
|
+
const bigtableInstanceName = await getBigtableInstanceName();
|
|
235
|
+
const bigtableTableName = await getBigtableTableName();
|
|
236
|
+
const bigtableProjectId = await getBigtableProjectId();
|
|
237
|
+
const firestoreProjectId = await _getFirestoreProjectId();
|
|
238
|
+
const jiraApiToken = await getJiraApiToken();
|
|
239
|
+
const jiraApiBaseUrl = await getJiraApiBaseUrl();
|
|
240
|
+
const jiraUserEmail = await getJiraUserEmail();
|
|
241
|
+
const geminiApiKey = await getGeminiApiKey();
|
|
242
|
+
const customSearchApiKey = await getCustomSearchApiKey();
|
|
243
|
+
const gcpProjectIdVal = await getGcpProjectId();
|
|
244
|
+
const gcpUserEmailVal = await getGcpUserEmail();
|
|
245
|
+
const npmToken = await getNpmToken();
|
|
246
|
+
console.log(`Project Root: ${getProjectRoot()}`);
|
|
247
|
+
console.log(`GCP Project ID: ${gcpProjectIdVal}`);
|
|
248
|
+
console.log(`GCP User Email (for Secret Manager naming): ${gcpUserEmailVal}`);
|
|
249
|
+
console.log(`Log to Console: ${logToConsole}`);
|
|
250
|
+
console.log(`PostgreSQL User: ${postgresUser}`);
|
|
251
|
+
console.log(`PostgreSQL Password: ${obfuscateCred(postgresPassword)}`);
|
|
252
|
+
console.log(`PostgreSQL Database: ${postgresDatabase}`);
|
|
253
|
+
console.log(`PostgreSQL Host Name: ${postgresHostName}`);
|
|
254
|
+
console.log(`PostgreSQL IP Type: ${postgresIpType}`);
|
|
255
|
+
console.log(`PostgreSQL Pool Size Max: ${postgresPoolSizeMax}`);
|
|
256
|
+
console.log(`PostgreSQL Instance Connection Name: ${postgresInstanceConnectionName}`);
|
|
257
|
+
console.log(`Bigtable Instance Name: ${bigtableInstanceName}`);
|
|
258
|
+
console.log(`Bigtable Table Name: ${bigtableTableName}`);
|
|
259
|
+
console.log(`Bigtable Project ID: ${bigtableProjectId}`);
|
|
260
|
+
console.log(`Firestore Project ID: ${firestoreProjectId}`);
|
|
261
|
+
console.log(`Jira API Token: ${obfuscateCred(jiraApiToken)}`);
|
|
262
|
+
console.log(`Jira API Base URL: ${jiraApiBaseUrl}`);
|
|
263
|
+
console.log(`Jira User Email: ${jiraUserEmail}`);
|
|
264
|
+
console.log(`Custom Search API Key: ${obfuscateCred(customSearchApiKey)}`);
|
|
265
|
+
console.log(`Gemini API Key: ${obfuscateCred(geminiApiKey)}`);
|
|
266
|
+
console.log(`NPM Token: ${obfuscateCred(npmToken)}`);
|
|
267
|
+
};
|
|
268
|
+
var run = async () => {
|
|
269
|
+
const command = process.argv[2];
|
|
270
|
+
switch (command) {
|
|
271
|
+
case "setLogToConsole":
|
|
272
|
+
await setLogToConsole();
|
|
273
|
+
break;
|
|
274
|
+
case "setPostgresUser":
|
|
275
|
+
await setPostgresUser();
|
|
276
|
+
break;
|
|
277
|
+
case "setPostgresPassword":
|
|
278
|
+
await setPostgresPassword();
|
|
279
|
+
break;
|
|
280
|
+
case "setPostgresDatabase":
|
|
281
|
+
await setPostgresDatabase();
|
|
282
|
+
break;
|
|
283
|
+
case "setPostgresHostName":
|
|
284
|
+
await setPostgresHostName();
|
|
285
|
+
break;
|
|
286
|
+
case "setPostgresIpType":
|
|
287
|
+
await setPostgresIpType();
|
|
288
|
+
break;
|
|
289
|
+
case "setPostgresPoolSizeMax":
|
|
290
|
+
await setPostgresPoolSizeMax();
|
|
291
|
+
break;
|
|
292
|
+
case "setPostgresInstanceConnectionName":
|
|
293
|
+
await setPostgresInstanceConnectionName();
|
|
294
|
+
break;
|
|
295
|
+
case "setBigtableInstanceName":
|
|
296
|
+
await setBigtableInstanceName();
|
|
297
|
+
break;
|
|
298
|
+
case "setBigtableTableName":
|
|
299
|
+
await setBigtableTableName();
|
|
300
|
+
break;
|
|
301
|
+
case "setBigtableProjectId":
|
|
302
|
+
await setBigtableProjectId();
|
|
303
|
+
break;
|
|
304
|
+
case "setFirestoreProjectId":
|
|
305
|
+
await setFirestoreProjectId();
|
|
306
|
+
break;
|
|
307
|
+
case "setJiraApiToken":
|
|
308
|
+
await setJiraApiToken();
|
|
309
|
+
break;
|
|
310
|
+
case "setJiraApiBaseUrl":
|
|
311
|
+
await setJiraApiBaseUrl();
|
|
312
|
+
break;
|
|
313
|
+
case "setJiraUserEmail":
|
|
314
|
+
await setJiraUserEmail();
|
|
315
|
+
break;
|
|
316
|
+
case "setGeminiApiKey":
|
|
317
|
+
await setGeminiApiKey();
|
|
318
|
+
break;
|
|
319
|
+
case "setNpmToken":
|
|
320
|
+
await setNpmToken();
|
|
321
|
+
break;
|
|
322
|
+
case "setCustomSearchApiKey":
|
|
323
|
+
await setCustomSearchApiKey();
|
|
324
|
+
break;
|
|
325
|
+
case "printEnv":
|
|
326
|
+
await printEnv();
|
|
327
|
+
break;
|
|
328
|
+
default:
|
|
329
|
+
console.log("Unknown command. Available commands: setEnv, setBearerToken, ..., printEnv");
|
|
330
|
+
}
|
|
331
|
+
rl.close();
|
|
332
|
+
};
|
|
333
|
+
if (process.argv[1] === new URL(import.meta.url).pathname) {
|
|
334
|
+
run().catch((error) => {
|
|
335
|
+
console.error("[EnvService.ts] An error occurred:", error);
|
|
336
|
+
rl.close();
|
|
337
|
+
process.exit(1);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
export {
|
|
341
|
+
askQuestion,
|
|
342
|
+
getBigtableInstanceName,
|
|
343
|
+
getBigtableProjectId,
|
|
344
|
+
getBigtableTableName,
|
|
345
|
+
getCustomSearchApiKey,
|
|
346
|
+
getEnvVar,
|
|
347
|
+
getFirestoreProjectId,
|
|
348
|
+
getGcpProjectId,
|
|
349
|
+
getGcpUserEmail,
|
|
350
|
+
getGeminiApiKey,
|
|
351
|
+
getJiraApiBaseUrl,
|
|
352
|
+
getJiraApiToken,
|
|
353
|
+
getJiraUserEmail,
|
|
354
|
+
getLogToConsole,
|
|
355
|
+
getNpmToken,
|
|
356
|
+
getPostgresDatabase,
|
|
357
|
+
getPostgresHostName,
|
|
358
|
+
getPostgresInstanceConnectionName,
|
|
359
|
+
getPostgresIpType,
|
|
360
|
+
getPostgresPassword,
|
|
361
|
+
getPostgresPoolSizeMax,
|
|
362
|
+
getPostgresUser,
|
|
363
|
+
getProjectRoot,
|
|
364
|
+
getSearchEngineId,
|
|
365
|
+
obfuscateCred,
|
|
366
|
+
printEnv,
|
|
367
|
+
run,
|
|
368
|
+
setBigtableInstanceName,
|
|
369
|
+
setBigtableProjectId,
|
|
370
|
+
setBigtableTableName,
|
|
371
|
+
setCustomSearchApiKey,
|
|
372
|
+
setEnvVar,
|
|
373
|
+
setFirestoreProjectId,
|
|
374
|
+
setGeminiApiKey,
|
|
375
|
+
setJiraApiBaseUrl,
|
|
376
|
+
setJiraApiToken,
|
|
377
|
+
setJiraUserEmail,
|
|
378
|
+
setLogToConsole,
|
|
379
|
+
setNpmToken,
|
|
380
|
+
setPostgresDatabase,
|
|
381
|
+
setPostgresHostName,
|
|
382
|
+
setPostgresInstanceConnectionName,
|
|
383
|
+
setPostgresIpType,
|
|
384
|
+
setPostgresPassword,
|
|
385
|
+
setPostgresPoolSizeMax,
|
|
386
|
+
setPostgresUser
|
|
387
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dataformer/env-service",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Environment service for Dataformer",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
16
|
+
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
17
|
+
"prepublish": "pnpm run build"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@google-cloud/secret-manager": "^5.4.0",
|
|
21
|
+
"@dataformer/secret-manager-client": "workspace:*"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"tsup": "^8.0.0",
|
|
25
|
+
"typescript": "^5.5.3"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"typescript": "^5.0.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
// EnvService.ts - Manages environment variables and credentials using Google Secret Manager.
|
|
2
|
+
//
|
|
3
|
+
// HOW TO USE:
|
|
4
|
+
// This script is typically invoked via the wrapper `env.js` in the project root.
|
|
5
|
+
// Commands are passed as arguments, e.g.:
|
|
6
|
+
// node env.js printEnv - Prints all current environment variable values.
|
|
7
|
+
// node env.js setApiKey - Prompts to set the API key.
|
|
8
|
+
// ... and so on for other specific setters listed in the `run` function's switch statement.
|
|
9
|
+
//
|
|
10
|
+
// GCLOUD AUTHENTICATION REQUIREMENT:
|
|
11
|
+
// This script requires you to be authenticated with Google Cloud CLI (`gcloud`).
|
|
12
|
+
// The credentials are used by the underlying SecretManagerClient to access Google Secret Manager.
|
|
13
|
+
//
|
|
14
|
+
// TO AUTHENTICATE WITH GCLOUD:
|
|
15
|
+
// 1. Install Google Cloud SDK: https://cloud.google.com/sdk/docs/install
|
|
16
|
+
// 2. Initialize gcloud (if you haven't already):
|
|
17
|
+
// gcloud init
|
|
18
|
+
// - Follow the prompts to log in with your Google account and choose/create a project.
|
|
19
|
+
// 3. Log in with application default credentials:
|
|
20
|
+
// gcloud auth application-default login
|
|
21
|
+
// - This command opens a browser window for you to authorize gcloud to access your Google account.
|
|
22
|
+
// Your user credentials will be used by SecretManagerClient to interact with Secret Manager.
|
|
23
|
+
// Ensure the authenticated user has the necessary IAM permissions on Secret Manager
|
|
24
|
+
// (e.g., roles/secretmanager.secretAccessor and roles/secretmanager.secretVersionAdder)
|
|
25
|
+
// for your GCP project.
|
|
26
|
+
//
|
|
27
|
+
// PROJECT ID DETECTION:
|
|
28
|
+
// The SecretManagerClient automatically detects the GCP project ID from:
|
|
29
|
+
// 1. SECRET_MANAGER_PROJECT_ID environment variable (for CI/CD deployments)
|
|
30
|
+
// 2. Your local gcloud configuration (for development: `gcloud config get-value project`)
|
|
31
|
+
// 3. Explicit override via createSecretManagerClient({ projectId: "your-project" })
|
|
32
|
+
//
|
|
33
|
+
// SECRET NAMING CONVENTION:
|
|
34
|
+
// Secrets are named using the format: {projectId}_{userEmail}_{secretId}
|
|
35
|
+
// This ensures user-specific secrets that don't conflict across users or projects.
|
|
36
|
+
|
|
37
|
+
import readline from 'readline';
|
|
38
|
+
import path from 'path';
|
|
39
|
+
import { createSecretManagerClient, SecretManagerClient } from '@dataformer/secret-manager-client';
|
|
40
|
+
|
|
41
|
+
// SecretManager client will be initialized lazily on first use
|
|
42
|
+
let secretManager: SecretManagerClient | null = null;
|
|
43
|
+
let secretManagerInitialized = false;
|
|
44
|
+
|
|
45
|
+
async function getSecretManager(): Promise<SecretManagerClient | null> {
|
|
46
|
+
if (secretManagerInitialized) {
|
|
47
|
+
return secretManager;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
secretManager = await createSecretManagerClient();
|
|
52
|
+
secretManagerInitialized = true;
|
|
53
|
+
return secretManager;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('[EnvService.ts] Failed to initialize SecretManagerClient:', (error as Error).message);
|
|
56
|
+
console.warn('[EnvService.ts] Secret Manager functionality will be unavailable.');
|
|
57
|
+
secretManagerInitialized = true; // Prevent retrying
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const rl = readline.createInterface({
|
|
63
|
+
input: process.stdin,
|
|
64
|
+
output: process.stdout,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const askQuestion = (question: string, defaultValue: string = ''): Promise<string> => {
|
|
68
|
+
return new Promise((resolve) => {
|
|
69
|
+
rl.question(question + (defaultValue ? ` [${defaultValue}]: ` : ': '), (answer: string) => {
|
|
70
|
+
resolve(answer || defaultValue);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function obfuscateCred(cred: string | null): string {
|
|
76
|
+
if (cred && cred.length >= 6) {
|
|
77
|
+
const start = cred.substring(0, 3);
|
|
78
|
+
const end = cred.substring(cred.length - 3);
|
|
79
|
+
return `${start}...${end}`;
|
|
80
|
+
} else {
|
|
81
|
+
return cred || '';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// --- Generic Environment Variable Accessors ---
|
|
86
|
+
async function getEnvVar(baseSecretKey: string): Promise<string | null> {
|
|
87
|
+
const sm = await getSecretManager();
|
|
88
|
+
if (!sm) {
|
|
89
|
+
console.warn(`[EnvService.ts] SecretManager not available for getEnvVar (key: ${baseSecretKey})`);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
return sm.getSecret(baseSecretKey);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function getCustomSearchApiKey(): Promise<string> {
|
|
96
|
+
const apiKey = await getEnvVar('CUSTOM_SEARCH_API_KEY');
|
|
97
|
+
if (!apiKey) {
|
|
98
|
+
throw new Error('CUSTOM_SEARCH_API_KEY not found in environment variables.');
|
|
99
|
+
}
|
|
100
|
+
return apiKey;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function getSearchEngineId(): Promise<string> {
|
|
104
|
+
const searchEngineId = await getEnvVar('SEARCH_ENGINE_ID');
|
|
105
|
+
if (!searchEngineId) {
|
|
106
|
+
throw new Error('SEARCH_ENGINE_ID not found in environment variables.');
|
|
107
|
+
}
|
|
108
|
+
return searchEngineId;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function getFirestoreProjectId(): Promise<string> {
|
|
112
|
+
const projectId = await getEnvVar('FIRESTORE_PROJECT_ID');
|
|
113
|
+
if (!projectId) {
|
|
114
|
+
throw new Error('FIRESTORE_PROJECT_ID not found in environment variables.');
|
|
115
|
+
}
|
|
116
|
+
return projectId;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function setEnvVar(baseSecretKey: string, value: string): Promise<boolean> {
|
|
120
|
+
const sm = await getSecretManager();
|
|
121
|
+
if (!sm) {
|
|
122
|
+
console.warn(`[EnvService.ts] SecretManager not available for setEnvVar (key: ${baseSecretKey})`);
|
|
123
|
+
return false; // Indicate failure
|
|
124
|
+
}
|
|
125
|
+
// TODO: need to get change iamPolicy permissions
|
|
126
|
+
// const currentUserOnly = true;
|
|
127
|
+
return sm.setSecret(baseSecretKey, value);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// --- Specific Setters (Now use generic setEnvVar) ---
|
|
131
|
+
const setLogToConsole = async (): Promise<void> => {
|
|
132
|
+
const logToConsole = await askQuestion('Use consoleLogger to log to console? (yes, no)', 'no');
|
|
133
|
+
if (logToConsole) {
|
|
134
|
+
await setEnvVar('LOG_TO_CONSOLE', logToConsole);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const setPostgresUser = async (): Promise<void> => {
|
|
139
|
+
const user = await askQuestion('Enter PostgreSQL User', '');
|
|
140
|
+
if (user) {
|
|
141
|
+
await setEnvVar('POSTGRES_USER', user);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const setPostgresPassword = async (): Promise<void> => {
|
|
146
|
+
const password = await askQuestion('Enter PostgreSQL Password', '');
|
|
147
|
+
if (password) {
|
|
148
|
+
await setEnvVar('POSTGRES_PASSWORD', password);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const setPostgresDatabase = async (): Promise<void> => {
|
|
153
|
+
const database = await askQuestion('Enter PostgreSQL Database', '');
|
|
154
|
+
if (database) {
|
|
155
|
+
await setEnvVar('POSTGRES_DATABASE', database);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const setPostgresHostName = async (): Promise<void> => {
|
|
160
|
+
const hostName = await askQuestion('Enter PostgreSQL Host name', 'localhost');
|
|
161
|
+
if (hostName) {
|
|
162
|
+
await setEnvVar('POSTGRES_HOST_NAME', hostName);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const setPostgresIpType = async (): Promise<void> => {
|
|
167
|
+
const ipType = await askQuestion('Enter PostgreSQL IP Type (PUBLIC, PRIVATE)', 'PUBLIC');
|
|
168
|
+
if (ipType) {
|
|
169
|
+
await setEnvVar('POSTGRES_IP_TYPE', ipType);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const setPostgresPoolSizeMax = async (): Promise<void> => {
|
|
174
|
+
const poolSizeMax = await askQuestion('Enter Maximum Pool Size for PostgreSQL', '10');
|
|
175
|
+
if (poolSizeMax) {
|
|
176
|
+
await setEnvVar('POSTGRES_POOL_SIZE_MAX', poolSizeMax);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const setPostgresInstanceConnectionName = async (): Promise<void> => {
|
|
181
|
+
const instanceConnectionName = await askQuestion('Enter PostgreSQL Instance Connection Name (your-project:your-region:your-instance)', '');
|
|
182
|
+
if (instanceConnectionName) {
|
|
183
|
+
await setEnvVar('POSTGRES_INSTANCE_CONNECTION_NAME', instanceConnectionName);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const setBigtableInstanceName = async (): Promise<void> => {
|
|
188
|
+
const btInstanceName = await askQuestion('Enter Bigtable Instance Name', '');
|
|
189
|
+
if (btInstanceName) {
|
|
190
|
+
await setEnvVar('BIGTABLE_INSTANCE_NAME', btInstanceName);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const setBigtableTableName = async (): Promise<void> => {
|
|
195
|
+
const btTableName = await askQuestion('Enter Bigtable Table Name', '');
|
|
196
|
+
if (btTableName) {
|
|
197
|
+
await setEnvVar('BIGTABLE_TABLE_NAME', btTableName);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const setBigtableProjectId = async (): Promise<void> => {
|
|
202
|
+
const btProjectId = await askQuestion('Enter Bigtable Google Project', '');
|
|
203
|
+
if (btProjectId) {
|
|
204
|
+
await setEnvVar('BIGTABLE_PROJECT_ID', btProjectId);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const setJiraApiToken = async (): Promise<void> => {
|
|
209
|
+
const jiraApiToken = await askQuestion('Enter Jira API token', '');
|
|
210
|
+
if (jiraApiToken) {
|
|
211
|
+
await setEnvVar('JIRA_API_TOKEN', jiraApiToken);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const setJiraApiBaseUrl = async (): Promise<void> => {
|
|
216
|
+
const jiraApiBaseUrl = await askQuestion('Enter Jira API Base URL', '');
|
|
217
|
+
if (jiraApiBaseUrl) {
|
|
218
|
+
await setEnvVar('JIRA_API_BASE_URL', jiraApiBaseUrl);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const setJiraUserEmail = async (): Promise<void> => {
|
|
223
|
+
const jiraUserEmail = await askQuestion('Enter Jira user email', 'you@domain.com');
|
|
224
|
+
if (jiraUserEmail) {
|
|
225
|
+
await setEnvVar('JIRA_USER_EMAIL', jiraUserEmail);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const setGeminiApiKey = async (): Promise<void> => {
|
|
230
|
+
const apiKey = await askQuestion('Enter Gemini API key:');
|
|
231
|
+
if (apiKey) await setEnvVar('GEMINI_API_KEY', apiKey);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const setNpmToken = async (): Promise<void> => {
|
|
235
|
+
const npmToken = await askQuestion('Enter NPM Token:');
|
|
236
|
+
if (npmToken) await setEnvVar('NPM_TOKEN', npmToken);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const setCustomSearchApiKey = async (): Promise<void> => {
|
|
240
|
+
const customSearchApiKey = await askQuestion('Enter Custom Search API Key', '');
|
|
241
|
+
if (customSearchApiKey) {
|
|
242
|
+
await setEnvVar('CUSTOM_SEARCH_API_KEY', customSearchApiKey);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const setFirestoreProjectId = async (): Promise<void> => {
|
|
247
|
+
const firestoreProjectId = await askQuestion('Enter Firestore Project ID', 'dataformer-prod');
|
|
248
|
+
if (firestoreProjectId) {
|
|
249
|
+
await setEnvVar('FIRESTORE_PROJECT_ID', firestoreProjectId);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// --- Specific Getters (Now use generic getEnvVar) ---
|
|
254
|
+
const getLogToConsole = async (): Promise<string | null> => await getEnvVar('LOG_TO_CONSOLE');
|
|
255
|
+
const getPostgresUser = async (): Promise<string | null> => await getEnvVar('POSTGRES_USER');
|
|
256
|
+
const getPostgresPassword = async (): Promise<string | null> => await getEnvVar('POSTGRES_PASSWORD');
|
|
257
|
+
const getPostgresDatabase = async (): Promise<string | null> => await getEnvVar('POSTGRES_DATABASE');
|
|
258
|
+
const getPostgresHostName = async (): Promise<string | null> => await getEnvVar('POSTGRES_HOST_NAME');
|
|
259
|
+
const getPostgresIpType = async (): Promise<string | null> => await getEnvVar('POSTGRES_IP_TYPE');
|
|
260
|
+
const getPostgresPoolSizeMax = async (): Promise<number | null> => {
|
|
261
|
+
const value = await getEnvVar('POSTGRES_POOL_SIZE_MAX');
|
|
262
|
+
return value ? parseInt(value, 10) : null;
|
|
263
|
+
};
|
|
264
|
+
const getPostgresInstanceConnectionName = async (): Promise<string | null> => await getEnvVar('POSTGRES_INSTANCE_CONNECTION_NAME');
|
|
265
|
+
const getBigtableInstanceName = async (): Promise<string | null> => await getEnvVar('BIGTABLE_INSTANCE_NAME');
|
|
266
|
+
const getBigtableTableName = async (): Promise<string | null> => await getEnvVar('BIGTABLE_TABLE_NAME');
|
|
267
|
+
const getBigtableProjectId = async (): Promise<string | null> => await getEnvVar('BIGTABLE_PROJECT_ID');
|
|
268
|
+
const _getFirestoreProjectId = async (): Promise<string | null> => await getEnvVar('FIRESTORE_PROJECT_ID');
|
|
269
|
+
const getJiraApiToken = async (): Promise<string | null> => await getEnvVar('JIRA_API_TOKEN');
|
|
270
|
+
const getJiraApiBaseUrl = async (): Promise<string | null> => await getEnvVar('JIRA_API_BASE_URL');
|
|
271
|
+
const getJiraUserEmail = async (): Promise<string | null> => await getEnvVar('JIRA_USER_EMAIL');
|
|
272
|
+
const getGeminiApiKey = async (): Promise<string | null> => await getEnvVar('GEMINI_API_KEY');
|
|
273
|
+
const getNpmToken = async (): Promise<string | null> => await getEnvVar('NPM_TOKEN');
|
|
274
|
+
|
|
275
|
+
const getProjectRoot = (): string => {
|
|
276
|
+
// When compiled, this will be in dist/services/, so we need to go up two levels
|
|
277
|
+
// Use import.meta.url for ES modules instead of __dirname
|
|
278
|
+
const currentDir = path.dirname(new URL(import.meta.url).pathname);
|
|
279
|
+
return path.resolve(currentDir, '../..');
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const _getResolvedGcpProjectId = async (): Promise<string | null> => {
|
|
283
|
+
const sm = await getSecretManager();
|
|
284
|
+
if (!sm) {
|
|
285
|
+
console.warn('[EnvService.ts] SecretManager not available for _getResolvedGcpProjectId');
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
return sm.getResolvedProjectId();
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const _getResolvedGcpUserEmail = async (): Promise<string | null> => {
|
|
292
|
+
const sm = await getSecretManager();
|
|
293
|
+
if (!sm) {
|
|
294
|
+
console.warn('[EnvService.ts] SecretManager not available for _getResolvedGcpUserEmail');
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
return sm.getResolvedUserEmail();
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const getGcpProjectId = _getResolvedGcpProjectId;
|
|
301
|
+
const getGcpUserEmail = _getResolvedGcpUserEmail;
|
|
302
|
+
|
|
303
|
+
const printEnv = async (): Promise<void> => {
|
|
304
|
+
const logToConsole = await getLogToConsole();
|
|
305
|
+
const postgresUser = await getPostgresUser();
|
|
306
|
+
const postgresPassword = await getPostgresPassword();
|
|
307
|
+
const postgresDatabase = await getPostgresDatabase();
|
|
308
|
+
const postgresHostName = await getPostgresHostName();
|
|
309
|
+
const postgresIpType = await getPostgresIpType();
|
|
310
|
+
const postgresPoolSizeMax = await getPostgresPoolSizeMax();
|
|
311
|
+
const postgresInstanceConnectionName = await getPostgresInstanceConnectionName();
|
|
312
|
+
const bigtableInstanceName = await getBigtableInstanceName();
|
|
313
|
+
const bigtableTableName = await getBigtableTableName();
|
|
314
|
+
const bigtableProjectId = await getBigtableProjectId();
|
|
315
|
+
const firestoreProjectId = await _getFirestoreProjectId();
|
|
316
|
+
const jiraApiToken = await getJiraApiToken();
|
|
317
|
+
const jiraApiBaseUrl = await getJiraApiBaseUrl();
|
|
318
|
+
const jiraUserEmail = await getJiraUserEmail();
|
|
319
|
+
const geminiApiKey = await getGeminiApiKey();
|
|
320
|
+
const customSearchApiKey = await getCustomSearchApiKey();
|
|
321
|
+
const gcpProjectIdVal = await getGcpProjectId();
|
|
322
|
+
const gcpUserEmailVal = await getGcpUserEmail();
|
|
323
|
+
const npmToken = await getNpmToken();
|
|
324
|
+
|
|
325
|
+
console.log(`Project Root: ${getProjectRoot()}`);
|
|
326
|
+
console.log(`GCP Project ID: ${gcpProjectIdVal}`);
|
|
327
|
+
console.log(`GCP User Email (for Secret Manager naming): ${gcpUserEmailVal}`);
|
|
328
|
+
console.log(`Log to Console: ${logToConsole}`);
|
|
329
|
+
console.log(`PostgreSQL User: ${postgresUser}`);
|
|
330
|
+
console.log(`PostgreSQL Password: ${obfuscateCred(postgresPassword)}`);
|
|
331
|
+
console.log(`PostgreSQL Database: ${postgresDatabase}`);
|
|
332
|
+
console.log(`PostgreSQL Host Name: ${postgresHostName}`);
|
|
333
|
+
console.log(`PostgreSQL IP Type: ${postgresIpType}`);
|
|
334
|
+
console.log(`PostgreSQL Pool Size Max: ${postgresPoolSizeMax}`);
|
|
335
|
+
console.log(`PostgreSQL Instance Connection Name: ${postgresInstanceConnectionName}`);
|
|
336
|
+
console.log(`Bigtable Instance Name: ${bigtableInstanceName}`);
|
|
337
|
+
console.log(`Bigtable Table Name: ${bigtableTableName}`);
|
|
338
|
+
console.log(`Bigtable Project ID: ${bigtableProjectId}`);
|
|
339
|
+
console.log(`Firestore Project ID: ${firestoreProjectId}`);
|
|
340
|
+
console.log(`Jira API Token: ${obfuscateCred(jiraApiToken)}`);
|
|
341
|
+
console.log(`Jira API Base URL: ${jiraApiBaseUrl}`);
|
|
342
|
+
console.log(`Jira User Email: ${jiraUserEmail}`);
|
|
343
|
+
console.log(`Custom Search API Key: ${obfuscateCred(customSearchApiKey)}`);
|
|
344
|
+
console.log(`Gemini API Key: ${obfuscateCred(geminiApiKey)}`);
|
|
345
|
+
console.log(`NPM Token: ${obfuscateCred(npmToken)}`);
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const run = async (): Promise<void> => {
|
|
349
|
+
const command = process.argv[2];
|
|
350
|
+
switch (command) {
|
|
351
|
+
case 'setLogToConsole': await setLogToConsole(); break;
|
|
352
|
+
case 'setPostgresUser': await setPostgresUser(); break;
|
|
353
|
+
case 'setPostgresPassword': await setPostgresPassword(); break;
|
|
354
|
+
case 'setPostgresDatabase': await setPostgresDatabase(); break;
|
|
355
|
+
case 'setPostgresHostName': await setPostgresHostName(); break;
|
|
356
|
+
case 'setPostgresIpType': await setPostgresIpType(); break;
|
|
357
|
+
case 'setPostgresPoolSizeMax': await setPostgresPoolSizeMax(); break;
|
|
358
|
+
case 'setPostgresInstanceConnectionName': await setPostgresInstanceConnectionName(); break;
|
|
359
|
+
case 'setBigtableInstanceName': await setBigtableInstanceName(); break;
|
|
360
|
+
case 'setBigtableTableName': await setBigtableTableName(); break;
|
|
361
|
+
case 'setBigtableProjectId': await setBigtableProjectId(); break;
|
|
362
|
+
case 'setFirestoreProjectId': await setFirestoreProjectId(); break;
|
|
363
|
+
case 'setJiraApiToken': await setJiraApiToken(); break;
|
|
364
|
+
case 'setJiraApiBaseUrl': await setJiraApiBaseUrl(); break;
|
|
365
|
+
case 'setJiraUserEmail': await setJiraUserEmail(); break;
|
|
366
|
+
case 'setGeminiApiKey': await setGeminiApiKey(); break;
|
|
367
|
+
case 'setNpmToken': await setNpmToken(); break;
|
|
368
|
+
case 'setCustomSearchApiKey': await setCustomSearchApiKey(); break;
|
|
369
|
+
case 'printEnv': await printEnv(); break;
|
|
370
|
+
default: console.log('Unknown command. Available commands: setEnv, setBearerToken, ..., printEnv');
|
|
371
|
+
}
|
|
372
|
+
rl.close();
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// If run directly from command line (ES module check)
|
|
376
|
+
if (process.argv[1] === new URL(import.meta.url).pathname) {
|
|
377
|
+
run().catch((error: Error) => {
|
|
378
|
+
console.error('[EnvService.ts] An error occurred:', error);
|
|
379
|
+
rl.close();
|
|
380
|
+
process.exit(1);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Export all functions
|
|
385
|
+
export {
|
|
386
|
+
// CLI functions
|
|
387
|
+
run,
|
|
388
|
+
printEnv,
|
|
389
|
+
|
|
390
|
+
// Setters
|
|
391
|
+
setLogToConsole,
|
|
392
|
+
setPostgresUser,
|
|
393
|
+
setPostgresPassword,
|
|
394
|
+
setPostgresDatabase,
|
|
395
|
+
setPostgresHostName,
|
|
396
|
+
setPostgresIpType,
|
|
397
|
+
setPostgresPoolSizeMax,
|
|
398
|
+
setPostgresInstanceConnectionName,
|
|
399
|
+
setBigtableInstanceName,
|
|
400
|
+
setBigtableTableName,
|
|
401
|
+
setBigtableProjectId,
|
|
402
|
+
setFirestoreProjectId,
|
|
403
|
+
setJiraApiToken,
|
|
404
|
+
setJiraApiBaseUrl,
|
|
405
|
+
setJiraUserEmail,
|
|
406
|
+
setGeminiApiKey,
|
|
407
|
+
setNpmToken,
|
|
408
|
+
setCustomSearchApiKey,
|
|
409
|
+
|
|
410
|
+
// Getters
|
|
411
|
+
getLogToConsole,
|
|
412
|
+
getPostgresUser,
|
|
413
|
+
getPostgresPassword,
|
|
414
|
+
getPostgresDatabase,
|
|
415
|
+
getPostgresHostName,
|
|
416
|
+
getPostgresIpType,
|
|
417
|
+
getPostgresPoolSizeMax,
|
|
418
|
+
getPostgresInstanceConnectionName,
|
|
419
|
+
getBigtableInstanceName,
|
|
420
|
+
getBigtableTableName,
|
|
421
|
+
getBigtableProjectId,
|
|
422
|
+
getJiraApiToken,
|
|
423
|
+
getJiraApiBaseUrl,
|
|
424
|
+
getJiraUserEmail,
|
|
425
|
+
getGeminiApiKey,
|
|
426
|
+
getNpmToken,
|
|
427
|
+
|
|
428
|
+
// Synchronous Getters / Utility
|
|
429
|
+
getProjectRoot,
|
|
430
|
+
getGcpProjectId,
|
|
431
|
+
getGcpUserEmail,
|
|
432
|
+
|
|
433
|
+
// Generic accessors
|
|
434
|
+
getEnvVar,
|
|
435
|
+
setEnvVar,
|
|
436
|
+
|
|
437
|
+
// Utility functions
|
|
438
|
+
obfuscateCred,
|
|
439
|
+
askQuestion
|
|
440
|
+
};
|