Skip to content

Commit

Permalink
Merge pull request #68 from johnbona/feature/ssl
Browse files Browse the repository at this point in the history
Implement support for SSL connections
  • Loading branch information
tanner0101 authored Dec 6, 2017
2 parents 525df89 + dbdcf11 commit 42cb0a0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ let package = Package(
.Package(url: "https://github.com/vapor/sockets.git", majorVersion: 2),

// Module for generating random bytes and numbers (for tests).
.Package(url: "https://github.com/vapor/random.git", majorVersion: 1)
.Package(url: "https://github.com/vapor/random.git", majorVersion: 1),

// Secure sockets
.Package(url: "https://github.com/vapor/tls.git", majorVersion: 2)
]
)
7 changes: 5 additions & 2 deletions Package@swift-4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ let package = Package(
.package(url: "https://github.com/vapor/sockets.git", from: "2.1.0"),

// Module for generating random bytes and numbers (for tests).
.package(url: "https://github.com/vapor/random.git", from: "1.2.0")
.package(url: "https://github.com/vapor/random.git", from: "1.2.0"),

// Secure sockets
.package(url: "https://github.com/vapor/tls.git", from: "2.1.0")
],
targets: [
.target(name: "Redis", dependencies: ["Core", "Node", "Sockets", "Random"]),
.target(name: "Redis", dependencies: ["Core", "Node", "Sockets", "Random", "TLS"]),
.testTarget(name: "RedisTests", dependencies: ["Redis"])
]
)
22 changes: 22 additions & 0 deletions Sources/Redis/Stream.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Sockets
import TLS

public var defaultHostname = "127.0.0.1"
public var defaultPort: UInt16 = 6379
Expand All @@ -19,3 +20,24 @@ extension Client where StreamType == TCPInternetSocket {
try self.init(socket, password: password)
}
}

public typealias TLSClient = Client<TLS.InternetSocket>

extension Client where StreamType == TLS.InternetSocket {
public convenience init (
hostname: String = defaultHostname,
port: UInt16 = defaultPort,
password: String? = nil
) throws {
let socket = try TCPInternetSocket(
scheme: "rediss",
hostname: hostname,
port: port
)

let stream = try TLS.InternetSocket(socket, Context(.client))

try stream.connect()
try self.init(stream, password: password)
}
}
49 changes: 31 additions & 18 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
machine:
services:
- redis
dependencies:
override:
- eval "$(curl -sL https://apt.vapor.sh)"
- sudo apt-get install swift vapor cmysql
- sudo chmod -R a+rx /usr/
test:
override:
- swift build
- swift build -c release
- swift test
- sudo apt-get remove swift
- sudo apt-get install swift=3.1.1
- swift build
- swift build -c release
- swift test
version: 2

jobs:
linux:
docker:
- image: swift:4.0
- image: redis
steps:
- run: apt-get install -y libssl-dev
- checkout
- run: swift build
- run: swift test

# 3.1 backward compat checks

linux-3:
docker:
- image: swift:3.1
- image: redis
steps:
- run: apt-get install -y libssl-dev
- checkout
- run: swift build
- run: swift test

workflows:
version: 2
tests:
jobs:
- linux
- linux-3

0 comments on commit 42cb0a0

Please sign in to comment.