Skip to content

Commit 3c38688

Browse files
authored
ValkeyClusterClient client config defines whether TLS is required (#212)
This means ValkeyNodeDescription does not need to include whether the node uses TLS. Signed-off-by: Adam Fowler <[email protected]>
1 parent 5ff41b5 commit 3c38688

File tree

6 files changed

+5
-37
lines changed

6 files changed

+5
-37
lines changed

Sources/Valkey/Cluster/ValkeyNodeDescription.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ package struct ValkeyNodeDescription: Identifiable, Hashable, Sendable {
5151
/// This property is required and is used as part of the node's unique identifier.
5252
package var port: Int
5353

54-
/// Indicates whether TLS/SSL should be used when connecting to this node.
55-
///
56-
/// When `true`, the connection will use secure transport with TLS.
57-
package var useTLS: Bool
58-
5954
/// Creates a node description from any type conforming to the `ValkeyNodeDescriptionProtocol`.
6055
///
6156
/// This initializer allows for easy conversion from various node description types
@@ -68,7 +63,6 @@ package struct ValkeyNodeDescription: Identifiable, Hashable, Sendable {
6863
self.ip = description.ip
6964
self.endpoint = description.endpoint
7065
self.port = description.port
71-
self.useTLS = description.useTLS
7266
}
7367

7468
/// Creates a node description from a cluster node description.
@@ -84,7 +78,6 @@ package struct ValkeyNodeDescription: Identifiable, Hashable, Sendable {
8478
self.ip = description.ip
8579
self.endpoint = description.endpoint
8680
self.port = description.tlsPort ?? description.port ?? 6379
87-
self.useTLS = description.tlsPort != nil
8881
}
8982

9083
/// Determines whether this node description matches a given cluster node description.
@@ -97,6 +90,5 @@ package struct ValkeyNodeDescription: Identifiable, Hashable, Sendable {
9790
func matches(_ other: ValkeyClusterDescription.Node) -> Bool {
9891
self.endpoint == other.endpoint
9992
&& self.port == other.tlsPort ?? other.port ?? 6379
100-
&& self.useTLS == (other.tlsPort != nil)
10193
}
10294
}

Sources/Valkey/Cluster/ValkeyNodeDescriptionProtocol.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,4 @@ public protocol ValkeyNodeDescriptionProtocol: Sendable, Equatable {
4040

4141
/// The port number on which the Valkey service is listening.
4242
var port: Int { get }
43-
44-
/// Indicates whether TLS (Transport Layer Security) should be used when connecting to this node.
45-
///
46-
/// - `true`: Use a secure TLS connection
47-
/// - `false`: Use a plain TCP connection
48-
var useTLS: Bool { get }
4943
}

Sources/Valkey/Cluster/ValkeyNodeDiscovery.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public protocol ValkeyNodeDiscovery: Sendable {
3636
/// ```swift
3737
/// // Using ExpressibleByArrayLiteral conformance for more concise initialization
3838
/// let discovery: ValkeyStaticNodeDiscovery = [
39-
/// .init(host: "replica1.valkey.io", port: 10600, useTLS: false),
40-
/// .init(ip: "192.168.12.1", port: 10600, useTLS: true)
39+
/// .init(host: "replica1.valkey.io", port: 10600),
40+
/// .init(ip: "192.168.12.1", port: 10600)
4141
/// ]
4242
/// ```
4343
public struct ValkeyStaticNodeDiscovery: ValkeyNodeDiscovery {
@@ -47,35 +47,30 @@ public struct ValkeyStaticNodeDiscovery: ValkeyNodeDiscovery {
4747
public var ip: String?
4848
public var endpoint: String
4949
public var port: Int
50-
public var useTLS: Bool
5150

5251
/// Initializes a `NodeDescription` with a host and optional IP.
5352
///
5453
/// - Parameters:
5554
/// - host: The host name of the node.
5655
/// - ip: The optional IP address of the node.
5756
/// - port: The port number the node listens on (default is 6379).
58-
/// - useTLS: A boolean indicating whether TLS should be used (default is true).
59-
public init(host: String, ip: String? = nil, port: Int = 6379, useTLS: Bool = true) {
57+
public init(host: String, ip: String? = nil, port: Int = 6379) {
6058
self.host = host
6159
self.ip = ip
6260
self.endpoint = host
6361
self.port = port
64-
self.useTLS = useTLS
6562
}
6663

6764
/// Initializes a `NodeDescription` with an IP address.
6865
///
6966
/// - Parameters:
7067
/// - ip: The IP address of the node.
7168
/// - port: The port number the node listens on (default is 6379).
72-
/// - useTLS: A boolean indicating whether TLS should be used (default is false).
73-
public init(ip: String, port: Int = 6379, useTLS: Bool = false) {
69+
public init(ip: String, port: Int = 6379) {
7470
self.host = nil
7571
self.ip = ip
7672
self.endpoint = ip
7773
self.port = port
78-
self.useTLS = useTLS
7974
}
8075
}
8176

Sources/Valkey/Cluster/ValkeyTopologyCandidate.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ package struct ValkeyTopologyCandidate: Hashable {
3737
/// The port to connect to (either standard port or TLS port).
3838
package var port: Int
3939

40-
/// Whether TLS should be used for connecting to this node.
41-
package var useTLS: Bool
42-
4340
/// Creates a simplified node representation from a `ValkeyClusterDescription.Node`.
4441
///
4542
/// - Parameter node: The source node from a cluster description.
4643
package init(_ node: ValkeyClusterDescription.Node) {
4744
self.endpoint = node.endpoint
4845
self.port = node.tlsPort ?? node.port ?? 6379
49-
self.useTLS = node.tlsPort != nil
5046
}
5147
}
5248

@@ -87,9 +83,6 @@ package struct ValkeyTopologyCandidate: Hashable {
8783
if lhs.port != rhs.port {
8884
return lhs.port < rhs.port
8985
}
90-
if lhs.useTLS != rhs.useTLS {
91-
return !lhs.useTLS
92-
}
9386
return true
9487
})
9588

Sources/Valkey/Node/ValkeyNodeClientFactory.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ package struct ValkeyNodeClientFactory: ValkeyNodeConnectionPoolFactory {
5353
port: nodeDescription.port
5454
)
5555

56-
var clientConfiguration = self.configuration
57-
if !nodeDescription.useTLS {
58-
// TODO: Should this throw? What about the other way around?
59-
clientConfiguration.tls = .disable
60-
}
61-
6256
return ValkeyNodeClient(
6357
serverAddress,
6458
connectionIDGenerator: self.connectionIDGenerator,

Tests/ClusterIntegrationTests/ClusterIntegrationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ struct ClusterIntegrationTests {
107107
) async throws -> T {
108108
let client = ValkeyClusterClient(
109109
clientConfiguration: nodeClientConfiguration,
110-
nodeDiscovery: ValkeyStaticNodeDiscovery(nodeAddresses.map { .init(host: $0.host, port: $0.port, useTLS: $0.tls) }),
110+
nodeDiscovery: ValkeyStaticNodeDiscovery(nodeAddresses.map { .init(host: $0.host, port: $0.port) }),
111111
logger: logger
112112
)
113113

0 commit comments

Comments
 (0)