Skip to content

Commit

Permalink
Allow backendKeyData to be set (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
rausnitz authored Jun 7, 2022
1 parent fdb1820 commit 10797f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
.library(name: "PostgresKit", targets: ["PostgresKit"]),
],
dependencies: [
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.9.0"),
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.11.0"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.16.0"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.0.0"),
],
Expand Down
6 changes: 6 additions & 0 deletions Sources/PostgresKit/PostgresConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ public struct PostgresConfiguration {
public var database: String?
public var tlsConfiguration: TLSConfiguration?

/// Require connection to provide `BackendKeyData`.
/// For use with Amazon RDS Proxy, this must be set to false.
///
/// - Default: true
public var requireBackendKeyData: Bool = true

/// Optional `search_path` to set on new connections.
public var searchPath: [String]?

Expand Down
7 changes: 6 additions & 1 deletion Sources/PostgresKit/PostgresConnectionSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ public struct PostgresConnectionSource: ConnectionPoolSource {
case let .success(sslContext): tlsMode = sslContext.map { .require($0) } ?? .disable
case let .failure(error): return eventLoop.makeFailedFuture(error)
}

var connection: PostgresConnection.Configuration.Connection
connection = .init(host: hostname, port: self.configuration._port ?? PostgresConfiguration.ianaPortNumber)
connection.requireBackendKeyData = configuration.requireBackendKeyData

let future = PostgresConnection.connect(
on: eventLoop,
configuration: .init(
connection: .init(host: hostname, port: self.configuration._port ?? PostgresConfiguration.ianaPortNumber),
connection: connection,
authentication: .init(username: self.configuration.username, database: self.configuration.database, password: self.configuration.password),
tls: tlsMode
),
Expand Down

0 comments on commit 10797f4

Please sign in to comment.