Skip to content

Commit

Permalink
Utkast til å få med strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
throndi committed Aug 31, 2023
1 parent 3bcaf53 commit fb35472
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ package no.nav.familie.unleash
import io.getunleash.DefaultUnleash
import io.getunleash.UnleashContext
import io.getunleash.UnleashContextProvider
import io.getunleash.strategy.Strategy
import io.getunleash.util.UnleashConfig

class DefaultUnleashService(
val apiUrl: String,
val apiToken: String,
val appName: String
private val apiUrl: String,
private val apiToken: String,
private val appName: String,
private val strategies: List<Strategy>
) : UnleashService {

private val defaultUnleash: DefaultUnleash

init {

defaultUnleash = DefaultUnleash(
UnleashConfig.builder()
.appName(appName)
.unleashAPI("$apiUrl/api")
.apiKey(apiToken)
.unleashContextProvider(lagUnleashContextProvider()).build()
.unleashContextProvider(lagUnleashContextProvider())
.build(),
*strategies.toTypedArray()
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.familie.unleash

import io.getunleash.strategy.Strategy
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.DisposableBean
import org.springframework.beans.factory.annotation.Value
Expand All @@ -14,13 +15,14 @@ open class UnleashConfig(
private val featureToggleProperties: UnleashProperties,
@Value("\${UNLEASH_SERVER_API_URL}") val apiUrl: String,
@Value("\${UNLEASH_SERVER_API_TOKEN}") val apiToken: String,
@Value("\${NAIS_APP_NAME}") val appName: String
@Value("\${NAIS_APP_NAME}") val appName: String,
private val strategies: List<Strategy> = listOf()
) {

@Bean
open fun unleashNext(): UnleashService =
if (featureToggleProperties.enabled) {
DefaultUnleashService(apiUrl = apiUrl, apiToken = apiToken, appName = appName)
DefaultUnleashService(apiUrl = apiUrl, apiToken = apiToken, appName = appName, strategies = strategies)
} else {
logger.warn(
"Funksjonsbryter-funksjonalitet er skrudd AV. " +
Expand Down

0 comments on commit fb35472

Please sign in to comment.