forked from vapor/postgres-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgreSQLTransportConfig.swift
58 lines (47 loc) · 2.06 KB
/
PostgreSQLTransportConfig.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Foundation
import NIOOpenSSL
public struct PostgreSQLTransportConfig {
/// Does not attempt to enable TLS (this is the default).
public static var cleartext: PostgreSQLTransportConfig {
return .init(method: .cleartext)
}
/// Enables TLS requiring a minimum version of TLS v1.1 on the server, but disables certificate verification.
/// This is what you would commonly use for paid Heroku PostgreSQL plans.
public static var unverifiedTLS: PostgreSQLTransportConfig {
return .init(method: .tls(.forClient(certificateVerification: .none)))
}
/// Enables TLS requiring a minimum version of TLS v1.1 on the server.
public static var standardTLS: PostgreSQLTransportConfig {
return .init(method: .tls(.forClient()))
}
/// Enables TLS requiring a minimum version of TLS v1.2 on the server.
public static var modernTLS: PostgreSQLTransportConfig {
return .init(method: .tls(.forClient(minimumTLSVersion: .tlsv12)))
}
/// Enables TLS requiring a minimum version of TLS v1.3 on the server.
/// TLS v1.3 specification is still a draft and unlikely to be supported by most servers.
/// See https://tools.ietf.org/html/draft-ietf-tls-tls13-28 for more info.
public static var edgeTLS: PostgreSQLTransportConfig {
return .init(method: .tls(.forClient(minimumTLSVersion: .tlsv13)))
}
/// Enables TLS using the given `TLSConfiguration`.
/// - parameter tlsConfiguration: See `TLSConfiguration` for more info.
public static func customTLS(_ tlsConfiguration: TLSConfiguration)-> PostgreSQLTransportConfig {
return .init(method: .tls(tlsConfiguration))
}
/// Returns `true` if this configuration uses TLS.
public var isTLS: Bool {
switch method {
case .cleartext: return false
case .tls: return true
}
}
internal enum Method {
case cleartext
case tls(TLSConfiguration)
}
internal let method: Method
internal init(method: Method) {
self.method = method
}
}