private detectPostgresConnections()

in src/tree/CosmosDBTreeItem.ts [201:237]


    private detectPostgresConnections(appSettings: { [propertyName: string]: string }): IDetectedConnection[] {
        const portDefault = '5432';
        const result: IDetectedConnection[] = [];
        const regexp = new RegExp(`(.+)${this._pgHostSuffix}`, 'i');

        for (const key of Object.keys(appSettings)) {
            const match = key && key.match(regexp);
            if (match) {
                const prefix = match[1];
                const hostKey = prefix + this._pgHostSuffix;
                const dbNameKey = prefix + this._pgDbNameSuffix;
                const userKey = prefix + this._pgUserSuffix;
                const passKey = prefix + this._pgPassSuffix;
                const portKey = prefix + this._pgPortSuffix;

                if (appSettings[hostKey]) {
                    const keys: string[] = [hostKey, portKey];
                    for (const optionalKey of [userKey, passKey, dbNameKey]) {
                        if (appSettings[optionalKey]) {
                            keys.push(optionalKey);
                        }
                    }
                    result.push({
                        keys, postgresData:
                        {
                            hostName: appSettings[hostKey],
                            port: appSettings[portKey] ? appSettings[portKey] : portDefault,
                            username: appSettings[userKey],
                            password: appSettings[passKey],
                            databaseName: appSettings[dbNameKey]
                        }
                    });
                }
            }
        }
        return result;
    }