@optima-chat/dev-skills 0.7.11 → 0.7.12
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
CHANGED
|
@@ -40,7 +40,7 @@ const SERVICE_DB_MAP = {
|
|
|
40
40
|
},
|
|
41
41
|
'session-gateway': {
|
|
42
42
|
ci: null, // CI 环境暂无 session-gateway 数据库
|
|
43
|
-
stage: { userKey: '
|
|
43
|
+
stage: { userKey: 'AI_SHELL_DB_USER', passwordKey: 'AI_SHELL_DB_PASSWORD', database: 'optima_shell' },
|
|
44
44
|
prod: { userKey: 'AI_SHELL_DB_USER', passwordKey: 'AI_SHELL_DB_PASSWORD', database: 'optima_ai_shell' }
|
|
45
45
|
}
|
|
46
46
|
};
|
|
@@ -75,14 +75,14 @@ function getInfisicalToken(config: InfisicalConfig): string {
|
|
|
75
75
|
return JSON.parse(response).accessToken;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
function getInfisicalSecrets(config: InfisicalConfig, token: string, environment: string): Record<string, string> {
|
|
78
|
+
function getInfisicalSecrets(config: InfisicalConfig, token: string, environment: string, secretPath: string): Record<string, string> {
|
|
79
79
|
const response = execSync(
|
|
80
|
-
`curl -s "${config.url}/api/v3/secrets/raw?workspaceId=${config.projectId}&environment=${environment}&secretPath
|
|
80
|
+
`curl -s "${config.url}/api/v3/secrets/raw?workspaceId=${config.projectId}&environment=${environment}&secretPath=${secretPath}" -H "Authorization: Bearer ${token}"`,
|
|
81
81
|
{ encoding: 'utf-8' }
|
|
82
82
|
);
|
|
83
83
|
const data = JSON.parse(response);
|
|
84
84
|
const secrets: Record<string, string> = {};
|
|
85
|
-
for (const secret of data.secrets) {
|
|
85
|
+
for (const secret of data.secrets || []) {
|
|
86
86
|
secrets[secret.secretKey] = secret.secretValue;
|
|
87
87
|
}
|
|
88
88
|
return secrets;
|
|
@@ -223,8 +223,10 @@ async function main() {
|
|
|
223
223
|
const token = getInfisicalToken(infisicalConfig);
|
|
224
224
|
console.log('✓ Obtained Infisical access token');
|
|
225
225
|
|
|
226
|
-
//
|
|
227
|
-
|
|
226
|
+
// 数据库凭证存储在 Infisical 的 /shared-secrets/database-users 路径
|
|
227
|
+
// Stage 从 staging 环境读取,Prod 从 prod 环境读取
|
|
228
|
+
const infisicalEnv = environment === 'stage' ? 'staging' : 'prod';
|
|
229
|
+
const secrets = getInfisicalSecrets(infisicalConfig, token, infisicalEnv, '/shared-secrets/database-users');
|
|
228
230
|
console.log('✓ Retrieved database credentials from Infisical');
|
|
229
231
|
|
|
230
232
|
const { userKey, passwordKey, database } = serviceConfig as any;
|
|
@@ -59,7 +59,7 @@ const SERVICE_DB_MAP = {
|
|
|
59
59
|
},
|
|
60
60
|
'session-gateway': {
|
|
61
61
|
ci: null, // CI 环境暂无 session-gateway 数据库
|
|
62
|
-
stage: { userKey: '
|
|
62
|
+
stage: { userKey: 'AI_SHELL_DB_USER', passwordKey: 'AI_SHELL_DB_PASSWORD', database: 'optima_shell' },
|
|
63
63
|
prod: { userKey: 'AI_SHELL_DB_USER', passwordKey: 'AI_SHELL_DB_PASSWORD', database: 'optima_ai_shell' }
|
|
64
64
|
}
|
|
65
65
|
};
|
|
@@ -85,11 +85,11 @@ function getInfisicalToken(config) {
|
|
|
85
85
|
const response = (0, child_process_1.execSync)(`curl -s -X POST "${config.url}/api/v1/auth/universal-auth/login" -H "Content-Type: application/json" -d '{"clientId": "${config.clientId}", "clientSecret": "${config.clientSecret}"}'`, { encoding: 'utf-8' });
|
|
86
86
|
return JSON.parse(response).accessToken;
|
|
87
87
|
}
|
|
88
|
-
function getInfisicalSecrets(config, token, environment) {
|
|
89
|
-
const response = (0, child_process_1.execSync)(`curl -s "${config.url}/api/v3/secrets/raw?workspaceId=${config.projectId}&environment=${environment}&secretPath
|
|
88
|
+
function getInfisicalSecrets(config, token, environment, secretPath) {
|
|
89
|
+
const response = (0, child_process_1.execSync)(`curl -s "${config.url}/api/v3/secrets/raw?workspaceId=${config.projectId}&environment=${environment}&secretPath=${secretPath}" -H "Authorization: Bearer ${token}"`, { encoding: 'utf-8' });
|
|
90
90
|
const data = JSON.parse(response);
|
|
91
91
|
const secrets = {};
|
|
92
|
-
for (const secret of data.secrets) {
|
|
92
|
+
for (const secret of data.secrets || []) {
|
|
93
93
|
secrets[secret.secretKey] = secret.secretValue;
|
|
94
94
|
}
|
|
95
95
|
return secrets;
|
|
@@ -201,8 +201,10 @@ async function main() {
|
|
|
201
201
|
console.log('✓ Loaded Infisical config from GitHub Variables');
|
|
202
202
|
const token = getInfisicalToken(infisicalConfig);
|
|
203
203
|
console.log('✓ Obtained Infisical access token');
|
|
204
|
-
//
|
|
205
|
-
|
|
204
|
+
// 数据库凭证存储在 Infisical 的 /shared-secrets/database-users 路径
|
|
205
|
+
// Stage 从 staging 环境读取,Prod 从 prod 环境读取
|
|
206
|
+
const infisicalEnv = environment === 'stage' ? 'staging' : 'prod';
|
|
207
|
+
const secrets = getInfisicalSecrets(infisicalConfig, token, infisicalEnv, '/shared-secrets/database-users');
|
|
206
208
|
console.log('✓ Retrieved database credentials from Infisical');
|
|
207
209
|
const { userKey, passwordKey, database } = serviceConfig;
|
|
208
210
|
const dbHost = RDS_HOSTS[environment];
|