@blogic-cz/agent-tools 0.4.1 → 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 +23 -6
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
|
{
|
|
@@ -506,19 +521,21 @@ export class DbService extends ServiceMap.Service<
|
|
|
506
521
|
throw new Error(`Unknown environment "${env}". Available: ${available}`);
|
|
507
522
|
}
|
|
508
523
|
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
|
|
524
|
+
const accessMode = resolveDbAccessMode(
|
|
525
|
+
env,
|
|
526
|
+
envConfig.host,
|
|
527
|
+
dbConfig.kubectl !== undefined,
|
|
528
|
+
);
|
|
512
529
|
|
|
513
530
|
return {
|
|
514
|
-
host:
|
|
531
|
+
host: accessMode.host,
|
|
515
532
|
user: envConfig.user,
|
|
516
533
|
database: envConfig.database,
|
|
517
534
|
password: envConfig.password,
|
|
518
535
|
passwordEnvVar: envConfig.passwordEnvVar,
|
|
519
536
|
port: envConfig.port,
|
|
520
|
-
needsTunnel,
|
|
521
|
-
allowMutations:
|
|
537
|
+
needsTunnel: accessMode.needsTunnel,
|
|
538
|
+
allowMutations: accessMode.allowMutations,
|
|
522
539
|
};
|
|
523
540
|
};
|
|
524
541
|
|