Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Revert "feat: Expose set sdk metadata (#166)" #173

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ object ConfidenceFactory {
fun create(
context: Context,
clientSecret: String,
sdk: SdkMetadata = SdkMetadata(SDK_ID, BuildConfig.SDK_VERSION),
initialContext: Map<String, ConfidenceValue> = mapOf(),
region: ConfidenceRegion = ConfidenceRegion.GLOBAL,
dispatcher: CoroutineDispatcher = Dispatchers.IO,
Expand All @@ -269,7 +268,7 @@ object ConfidenceFactory {
)
val flagApplierClient = FlagApplierClientImpl(
clientSecret,
sdk,
SdkMetadata(SDK_ID, BuildConfig.SDK_VERSION),
region,
dispatcher
)
Expand All @@ -278,7 +277,7 @@ object ConfidenceFactory {
region = region,
httpClient = OkHttpClient(),
dispatcher = dispatcher,
sdkMetadata = sdk
sdkMetadata = SdkMetadata(SDK_ID, BuildConfig.SDK_VERSION)
)
val visitorId = ConfidenceValue.String(VisitorUtil.getId(context))
val initContext = initialContext.toMutableMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ConfidenceIntegrationTests {
map["user"] =
ConfidenceValue.Struct(mapOf("country" to ConfidenceValue.String("SE")))

val oldConfidence = ConfidenceFactory.create(mockContext, clientSecret, initialContext = map)
val oldConfidence = ConfidenceFactory.create(mockContext, clientSecret, map)
val context = oldConfidence.getContext()

val storage = FileDiskStorage.create(mockContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MainVm(app: Application) : AndroidViewModel(app) {
app.applicationContext,
clientSecret,
initialContext = mapOf("targeting_key" to ConfidenceValue.String("a98a4291-53b0-49d9-bae8-73d3f5da2070")),
region = ConfidenceRegion.EUROPE
ConfidenceRegion.EUROPE
)
confidence.track(AndroidLifecycleEventProducer(getApplication(), false))
eventSender = confidence.withContext(mutableMap)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@

package com.spotify.confidence.openfeature

import android.content.Context
import com.spotify.confidence.BuildConfig
import com.spotify.confidence.Confidence
import com.spotify.confidence.ConfidenceError.ErrorCode
import com.spotify.confidence.ConfidenceError.FlagNotFoundError
import com.spotify.confidence.ConfidenceError.ParseError
import com.spotify.confidence.ConfidenceFactory
import com.spotify.confidence.ConfidenceRegion
import com.spotify.confidence.ConfidenceValue
import com.spotify.confidence.Evaluation
import com.spotify.confidence.ResolveReason
import com.spotify.confidence.client.SdkMetadata
import dev.openfeature.sdk.EvaluationContext
import dev.openfeature.sdk.FeatureProvider
import dev.openfeature.sdk.Hook
Expand All @@ -31,6 +26,8 @@ import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch

internal const val PROVIDER_ID = "SDK_ID_KOTLIN_CONFIDENCE"

@Suppress(
"TooManyFunctions",
"LongParameterList"
Expand Down Expand Up @@ -145,33 +142,12 @@ class ConfidenceFeatureProvider private constructor(
throw OpenFeatureError.FlagNotFoundError(e.flag)
}
}

companion object {
private class ConfidenceMetadata(override var name: String? = "confidence") : ProviderMetadata
class ConfidenceForOpenFeature internal constructor(val confidence: Confidence)

fun createConfidence(
context: Context,
clientSecret: String,
initialContext: Map<String, ConfidenceValue> = mapOf(),
region: ConfidenceRegion = ConfidenceRegion.GLOBAL,
dispatcher: CoroutineDispatcher = Dispatchers.IO
): ConfidenceForOpenFeature {
return ConfidenceForOpenFeature(
ConfidenceFactory.create(
context,
clientSecret,
sdk = SdkMetadata("SDK_ID_KOTLIN_PROVIDER", BuildConfig.SDK_VERSION),
initialContext = initialContext,
region = region,
dispatcher = dispatcher
)
)
}
private class ConfidenceMetadata(override var name: String? = PROVIDER_ID) : ProviderMetadata

@Suppress("LongParameterList")
fun create(
confidenceForOF: ConfidenceForOpenFeature,
confidence: Confidence,
initialisationStrategy: InitialisationStrategy = InitialisationStrategy.FetchAndActivate,
hooks: List<Hook<*>> = listOf(),
metadata: ProviderMetadata = ConfidenceMetadata(),
Expand All @@ -183,7 +159,7 @@ class ConfidenceFeatureProvider private constructor(
metadata = metadata,
initialisationStrategy = initialisationStrategy,
eventHandler = eventHandler,
confidence = confidenceForOF.confidence,
confidence = confidence,
dispatcher = dispatcher
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ class ConfidenceIntegrationTests {
val eventsHandler = EventHandler(Dispatchers.IO).apply {
publish(OpenFeatureEvents.ProviderStale)
}
val mockConfidence = ConfidenceFeatureProvider.Companion.ConfidenceForOpenFeature(
ConfidenceFactory.create(mockContext, clientSecret)
)
val mockConfidence = ConfidenceFactory.create(mockContext, clientSecret)
OpenFeatureAPI.setProvider(
ConfidenceFeatureProvider.create(
confidenceForOF = mockConfidence,
confidence = mockConfidence,
initialisationStrategy = InitialisationStrategy.FetchAndActivate,
eventHandler = eventsHandler
),
Expand Down Expand Up @@ -89,12 +87,10 @@ class ConfidenceIntegrationTests {
}
val cacheFile = File(mockContext.filesDir, FLAGS_FILE_NAME)
assertEquals(0L, cacheFile.length())
val mockConfidence = ConfidenceFeatureProvider.Companion.ConfidenceForOpenFeature(
ConfidenceFactory.create(mockContext, clientSecret)
)
val mockConfidence = ConfidenceFactory.create(mockContext, clientSecret)
OpenFeatureAPI.setProvider(
ConfidenceFeatureProvider.create(
confidenceForOF = mockConfidence,
confidence = mockConfidence,
eventHandler = eventsHandler
),
ImmutableContext(
Expand Down
Loading