export function fixupConnectionCredentials()

in src/models/connectionInfo.ts [17:103]


export function fixupConnectionCredentials(connCreds: Interfaces.IConnectionCredentials): Interfaces.IConnectionCredentials {
    if (!connCreds.host) {
        connCreds.host = '';
    }

    if (!connCreds.dbname) {
        connCreds.dbname = '';
    }

    if (!connCreds.user) {
        connCreds.user = '';
    }

    if (!connCreds.password) {
        connCreds.password = '';
    }

    if (!connCreds.connectTimeout) {
        connCreds.connectTimeout = Constants.defaultConnectionTimeout;
    }

    // default value for encrypt
    if (!connCreds.encrypt) {
        connCreds.encrypt = false;
    }

    // default value for appName
    if (!connCreds.applicationName) {
        connCreds.applicationName = Constants.connectionApplicationName;
    }

    if (isAzureDatabase(connCreds.host)) {
        // always encrypt connection if connecting to Azure SQL
        connCreds.encrypt = true;

        // Ensure minumum connection timeout if connecting to Azure SQL
        if (connCreds.connectTimeout < Constants.azureSqlDbConnectionTimeout) {
            connCreds.connectTimeout = Constants.azureSqlDbConnectionTimeout;
        }
    }

    if (!connCreds.hostaddr) {
        connCreds.hostaddr = '';
    }

    if (!connCreds.options) {
        connCreds.options = '';
    }

    if (!connCreds.sslmode) {
        connCreds.sslmode = 'prefer';
    }

    if (!connCreds.clientEncoding) {
        connCreds.clientEncoding = '';
    }

    if (!connCreds.sslcompression) {
        connCreds.sslcompression = true;
    }

    if (!connCreds.sslcert) {
        connCreds.sslcert = '';
    }

    if (!connCreds.sslkey) {
        connCreds.sslkey = '';
    }

    if (!connCreds.sslrootcert) {
        connCreds.sslrootcert = '';
    }

    if (!connCreds.sslcrl) {
        connCreds.sslcrl = '';
    }

    if (!connCreds.requirepeer) {
        connCreds.requirepeer = '';
    }

    if (!connCreds.service) {
        connCreds.service = undefined;
    }

    return connCreds;
}