Skip to content

Commit

Permalink
refactor: Revert "feat: Expose set sdk metadata (#166)" (#173)
Browse files Browse the repository at this point in the history
* Revert "refactor: Add ConfidenceForOF proxy for safe init (#167)"

This reverts commit e177c5b.

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

This reverts commit 10548d9.

* Fix ID in Provider
  • Loading branch information
fabriziodemaria authored Jun 25, 2024
1 parent 5e7422c commit 743a076
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 42 deletions.
5 changes: 2 additions & 3 deletions Confidence/src/main/java/com/spotify/confidence/Confidence.kt
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

0 comments on commit 743a076

Please sign in to comment.