Skip to content

Commit

Permalink
fix: Ensure secondary environments use correct mobile key (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 authored Mar 1, 2024
1 parent 52fe6b3 commit e92054c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions LaunchDarkly/LaunchDarkly/LDClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ public class LDClient {
return
}

let serviceFactory = serviceFactory ?? ClientServiceFactory(config: config)
let serviceFactory = serviceFactory ?? ClientServiceFactory(logger: config.logger)
var keys = [config.mobileKey]
keys.append(contentsOf: config.getSecondaryMobileKeys().values)
serviceFactory.makeCacheConverter().convertCacheData(serviceFactory: serviceFactory, keysToConvert: keys, maxCachedContexts: config.maxCachedContexts)
Expand Down Expand Up @@ -783,7 +783,7 @@ public class LDClient {

private init(serviceFactory: ClientServiceCreating, configuration: LDConfig, startContext: LDContext?, completion: (() -> Void)? = nil) {
self.serviceFactory = serviceFactory
environmentReporter = self.serviceFactory.makeEnvironmentReporter()
environmentReporter = self.serviceFactory.makeEnvironmentReporter(config: configuration)
flagCache = self.serviceFactory.makeFeatureFlagCache(mobileKey: configuration.mobileKey, maxCachedContexts: configuration.maxCachedContexts)
flagStore = self.serviceFactory.makeFlagStore()
flagChangeNotifier = self.serviceFactory.makeFlagChangeNotifier()
Expand All @@ -797,7 +797,7 @@ public class LDClient {
context = AutoEnvContextModifier(environmentReporter: environmentReporter, logger: config.logger).modifyContext(context)
}

service = self.serviceFactory.makeDarklyServiceProvider(context: context, envReporter: environmentReporter)
service = self.serviceFactory.makeDarklyServiceProvider(config: config, context: context, envReporter: environmentReporter)
diagnosticReporter = self.serviceFactory.makeDiagnosticReporter(service: service, environmentReporter: environmentReporter)
eventReporter = self.serviceFactory.makeEventReporter(service: service)
connectionInformation = self.serviceFactory.makeConnectionInformation()
Expand Down
21 changes: 11 additions & 10 deletions LaunchDarkly/LaunchDarkly/ServiceObjects/ClientServiceFactory.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Foundation
import LDSwiftEventSource
import OSLog

protocol ClientServiceCreating {
func makeKeyedValueCache(cacheKey: String?) -> KeyedValueCaching
func makeFeatureFlagCache(mobileKey: String, maxCachedContexts: Int) -> FeatureFlagCaching
func makeCacheConverter() -> CacheConverting
func makeDarklyServiceProvider(context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider
func makeDarklyServiceProvider(config: LDConfig, context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider
func makeFlagSynchronizer(streamingMode: LDStreamingMode, pollingInterval: TimeInterval, useReport: Bool, service: DarklyServiceProvider) -> LDFlagSynchronizing
func makeFlagSynchronizer(streamingMode: LDStreamingMode,
pollingInterval: TimeInterval,
Expand All @@ -16,7 +17,7 @@ protocol ClientServiceCreating {
func makeEventReporter(service: DarklyServiceProvider) -> EventReporting
func makeEventReporter(service: DarklyServiceProvider, onSyncComplete: EventSyncCompleteClosure?) -> EventReporting
func makeStreamingProvider(url: URL, httpHeaders: [String: String], connectMethod: String, connectBody: Data?, handler: EventHandler, delegate: RequestHeaderTransform?, errorHandler: ConnectionErrorHandler?) -> DarklyStreamingProvider
func makeEnvironmentReporter() -> EnvironmentReporting
func makeEnvironmentReporter(config: LDConfig) -> EnvironmentReporting
func makeThrottler(environmentReporter: EnvironmentReporting) -> Throttling
func makeConnectionInformation() -> ConnectionInformation
func makeDiagnosticCache(sdkKey: String) -> DiagnosticCaching
Expand All @@ -25,10 +26,10 @@ protocol ClientServiceCreating {
}

final class ClientServiceFactory: ClientServiceCreating {
private let config: LDConfig
private let logger: OSLog

init(config: LDConfig) {
self.config = config
init(logger: OSLog) {
self.logger = logger
}

func makeKeyedValueCache(cacheKey: String?) -> KeyedValueCaching {
Expand All @@ -43,7 +44,7 @@ final class ClientServiceFactory: ClientServiceCreating {
CacheConverter()
}

func makeDarklyServiceProvider(context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider {
func makeDarklyServiceProvider(config: LDConfig, context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider {
DarklyService(config: config, context: context, envReporter: envReporter, serviceFactory: self)
}

Expand All @@ -60,7 +61,7 @@ final class ClientServiceFactory: ClientServiceCreating {
}

func makeFlagChangeNotifier() -> FlagChangeNotifying {
FlagChangeNotifier(logger: config.logger)
FlagChangeNotifier(logger: logger)
}

func makeEventReporter(service: DarklyServiceProvider) -> EventReporting {
Expand Down Expand Up @@ -91,7 +92,7 @@ final class ClientServiceFactory: ClientServiceCreating {
return EventSource(config: config)
}

func makeEnvironmentReporter() -> EnvironmentReporting {
func makeEnvironmentReporter(config: LDConfig) -> EnvironmentReporting {
let builder = EnvironmentReporterBuilder()

if let info = config.applicationInfo {
Expand All @@ -106,7 +107,7 @@ final class ClientServiceFactory: ClientServiceCreating {
}

func makeThrottler(environmentReporter: EnvironmentReporting) -> Throttling {
Throttler(logger: config.logger)
Throttler(logger: logger)
}

func makeConnectionInformation() -> ConnectionInformation {
Expand All @@ -122,6 +123,6 @@ final class ClientServiceFactory: ClientServiceCreating {
}

func makeFlagStore() -> FlagMaintaining {
FlagStore(logger: config.logger)
FlagStore(logger: logger)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class ClientServiceMockFactory: ClientServiceCreating {
return makeCacheConverterReturnValue
}

func makeDarklyServiceProvider(context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider {
func makeDarklyServiceProvider(config: LDConfig, context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider {
DarklyServiceMock(config: config, context: context)
}

Expand Down Expand Up @@ -111,7 +111,7 @@ final class ClientServiceMockFactory: ClientServiceCreating {
}

var makeEnvironmentReporterReturnValue: EnvironmentReportingMock = EnvironmentReportingMock()
func makeEnvironmentReporter() -> EnvironmentReporting {
func makeEnvironmentReporter(config: LDConfig) -> EnvironmentReporting {
return makeEnvironmentReporterReturnValue
}

Expand Down

0 comments on commit e92054c

Please sign in to comment.