-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Split OFREP and GO Feature Flag provider (#7)
Signed-off-by: Thomas Poignant <[email protected]>
- Loading branch information
1 parent
560ce65
commit 9615bfd
Showing
19 changed files
with
1,070 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Sources/GOFeatureFlag/model/options.swift → Sources/GOFeatureFlag/options.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
import Foundation | ||
import OFREP | ||
|
||
public struct GoFeatureFlagProviderOptions { | ||
public let endpoint: String | ||
public var pollInterval: TimeInterval | ||
public var networkService: NetworkingService? | ||
public var apiKey: String? | ||
|
||
public init( | ||
endpoint: String, | ||
pollInterval: TimeInterval = 30, | ||
apiKey: String?, | ||
networkService: NetworkingService? = URLSession.shared) { | ||
self.endpoint = endpoint | ||
self.pollInterval = pollInterval | ||
self.apiKey = apiKey | ||
self.networkService = networkService | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Foundation | ||
import OFREP | ||
import OpenFeature | ||
import Combine | ||
|
||
struct Metadata: ProviderMetadata { | ||
var name: String? = "GO Feature Flag provider" | ||
} | ||
|
||
public final class GoFeatureFlagProvider: FeatureProvider { | ||
public var hooks: [any OpenFeature.Hook] = [] | ||
public var metadata: ProviderMetadata = Metadata() | ||
private let ofrepProvider: OfrepProvider | ||
|
||
public init(options: GoFeatureFlagProviderOptions){ | ||
var headers: [String:String] = [:] | ||
if let apiKey = options.apiKey { | ||
headers["Authorization"] = "Bearer \(apiKey)" | ||
} | ||
let ofrepOptions = OfrepProviderOptions( | ||
endpoint: options.endpoint, | ||
pollInterval: options.pollInterval, | ||
headers: headers, | ||
networkService: options.networkService | ||
) | ||
self.ofrepProvider = OfrepProvider(options: ofrepOptions) | ||
} | ||
|
||
public func initialize(initialContext: (any OpenFeature.EvaluationContext)?) { | ||
self.ofrepProvider.initialize(initialContext: initialContext) | ||
} | ||
|
||
public func onContextSet(oldContext: (any OpenFeature.EvaluationContext)?, newContext: any OpenFeature.EvaluationContext) { | ||
self.ofrepProvider.onContextSet(oldContext: oldContext, newContext: newContext) | ||
} | ||
|
||
public func getBooleanEvaluation(key: String, defaultValue: Bool, context: (any OpenFeature.EvaluationContext)?) throws -> OpenFeature.ProviderEvaluation<Bool> { | ||
return try self.ofrepProvider.getBooleanEvaluation(key: key, defaultValue: defaultValue, context: context) | ||
} | ||
|
||
public func getStringEvaluation(key: String, defaultValue: String, context: (any OpenFeature.EvaluationContext)?) throws -> OpenFeature.ProviderEvaluation<String> { | ||
return try self.ofrepProvider.getStringEvaluation(key: key, defaultValue: defaultValue, context: context) | ||
} | ||
|
||
public func getIntegerEvaluation(key: String, defaultValue: Int64, context: (any OpenFeature.EvaluationContext)?) throws -> OpenFeature.ProviderEvaluation<Int64> { | ||
return try self.ofrepProvider.getIntegerEvaluation(key: key, defaultValue: defaultValue, context: context) | ||
} | ||
|
||
public func getDoubleEvaluation(key: String, defaultValue: Double, context: (any OpenFeature.EvaluationContext)?) throws -> OpenFeature.ProviderEvaluation<Double> { | ||
return try self.ofrepProvider.getDoubleEvaluation(key: key, defaultValue: defaultValue, context: context) | ||
} | ||
|
||
public func getObjectEvaluation(key: String, defaultValue: OpenFeature.Value, context: (any OpenFeature.EvaluationContext)?) throws -> OpenFeature.ProviderEvaluation<OpenFeature.Value> { | ||
return try self.ofrepProvider.getObjectEvaluation(key: key, defaultValue: defaultValue, context: context) | ||
} | ||
|
||
public func observe() -> AnyPublisher<OpenFeature.ProviderEvent, Never> { | ||
return self.ofrepProvider.observe() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Foundation | ||
|
||
public struct OfrepProviderOptions { | ||
public let endpoint: String | ||
public var pollInterval: TimeInterval | ||
public var headers: [String:String]? | ||
public var networkService: NetworkingService? | ||
|
||
public init( | ||
endpoint: String, | ||
pollInterval: TimeInterval = 30, | ||
headers: [String:String] = [:], | ||
networkService: NetworkingService? = URLSession.shared) { | ||
self.endpoint = endpoint | ||
self.pollInterval = pollInterval | ||
self.headers = headers | ||
self.networkService = networkService | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import XCTest | ||
import Combine | ||
import Foundation | ||
import OpenFeature | ||
@testable import GOFeatureFlag | ||
|
||
class GoFeatureFlagProviderTests: XCTestCase { | ||
var defaultEvaluationContext: MutableContext! | ||
var cancellables: Set<AnyCancellable> = [] | ||
func testShouldBeInFATALStatusIf401ErrorDuringInitialise() async { | ||
print("toto") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.