Skip to content

Commit

Permalink
Add PostgresConfiguration.ianaPortNumber with appropriate value. Us…
Browse files Browse the repository at this point in the history
…e the property in place of the hardcoded value. (#201)
  • Loading branch information
gwynne authored Nov 3, 2020
1 parent bb1493e commit 13f6c73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Sources/PostgresKit/PostgresConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ public struct PostgresConfiguration {
/// Optional `search_path` to set on new connections.
public var searchPath: [String]?

internal var _hostname: String?
/// IANA-assigned port number for PostgreSQL
/// `UInt16(getservbyname("postgresql", "tcp").pointee.s_port).byteSwapped`
public static var ianaPortNumber: Int { 5432 }

internal var _hostname: String?

public init?(url: String) {
guard let url = URL(string: url) else {
Expand All @@ -31,7 +34,7 @@ public struct PostgresConfiguration {
guard let hostname = url.host else {
return nil
}
let port = url.port ?? 5432
let port = url.port ?? Self.ianaPortNumber

let tlsConfiguration: TLSConfiguration?
if url.query?.contains("ssl=true") == true || url.query?.contains("sslmode=require") == true {
Expand Down Expand Up @@ -68,7 +71,7 @@ public struct PostgresConfiguration {

public init(
hostname: String,
port: Int = 5432,
port: Int = Self.ianaPortNumber,
username: String,
password: String? = nil,
database: String? = nil,
Expand Down
4 changes: 2 additions & 2 deletions Tests/PostgresKitTests/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extension PostgresConnection {
static func test(on eventLoop: EventLoop) -> EventLoopFuture<PostgresConnection> {
do {
let address: SocketAddress
address = try .makeAddressResolvingHost(hostname, port: 5432)
address = try .makeAddressResolvingHost(hostname, port: PostgresConfiguration.ianaPortNumber)
return connect(to: address, on: eventLoop).flatMap { conn in
return conn.authenticate(
username: "vapor_username",
Expand All @@ -22,7 +22,7 @@ extension PostgresConfiguration {
static var test: Self {
.init(
hostname: hostname,
port: 5432,
port: Self.ianaPortNumber,
username: "vapor_username",
password: "vapor_password",
database: "vapor_database"
Expand Down

0 comments on commit 13f6c73

Please sign in to comment.