MCPcopy Create free account
hub / github.com/bytebase/dbhub / transformSourceConfig

Function transformSourceConfig

src/api/sources.ts:16–74  ·  view source on GitHub ↗

* Transform a SourceConfig into an API DataSource response * Excludes sensitive fields like passwords and SSH credentials

(source: SourceConfig)

Source from the content-addressed store, hash-verified

14 * Excludes sensitive fields like passwords and SSH credentials
15 */
16function transformSourceConfig(source: SourceConfig): DataSource {
17 // Determine type from explicit config or infer from DSN
18 if (!source.type && source.dsn) {
19 const inferredType = getDatabaseTypeFromDSN(source.dsn);
20 if (inferredType) {
21 source.type = inferredType;
22 }
23 }
24
25 if (!source.type) {
26 throw new Error(`Source ${source.id} is missing required type field`);
27 }
28
29 const dataSource: DataSource = {
30 id: source.id,
31 type: source.type,
32 };
33
34 // Add description if present
35 if (source.description) {
36 dataSource.description = source.description;
37 }
38
39 // Add connection details (excluding password)
40 if (source.host) {
41 dataSource.host = source.host;
42 }
43 if (source.port !== undefined) {
44 dataSource.port = source.port;
45 }
46 if (source.database) {
47 dataSource.database = source.database;
48 }
49 if (source.user) {
50 dataSource.user = source.user;
51 }
52
53 // Add SSH tunnel configuration (excluding credentials)
54 if (source.ssh_host) {
55 const sshTunnel: SSHTunnel = {
56 enabled: true,
57 ssh_host: source.ssh_host,
58 };
59
60 if (source.ssh_port !== undefined) {
61 sshTunnel.ssh_port = source.ssh_port;
62 }
63 if (source.ssh_user) {
64 sshTunnel.ssh_user = source.ssh_user;
65 }
66
67 dataSource.ssh_tunnel = sshTunnel;
68 }
69
70 // Add tools for this source
71 dataSource.tools = getToolsForSource(source.id);
72
73 return dataSource;

Callers 2

listSourcesFunction · 0.85
getSourceFunction · 0.85

Calls 2

getDatabaseTypeFromDSNFunction · 0.85
getToolsForSourceFunction · 0.85

Tested by

no test coverage detected