Skip to content

Commit 4707bd0

Browse files
algolia-botFluf22millotp
committed
feat(clients): helper to switch API key in use (generated)
algolia/api-clients-automation#3616 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Thomas Raffray <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 672416f commit 4707bd0

22 files changed

+67
-13
lines changed

Sources/Abtesting/AbtestingClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class AbtestingClient {
2727
try self.init(configuration: AbtestingClientConfiguration(appID: appID, apiKey: apiKey, region: region))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter addABTestsRequest: (body)
3136
/// - returns: ABTestResponse
3237
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)

Sources/Abtesting/AbtestingClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct AbtestingClientConfiguration: BaseConfiguration, Credentials {
1212
]
1313

1414
public let appID: String
15-
public let apiKey: String
15+
public var apiKey: String
1616
public var writeTimeout: TimeInterval
1717
public var readTimeout: TimeInterval
1818
public var logLevel: LogLevel

Sources/Analytics/AnalyticsClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class AnalyticsClient {
2727
try self.init(configuration: AnalyticsClientConfiguration(appID: appID, apiKey: apiKey, region: region))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter path: (path) Path of the endpoint, anything after \"/1\" must be specified.
3136
/// - parameter parameters: (query) Query parameters to apply to the current query. (optional)
3237
/// - returns: AnyCodable

Sources/Analytics/AnalyticsClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct AnalyticsClientConfiguration: BaseConfiguration, Credentials {
1212
]
1313

1414
public let appID: String
15-
public let apiKey: String
15+
public var apiKey: String
1616
public var writeTimeout: TimeInterval
1717
public var readTimeout: TimeInterval
1818
public var logLevel: LogLevel

Sources/Core/Networking/BaseConfiguration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public protocol BaseConfiguration {
2323
var hosts: [RetryableHost] { get }
2424

2525
/// Default headers that should be applied to every request.
26-
var defaultHeaders: [String: String]? { get }
26+
var defaultHeaders: [String: String]? { get set }
2727

2828
/// Compression type
2929
var compression: CompressionAlgorithm { get }
@@ -48,7 +48,7 @@ public struct DefaultConfiguration: BaseConfiguration {
4848
public let writeTimeout: TimeInterval = 30
4949
public let readTimeout: TimeInterval = 5
5050
public let logLevel: LogLevel = .info
51-
public let defaultHeaders: [String: String]? = [:]
51+
public var defaultHeaders: [String: String]? = [:]
5252
public var hosts: [RetryableHost] = []
5353
public let compression: CompressionAlgorithm = .none
5454
}

Sources/Core/Networking/Transporter.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212
// MARK: - Transporter
1313

1414
open class Transporter {
15-
let configuration: BaseConfiguration
15+
var configuration: BaseConfiguration
1616
let retryStrategy: RetryStrategy
1717
let requestBuilder: RequestBuilder
1818
let exposeIntermediateErrors: Bool
@@ -43,6 +43,10 @@ open class Transporter {
4343
self.requestBuilder = requestBuilder
4444
}
4545

46+
public func setClientApiKey(apiKey: String) {
47+
self.configuration.defaultHeaders?.updateValue(apiKey, forKey: "X-Algolia-API-Key")
48+
}
49+
4650
public func send<T: Decodable>(
4751
method: String, path: String, data: Codable?, requestOptions: RequestOptions? = nil,
4852
useReadTransporter: Bool = false

Sources/Ingestion/IngestionClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class IngestionClient {
2727
try self.init(configuration: IngestionClientConfiguration(appID: appID, apiKey: apiKey, region: region))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter authenticationCreate: (body)
3136
/// - returns: AuthenticationCreateResponse
3237
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)

Sources/Ingestion/IngestionClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct IngestionClientConfiguration: BaseConfiguration, Credentials {
1212
]
1313

1414
public let appID: String
15-
public let apiKey: String
15+
public var apiKey: String
1616
public var writeTimeout: TimeInterval
1717
public var readTimeout: TimeInterval
1818
public var logLevel: LogLevel

Sources/Insights/InsightsClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class InsightsClient {
2727
try self.init(configuration: InsightsClientConfiguration(appID: appID, apiKey: apiKey, region: region))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter path: (path) Path of the endpoint, anything after \"/1\" must be specified.
3136
/// - parameter parameters: (query) Query parameters to apply to the current query. (optional)
3237
/// - returns: AnyCodable

Sources/Insights/InsightsClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct InsightsClientConfiguration: BaseConfiguration, Credentials {
1212
]
1313

1414
public let appID: String
15-
public let apiKey: String
15+
public var apiKey: String
1616
public var writeTimeout: TimeInterval
1717
public var readTimeout: TimeInterval
1818
public var logLevel: LogLevel

Sources/Monitoring/MonitoringClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class MonitoringClient {
2727
try self.init(configuration: MonitoringClientConfiguration(appID: appID, apiKey: apiKey))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter path: (path) Path of the endpoint, anything after \"/1\" must be specified.
3136
/// - parameter parameters: (query) Query parameters to apply to the current query. (optional)
3237
/// - returns: AnyCodable

Sources/Monitoring/MonitoringClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Foundation
88

99
public struct MonitoringClientConfiguration: BaseConfiguration, Credentials {
1010
public let appID: String
11-
public let apiKey: String
11+
public var apiKey: String
1212
public var writeTimeout: TimeInterval
1313
public var readTimeout: TimeInterval
1414
public var logLevel: LogLevel

Sources/Personalization/PersonalizationClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class PersonalizationClient {
2727
try self.init(configuration: PersonalizationClientConfiguration(appID: appID, apiKey: apiKey, region: region))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter path: (path) Path of the endpoint, anything after \"/1\" must be specified.
3136
/// - parameter parameters: (query) Query parameters to apply to the current query. (optional)
3237
/// - returns: AnyCodable

Sources/Personalization/PersonalizationClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct PersonalizationClientConfiguration: BaseConfiguration, Credentials
1212
]
1313

1414
public let appID: String
15-
public let apiKey: String
15+
public var apiKey: String
1616
public var writeTimeout: TimeInterval
1717
public var readTimeout: TimeInterval
1818
public var logLevel: LogLevel

Sources/QuerySuggestions/QuerySuggestionsClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class QuerySuggestionsClient {
2727
try self.init(configuration: QuerySuggestionsClientConfiguration(appID: appID, apiKey: apiKey, region: region))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter configurationWithIndex: (body)
3136
/// - returns: BaseResponse
3237
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)

Sources/QuerySuggestions/QuerySuggestionsClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct QuerySuggestionsClientConfiguration: BaseConfiguration, Credential
1212
]
1313

1414
public let appID: String
15-
public let apiKey: String
15+
public var apiKey: String
1616
public var writeTimeout: TimeInterval
1717
public var readTimeout: TimeInterval
1818
public var logLevel: LogLevel

Sources/Recommend/RecommendClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class RecommendClient {
2727
try self.init(configuration: RecommendClientConfiguration(appID: appID, apiKey: apiKey))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter path: (path) Path of the endpoint, anything after \"/1\" must be specified.
3136
/// - parameter parameters: (query) Query parameters to apply to the current query. (optional)
3237
/// - returns: AnyCodable

Sources/Recommend/RecommendClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Foundation
88

99
public struct RecommendClientConfiguration: BaseConfiguration, Credentials {
1010
public let appID: String
11-
public let apiKey: String
11+
public var apiKey: String
1212
public var writeTimeout: TimeInterval
1313
public var readTimeout: TimeInterval
1414
public var logLevel: LogLevel

Sources/Search/SearchClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class SearchClient {
2727
try self.init(configuration: SearchClientConfiguration(appID: appID, apiKey: apiKey))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter apiKey: (body)
3136
/// - returns: AddApiKeyResponse
3237
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)

Sources/Search/SearchClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Foundation
88

99
public struct SearchClientConfiguration: BaseConfiguration, Credentials {
1010
public let appID: String
11-
public let apiKey: String
11+
public var apiKey: String
1212
public var writeTimeout: TimeInterval
1313
public var readTimeout: TimeInterval
1414
public var logLevel: LogLevel

Sources/Usage/UsageClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ open class UsageClient {
2727
try self.init(configuration: UsageClientConfiguration(appID: appID, apiKey: apiKey))
2828
}
2929

30+
open func setClientApiKey(apiKey: String) {
31+
self.configuration.apiKey = apiKey
32+
self.transporter.setClientApiKey(apiKey: apiKey)
33+
}
34+
3035
/// - parameter path: (path) Path of the endpoint, anything after \"/1\" must be specified.
3136
/// - parameter parameters: (query) Query parameters to apply to the current query. (optional)
3237
/// - returns: AnyCodable

Sources/Usage/UsageClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Foundation
88

99
public struct UsageClientConfiguration: BaseConfiguration, Credentials {
1010
public let appID: String
11-
public let apiKey: String
11+
public var apiKey: String
1212
public var writeTimeout: TimeInterval
1313
public var readTimeout: TimeInterval
1414
public var logLevel: LogLevel

0 commit comments

Comments
 (0)