@optima-chat/dev-skills 0.7.9 → 0.7.10
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/helpers/query-db.ts +26 -4
- package/dist/bin/helpers/query-db.js +22 -4
- package/package.json +1 -1
package/bin/helpers/query-db.ts
CHANGED
|
@@ -214,20 +214,42 @@ async function main() {
|
|
|
214
214
|
{ encoding: 'utf-8' }
|
|
215
215
|
);
|
|
216
216
|
|
|
217
|
+
console.log('\n' + result);
|
|
218
|
+
} else if (environment === 'stage') {
|
|
219
|
+
// Stage 环境:直连 RDS(Stage RDS 在公有子网,可以本地直连)
|
|
220
|
+
const infisicalConfig = getInfisicalConfig();
|
|
221
|
+
console.log('✓ Loaded Infisical config from GitHub Variables');
|
|
222
|
+
|
|
223
|
+
const token = getInfisicalToken(infisicalConfig);
|
|
224
|
+
console.log('✓ Obtained Infisical access token');
|
|
225
|
+
|
|
226
|
+
const secrets = getInfisicalSecrets(infisicalConfig, token, 'staging');
|
|
227
|
+
console.log('✓ Retrieved database credentials from Infisical');
|
|
228
|
+
|
|
229
|
+
const { userKey, passwordKey, database } = serviceConfig as any;
|
|
230
|
+
const dbHost = RDS_HOSTS.stage;
|
|
231
|
+
const dbUser = secrets[userKey];
|
|
232
|
+
const dbPassword = secrets[passwordKey];
|
|
233
|
+
|
|
234
|
+
if (!dbUser || !dbPassword) {
|
|
235
|
+
throw new Error(`Database credentials not found in Infisical for ${service}. Keys: ${userKey}, ${passwordKey}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const result = queryDatabase(dbHost, 5432, dbUser, dbPassword, database, sql);
|
|
217
239
|
console.log('\n' + result);
|
|
218
240
|
} else {
|
|
219
|
-
//
|
|
241
|
+
// Prod 环境:通过 SSH 隧道访问 RDS(Prod RDS 在私有子网)
|
|
220
242
|
const infisicalConfig = getInfisicalConfig();
|
|
221
243
|
console.log('✓ Loaded Infisical config from GitHub Variables');
|
|
222
244
|
|
|
223
245
|
const token = getInfisicalToken(infisicalConfig);
|
|
224
246
|
console.log('✓ Obtained Infisical access token');
|
|
225
247
|
|
|
226
|
-
const secrets = getInfisicalSecrets(infisicalConfig, token,
|
|
248
|
+
const secrets = getInfisicalSecrets(infisicalConfig, token, 'prod');
|
|
227
249
|
console.log('✓ Retrieved database credentials from Infisical');
|
|
228
250
|
|
|
229
251
|
const { userKey, passwordKey, database } = serviceConfig as any;
|
|
230
|
-
const dbHost = RDS_HOSTS
|
|
252
|
+
const dbHost = RDS_HOSTS.prod;
|
|
231
253
|
const dbUser = secrets[userKey];
|
|
232
254
|
const dbPassword = secrets[passwordKey];
|
|
233
255
|
|
|
@@ -235,7 +257,7 @@ async function main() {
|
|
|
235
257
|
throw new Error(`Database credentials not found in Infisical for ${service}. Keys: ${userKey}, ${passwordKey}`);
|
|
236
258
|
}
|
|
237
259
|
|
|
238
|
-
const localPort =
|
|
260
|
+
const localPort = 15433;
|
|
239
261
|
|
|
240
262
|
setupSSHTunnel(EC2_HOST, dbHost, localPort);
|
|
241
263
|
|
|
@@ -195,22 +195,40 @@ async function main() {
|
|
|
195
195
|
const result = (0, child_process_1.execSync)(`sshpass -p "${ciPassword}" ssh -o StrictHostKeyChecking=no ${ciUser}@${ciHost} "docker exec ${container} psql -U ${user} -d ${database} -c \\"${sql}\\""`, { encoding: 'utf-8' });
|
|
196
196
|
console.log('\n' + result);
|
|
197
197
|
}
|
|
198
|
+
else if (environment === 'stage') {
|
|
199
|
+
// Stage 环境:直连 RDS(Stage RDS 在公有子网,可以本地直连)
|
|
200
|
+
const infisicalConfig = getInfisicalConfig();
|
|
201
|
+
console.log('✓ Loaded Infisical config from GitHub Variables');
|
|
202
|
+
const token = getInfisicalToken(infisicalConfig);
|
|
203
|
+
console.log('✓ Obtained Infisical access token');
|
|
204
|
+
const secrets = getInfisicalSecrets(infisicalConfig, token, 'staging');
|
|
205
|
+
console.log('✓ Retrieved database credentials from Infisical');
|
|
206
|
+
const { userKey, passwordKey, database } = serviceConfig;
|
|
207
|
+
const dbHost = RDS_HOSTS.stage;
|
|
208
|
+
const dbUser = secrets[userKey];
|
|
209
|
+
const dbPassword = secrets[passwordKey];
|
|
210
|
+
if (!dbUser || !dbPassword) {
|
|
211
|
+
throw new Error(`Database credentials not found in Infisical for ${service}. Keys: ${userKey}, ${passwordKey}`);
|
|
212
|
+
}
|
|
213
|
+
const result = queryDatabase(dbHost, 5432, dbUser, dbPassword, database, sql);
|
|
214
|
+
console.log('\n' + result);
|
|
215
|
+
}
|
|
198
216
|
else {
|
|
199
|
-
//
|
|
217
|
+
// Prod 环境:通过 SSH 隧道访问 RDS(Prod RDS 在私有子网)
|
|
200
218
|
const infisicalConfig = getInfisicalConfig();
|
|
201
219
|
console.log('✓ Loaded Infisical config from GitHub Variables');
|
|
202
220
|
const token = getInfisicalToken(infisicalConfig);
|
|
203
221
|
console.log('✓ Obtained Infisical access token');
|
|
204
|
-
const secrets = getInfisicalSecrets(infisicalConfig, token,
|
|
222
|
+
const secrets = getInfisicalSecrets(infisicalConfig, token, 'prod');
|
|
205
223
|
console.log('✓ Retrieved database credentials from Infisical');
|
|
206
224
|
const { userKey, passwordKey, database } = serviceConfig;
|
|
207
|
-
const dbHost = RDS_HOSTS
|
|
225
|
+
const dbHost = RDS_HOSTS.prod;
|
|
208
226
|
const dbUser = secrets[userKey];
|
|
209
227
|
const dbPassword = secrets[passwordKey];
|
|
210
228
|
if (!dbUser || !dbPassword) {
|
|
211
229
|
throw new Error(`Database credentials not found in Infisical for ${service}. Keys: ${userKey}, ${passwordKey}`);
|
|
212
230
|
}
|
|
213
|
-
const localPort =
|
|
231
|
+
const localPort = 15433;
|
|
214
232
|
setupSSHTunnel(EC2_HOST, dbHost, localPort);
|
|
215
233
|
// 等待隧道建立
|
|
216
234
|
await new Promise(resolve => setTimeout(resolve, 1000));
|