Skip to content

Commit 27c98d2

Browse files
committed
Moved configuration enums to dedicated type ConfigEnums
1 parent 6e7e645 commit 27c98d2

File tree

4 files changed

+103
-88
lines changed

4 files changed

+103
-88
lines changed

Diff for: Sources/SwiftKafka/New/ClientConfig.swift

+14-78
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// TODO: DocC: inherit documentation?
1919
// TODO: DocC: take from lirbdkafka official documentation
2020
// TODO: Topic config -> see KafkaConfig in SwiftKafka
21-
// TODO: make IPAddressFamily etc. part of some ConfigProperty like type to avoid cluttering docc
2221
// TODO: create empty init for substructs to disable free initializer?
2322
// TODO: test that values get set accordingly
2423
// TODO: remove old config tests
@@ -91,7 +90,7 @@ extension ClientConfig {
9190
set { self.properties["topic.blacklist"] = newValue.joined(separator: ",") }
9291
}
9392

94-
public var debug: [DebugOption] {
93+
public var debug: [ConfigEnums.DebugOption] {
9594
get { self.getDebugOptions() }
9695
set {
9796
if !newValue.isEmpty {
@@ -140,7 +139,7 @@ extension ClientConfig {
140139
set { self.properties["broker.address.ttl"] = String(newValue) }
141140
}
142141

143-
public var brokerAddressFamily: IPAddressFamily {
142+
public var brokerAddressFamily: ConfigEnums.IPAddressFamily {
144143
get { self.getIPAddressFamily() ?? .any }
145144
set { self.properties["broker.address.family"] = newValue.description }
146145
}
@@ -155,7 +154,7 @@ extension ClientConfig {
155154
set { self.properties["reconnect.backoff.max.ms"] = String(newValue) }
156155
}
157156

158-
public var securityProtocol: SecurityProtocol {
157+
public var securityProtocol: ConfigEnums.SecurityProtocol {
159158
get { self.getSecurityProtocol() ?? .plaintext }
160159
set { self.properties["security.protocol"] = newValue.description }
161160
}
@@ -195,7 +194,7 @@ extension ClientConfig {
195194
set { self.properties["ssl.keystore.password"] = newValue }
196195
}
197196

198-
public var saslMechanism: SASLMechanism? {
197+
public var saslMechanism: ConfigEnums.SASLMechanism? {
199198
get { self.getSASLMechanism() }
200199
set {
201200
if let newValue {
@@ -250,104 +249,41 @@ extension ClientConfig {
250249
return Bool(value)
251250
}
252251

253-
func getDebugOptions() -> [DebugOption] {
252+
func getDebugOptions() -> [ConfigEnums.DebugOption] {
254253
guard let options = properties["debug"] else {
255254
return []
256255
}
257256
return options.components(separatedBy: ",")
258-
.map { DebugOption(description: $0) }
257+
.map { ConfigEnums.DebugOption(description: $0) }
259258
}
260259

261-
func getIPAddressFamily() -> IPAddressFamily? {
260+
func getIPAddressFamily() -> ConfigEnums.IPAddressFamily? {
262261
guard let value = properties["broker.address.family"] else {
263262
return nil
264263
}
265-
return IPAddressFamily(description: value)
264+
return ConfigEnums.IPAddressFamily(description: value)
266265
}
267266

268-
func getSecurityProtocol() -> SecurityProtocol? {
267+
func getSecurityProtocol() -> ConfigEnums.SecurityProtocol? {
269268
guard let value = properties["security.protocol"] else {
270269
return nil
271270
}
272-
return SecurityProtocol(description: value)
271+
return ConfigEnums.SecurityProtocol(description: value)
273272
}
274273

275-
func getSASLMechanism() -> SASLMechanism? {
274+
func getSASLMechanism() -> ConfigEnums.SASLMechanism? {
276275
guard let value = properties["sasl.mechanism"] else {
277276
return nil
278277
}
279-
return SASLMechanism(description: value)
278+
return ConfigEnums.SASLMechanism(description: value)
280279
}
281280

282281
// TODO: move to Consumer
283-
func getAutoOffsetReset() -> AutoOffsetReset? {
282+
func getAutoOffsetReset() -> ConfigEnums.AutoOffsetReset? {
284283
guard let value = properties["auto.offset.reset"] else {
285284
return nil
286285
}
287-
return AutoOffsetReset(description: value)
286+
return ConfigEnums.AutoOffsetReset(description: value)
288287
}
289288
}
290289

291-
// MARK: - Auxiliary Types
292-
293-
public struct DebugOption: Hashable, Equatable, CustomStringConvertible {
294-
public let description: String
295-
296-
public static let generic = DebugOption(description: "generic")
297-
public static let broker = DebugOption(description: "broker")
298-
public static let topic = DebugOption(description: "topic")
299-
public static let metadata = DebugOption(description: "metadata")
300-
public static let feature = DebugOption(description: "feature")
301-
public static let queue = DebugOption(description: "queue")
302-
public static let msg = DebugOption(description: "msg")
303-
public static let `protocol` = DebugOption(description: "protocol")
304-
public static let cgrp = DebugOption(description: "cgrp")
305-
public static let security = DebugOption(description: "security")
306-
public static let fetch = DebugOption(description: "fetch")
307-
public static let interceptor = DebugOption(description: "interceptor")
308-
public static let plugin = DebugOption(description: "plugin")
309-
public static let consumer = DebugOption(description: "consumer")
310-
public static let admin = DebugOption(description: "admin")
311-
public static let eos = DebugOption(description: "eos")
312-
public static let all = DebugOption(description: "all")
313-
}
314-
315-
public struct IPAddressFamily: Hashable, Equatable, CustomStringConvertible {
316-
public let description: String
317-
318-
public static let any = IPAddressFamily(description: "any")
319-
public static let v4 = IPAddressFamily(description: "v4")
320-
public static let v6 = IPAddressFamily(description: "v6")
321-
}
322-
323-
public struct SecurityProtocol: Hashable, Equatable, CustomStringConvertible {
324-
public let description: String
325-
326-
public static let plaintext = SecurityProtocol(description: "plaintext")
327-
public static let ssl = SecurityProtocol(description: "ssl")
328-
public static let saslPlaintext = SecurityProtocol(description: "sasl_plaintext")
329-
public static let saslSSL = SecurityProtocol(description: "sasl_ssl")
330-
}
331-
332-
public struct SASLMechanism: Hashable, Equatable, CustomStringConvertible {
333-
public let description: String
334-
335-
public static let gssapi = SASLMechanism(description: "GSSAPI")
336-
public static let plain = SASLMechanism(description: "PLAIN")
337-
public static let scramSHA256 = SASLMechanism(description: "SCRAM-SHA-256")
338-
public static let scramSHA512 = SASLMechanism(description: "SCRAM-SHA-512")
339-
public static let oauthbearer = SASLMechanism(description: "OAUTHBEARER")
340-
}
341-
342-
// TODO: move to consumer? -> only used there
343-
public struct AutoOffsetReset: Hashable, Equatable, CustomStringConvertible {
344-
public let description: String
345-
346-
public static let smallest = AutoOffsetReset(description: "smallest")
347-
public static let earliest = AutoOffsetReset(description: "earliest")
348-
public static let beginning = AutoOffsetReset(description: "beginning")
349-
public static let largest = AutoOffsetReset(description: "largest")
350-
public static let latest = AutoOffsetReset(description: "latest")
351-
public static let end = AutoOffsetReset(description: "end")
352-
public static let error = AutoOffsetReset(description: "error")
353-
}

Diff for: Sources/SwiftKafka/New/ConfigEnums.swift

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-kafka-gsoc open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the swift-kafka-gsoc project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of swift-kafka-gsoc project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
// TODO: docc
16+
public struct ConfigEnums {
17+
18+
public struct DebugOption: Hashable, Equatable, CustomStringConvertible {
19+
public let description: String
20+
21+
public static let generic = DebugOption(description: "generic")
22+
public static let broker = DebugOption(description: "broker")
23+
public static let topic = DebugOption(description: "topic")
24+
public static let metadata = DebugOption(description: "metadata")
25+
public static let feature = DebugOption(description: "feature")
26+
public static let queue = DebugOption(description: "queue")
27+
public static let msg = DebugOption(description: "msg")
28+
public static let `protocol` = DebugOption(description: "protocol")
29+
public static let cgrp = DebugOption(description: "cgrp")
30+
public static let security = DebugOption(description: "security")
31+
public static let fetch = DebugOption(description: "fetch")
32+
public static let interceptor = DebugOption(description: "interceptor")
33+
public static let plugin = DebugOption(description: "plugin")
34+
public static let consumer = DebugOption(description: "consumer")
35+
public static let admin = DebugOption(description: "admin")
36+
public static let eos = DebugOption(description: "eos")
37+
public static let all = DebugOption(description: "all")
38+
}
39+
40+
public struct IPAddressFamily: Hashable, Equatable, CustomStringConvertible {
41+
public let description: String
42+
43+
public static let any = IPAddressFamily(description: "any")
44+
public static let v4 = IPAddressFamily(description: "v4")
45+
public static let v6 = IPAddressFamily(description: "v6")
46+
}
47+
48+
public struct SecurityProtocol: Hashable, Equatable, CustomStringConvertible {
49+
public let description: String
50+
51+
public static let plaintext = SecurityProtocol(description: "plaintext")
52+
public static let ssl = SecurityProtocol(description: "ssl")
53+
public static let saslPlaintext = SecurityProtocol(description: "sasl_plaintext")
54+
public static let saslSSL = SecurityProtocol(description: "sasl_ssl")
55+
}
56+
57+
public struct SASLMechanism: Hashable, Equatable, CustomStringConvertible {
58+
public let description: String
59+
60+
public static let gssapi = SASLMechanism(description: "GSSAPI")
61+
public static let plain = SASLMechanism(description: "PLAIN")
62+
public static let scramSHA256 = SASLMechanism(description: "SCRAM-SHA-256")
63+
public static let scramSHA512 = SASLMechanism(description: "SCRAM-SHA-512")
64+
public static let oauthbearer = SASLMechanism(description: "OAUTHBEARER")
65+
}
66+
67+
// TODO: move to consumer? -> only used there
68+
public struct AutoOffsetReset: Hashable, Equatable, CustomStringConvertible {
69+
public let description: String
70+
71+
public static let smallest = AutoOffsetReset(description: "smallest")
72+
public static let earliest = AutoOffsetReset(description: "earliest")
73+
public static let beginning = AutoOffsetReset(description: "beginning")
74+
public static let largest = AutoOffsetReset(description: "largest")
75+
public static let latest = AutoOffsetReset(description: "latest")
76+
public static let end = AutoOffsetReset(description: "end")
77+
public static let error = AutoOffsetReset(description: "error")
78+
}
79+
}

Diff for: Sources/SwiftKafka/New/ConsumerConfig.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public struct ConsumerConfig: ClientConfig {
4747
set { self.properties["auto.commit.interval.ms"] = String(newValue) }
4848
}
4949

50-
public var autoOffsetReset: AutoOffsetReset {
50+
public var autoOffsetReset: ConfigEnums.AutoOffsetReset {
5151
get { self.getAutoOffsetReset() ?? .largest }
5252
set { self.properties["auto.offset.reset"] = newValue.description }
5353
}
@@ -75,7 +75,7 @@ public struct ConsumerConfig: ClientConfig {
7575
enableAutoCommit: Bool = true,
7676
autoCommitIntervalMs: UInt = 5000,
7777
enableAutoOffsetStore: Bool = true,
78-
autoOffsetReset: AutoOffsetReset = .largest,
78+
autoOffsetReset: ConfigEnums.AutoOffsetReset = .largest,
7979
enablePartitionEOF: Bool = false,
8080
allowAutoCreateTopics: Bool = false,
8181
clientID: String = "rdkafka",
@@ -90,7 +90,7 @@ public struct ConsumerConfig: ClientConfig {
9090
topicMetadataRefreshSparse: Bool = true,
9191
topicMetadataPropagationMaxMs: UInt = 30000,
9292
topicDenylist: [String] = [],
93-
debug: [DebugOption] = [],
93+
debug: [ConfigEnums.DebugOption] = [],
9494
socketTimeoutMs: UInt = 60000,
9595
socketSendBufferBytes: UInt = 0,
9696
socketReceiveBufferBytes: UInt = 0,
@@ -99,18 +99,18 @@ public struct ConsumerConfig: ClientConfig {
9999
socketMaxFails: UInt = 1,
100100
socketConnectionSetupTimeoutMs: UInt = 30000,
101101
brokerAddressTTL: UInt = 1000,
102-
brokerAddressFamily: IPAddressFamily = .any,
102+
brokerAddressFamily: ConfigEnums.IPAddressFamily = .any,
103103
reconnectBackoffMs: UInt = 100,
104104
reconnectBackoffMaxMs: UInt = 10000,
105-
securityProtocol: SecurityProtocol = .plaintext,
105+
securityProtocol: ConfigEnums.SecurityProtocol = .plaintext,
106106
sslKeyLocation: String = "",
107107
sslKeyPassword: String = "",
108108
sslCertificateLocation: String = "",
109109
sslCALocation: String = "",
110110
sslCRLLocation: String = "",
111111
sslKeystoreLocation: String = "",
112112
sslKeystorePassword: String = "",
113-
saslMechanism: SASLMechanism? = nil,
113+
saslMechanism: ConfigEnums.SASLMechanism? = nil,
114114
saslUsername: String? = nil,
115115
saslPassword: String? = nil
116116
) {

Diff for: Sources/SwiftKafka/New/ProducerConfig.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public struct ProducerConfig: ClientConfig {
7171
topicMetadataRefreshSparse: Bool = true,
7272
topicMetadataPropagationMaxMs: UInt = 30000,
7373
topicDenylist: [String] = [],
74-
debug: [DebugOption] = [],
74+
debug: [ConfigEnums.DebugOption] = [],
7575
socketTimeoutMs: UInt = 60000,
7676
socketSendBufferBytes: UInt = 0,
7777
socketReceiveBufferBytes: UInt = 0,
@@ -80,18 +80,18 @@ public struct ProducerConfig: ClientConfig {
8080
socketMaxFails: UInt = 1,
8181
socketConnectionSetupTimeoutMs: UInt = 30000,
8282
brokerAddressTTL: UInt = 1000,
83-
brokerAddressFamily: IPAddressFamily = .any,
83+
brokerAddressFamily: ConfigEnums.IPAddressFamily = .any,
8484
reconnectBackoffMs: UInt = 100,
8585
reconnectBackoffMaxMs: UInt = 10000,
86-
securityProtocol: SecurityProtocol = .plaintext,
86+
securityProtocol: ConfigEnums.SecurityProtocol = .plaintext,
8787
sslKeyLocation: String = "",
8888
sslKeyPassword: String = "",
8989
sslCertificateLocation: String = "",
9090
sslCALocation: String = "",
9191
sslCRLLocation: String = "",
9292
sslKeystoreLocation: String = "",
9393
sslKeystorePassword: String = "",
94-
saslMechanism: SASLMechanism? = nil,
94+
saslMechanism: ConfigEnums.SASLMechanism? = nil,
9595
saslUsername: String? = nil,
9696
saslPassword: String? = nil
9797
) {

0 commit comments

Comments
 (0)