@blogic-cz/agent-tools 0.4.0 → 0.4.2
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/package.json +1 -1
- package/src/db-tool/service.ts +28 -6
- package/src/db-tool/types.ts +1 -0
package/package.json
CHANGED
package/src/db-tool/service.ts
CHANGED
|
@@ -17,6 +17,21 @@ import { detectSchemaError, isValidTableName, isMutationQuery } from "./security
|
|
|
17
17
|
|
|
18
18
|
const LOCALHOST_HOSTS = new Set(["localhost", "127.0.0.1"]);
|
|
19
19
|
|
|
20
|
+
export function resolveDbAccessMode(
|
|
21
|
+
env: string,
|
|
22
|
+
host: string,
|
|
23
|
+
hasKubectlConfig: boolean,
|
|
24
|
+
): Pick<DbConfig, "allowMutations" | "host" | "needsTunnel"> {
|
|
25
|
+
const isLocalHost = LOCALHOST_HOSTS.has(host);
|
|
26
|
+
const isLocalEnvironment = env === "local";
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
host,
|
|
30
|
+
needsTunnel: hasKubectlConfig && !isLocalEnvironment && isLocalHost,
|
|
31
|
+
allowMutations: isLocalEnvironment,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
export class DbService extends ServiceMap.Service<
|
|
21
36
|
DbService,
|
|
22
37
|
{
|
|
@@ -79,10 +94,11 @@ export class DbService extends ServiceMap.Service<
|
|
|
79
94
|
|
|
80
95
|
const envVars: Record<string, string> = {};
|
|
81
96
|
const regex = /^export\s+([A-Z_][A-Z0-9_]*)=["']?([^"'\n]+)["']?/gm;
|
|
82
|
-
let match
|
|
97
|
+
let match = regex.exec(content);
|
|
83
98
|
|
|
84
|
-
while (
|
|
99
|
+
while (match !== null) {
|
|
85
100
|
envVars[match[1]] = match[2];
|
|
101
|
+
match = regex.exec(content);
|
|
86
102
|
}
|
|
87
103
|
|
|
88
104
|
yield* Ref.set(zshrcEnvCache, envVars);
|
|
@@ -214,7 +230,7 @@ export class DbService extends ServiceMap.Service<
|
|
|
214
230
|
) => {
|
|
215
231
|
const args = [
|
|
216
232
|
"-h",
|
|
217
|
-
|
|
233
|
+
config.host,
|
|
218
234
|
"-p",
|
|
219
235
|
String(config.port),
|
|
220
236
|
"-U",
|
|
@@ -505,15 +521,21 @@ export class DbService extends ServiceMap.Service<
|
|
|
505
521
|
throw new Error(`Unknown environment "${env}". Available: ${available}`);
|
|
506
522
|
}
|
|
507
523
|
|
|
508
|
-
const
|
|
524
|
+
const accessMode = resolveDbAccessMode(
|
|
525
|
+
env,
|
|
526
|
+
envConfig.host,
|
|
527
|
+
dbConfig.kubectl !== undefined,
|
|
528
|
+
);
|
|
509
529
|
|
|
510
530
|
return {
|
|
531
|
+
host: accessMode.host,
|
|
511
532
|
user: envConfig.user,
|
|
512
533
|
database: envConfig.database,
|
|
534
|
+
password: envConfig.password,
|
|
513
535
|
passwordEnvVar: envConfig.passwordEnvVar,
|
|
514
536
|
port: envConfig.port,
|
|
515
|
-
needsTunnel:
|
|
516
|
-
allowMutations:
|
|
537
|
+
needsTunnel: accessMode.needsTunnel,
|
|
538
|
+
allowMutations: accessMode.allowMutations,
|
|
517
539
|
};
|
|
518
540
|
};
|
|
519
541
|
|