Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSLMode is not configurable. #94

Open
geertberkers opened this issue Nov 14, 2019 · 1 comment
Open

SSLMode is not configurable. #94

geertberkers opened this issue Nov 14, 2019 · 1 comment

Comments

@geertberkers
Copy link

Azure requires me to enable SSLMode.

SSLMode can have 4 values: disable, allow, prefer or require.

This is currently not settable in ConnectionOptions but required to connect to an Azure PostgreSQL Database.

Connection documentation
https://www.postgresql.org/docs/8.0/libpq.html#LIBPQ-CONNECT

This could be resolved by adding something like:

PostgreSQLConnection.swift:

private static func extractConnectionParameters(host: String, port: Int32, options: [ConnectionOptions]?) -> String {
    var result = "host = \(host) port = \(port)"
    if let options = options {
        for option in options {
            switch option {
            case .sslmode(let value):
                result += " sslmode = \(value)"
            case .options(let value):
                result += " options = \(value)"
            case .databaseName(let value):
                result += " dbname = \(value)"
            case .userName(let value):
                result += " user = \(value)"
            case .password(let value):
                result += " password = \(value)"
            case .connectionTimeout(let value):
                result += " connect_timeout = \(value)"
            }
        }
    }
    return result
}

And adding options in ConnectionOptions.swift:

/**
 Copyright IBM Corporation 2016
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

// MARK: ConnectionOptions

/// Configuration options to be passed to PostgreSQL server.
public enum ConnectionOptions {
    /// The command-line options to be sent to the server.
    case options(String)
    /// The database name.
    case databaseName(String)
    /// The user name.
    case userName(String)
    /// The user password.
    case password(String)
    /// The maximum wait for connection in seconds. Zero or not specified means wait indefinitely.
    case connectionTimeout(Int)
    /// SSL Mode
    case sslmode(SSLMode)
}

public enum SSLMode {
    /// Will attempt only an unencrypted SSL connection
    case disable
    /// Will negotiate, trying first a non-SSL connection, then if that fails, trying an SSL connection
    case allow
    /// Will negotiate, trying first an SSL connection, then if that fails, trying a regular non-SSL connection
    case prefer
    /// Will try only an SSL connection
    case require
}

I also forked this project and made my own implementation, but the one from master is failing due dependencies.

@mbarnach
Copy link
Member

Hi @geertberkers

Thanks for the report (that stay unnoticed for too long... sorry about that!).
Are you able to make a PR for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants