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

Function processSourceConfigs

src/config/toml-loader.ts:646–713  ·  view source on GitHub ↗

* Process source configurations (expand paths, populate fields from DSN)

(
  sources: SourceConfig[],
  configPath: string
)

Source from the content-addressed store, hash-verified

644 * Process source configurations (expand paths, populate fields from DSN)
645 */
646function processSourceConfigs(
647 sources: SourceConfig[],
648 configPath: string
649): SourceConfig[] {
650 return sources.map((source) => {
651 const processed = { ...source };
652
653 // Expand ~ in SSH key path
654 if (processed.ssh_key) {
655 processed.ssh_key = expandHomeDir(processed.ssh_key);
656 }
657
658 // Expand ~ in sslrootcert path
659 if (processed.sslrootcert) {
660 processed.sslrootcert = expandHomeDir(processed.sslrootcert);
661 }
662
663 // Expand ~ in SQLite database path (if relative)
664 if (processed.type === "sqlite" && processed.database) {
665 processed.database = expandHomeDir(processed.database);
666 }
667
668 // Expand ~ in DSN for SQLite
669 if (processed.dsn && processed.dsn.startsWith("sqlite:///~")) {
670 processed.dsn = `sqlite:///${expandHomeDir(processed.dsn.substring(11))}`;
671 }
672
673 // Parse DSN to populate connection info fields (if not already set)
674 // This ensures API responses include host/port/database/user even when DSN is used
675 if (processed.dsn) {
676 const connectionInfo = parseConnectionInfoFromDSN(processed.dsn);
677 if (connectionInfo) {
678 // Only set fields that aren't already explicitly configured
679 if (!processed.type && connectionInfo.type) {
680 processed.type = connectionInfo.type;
681 }
682 if (!processed.host && connectionInfo.host) {
683 processed.host = connectionInfo.host;
684 }
685 if (processed.port === undefined && connectionInfo.port !== undefined) {
686 processed.port = connectionInfo.port;
687 }
688 if (!processed.database && connectionInfo.database) {
689 processed.database = connectionInfo.database;
690 }
691 if (!processed.user && connectionInfo.user) {
692 processed.user = connectionInfo.user;
693 }
694 }
695
696 try {
697 const url = new SafeURL(processed.dsn);
698 const dsnSslmode = url.getSearchParam("sslmode");
699 if (!processed.sslmode && dsnSslmode) {
700 processed.sslmode = dsnSslmode as SourceConfig["sslmode"];
701 }
702 const dsnSslrootcert = url.getSearchParam("sslrootcert");
703 if (!processed.sslrootcert && dsnSslrootcert) {

Callers 1

loadTomlConfigFunction · 0.85

Calls 3

getSearchParamMethod · 0.95
expandHomeDirFunction · 0.85

Tested by

no test coverage detected