-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/github_actions/actions/checkout-4
- Loading branch information
Showing
9 changed files
with
37 additions
and
188 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
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
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
81 changes: 13 additions & 68 deletions
81
src/main/kotlin/no/nav/familie/ef/søknad/config/FeatureToggleConfig.kt
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,81 +1,26 @@ | ||
package no.nav.familie.ef.søknad.config | ||
|
||
import io.getunleash.DefaultUnleash | ||
import io.getunleash.UnleashContext | ||
import io.getunleash.UnleashContextProvider | ||
import io.getunleash.util.UnleashConfig | ||
import io.getunleash.strategy.Strategy | ||
import no.nav.familie.ef.søknad.featuretoggle.ByEnvironmentStrategy | ||
import no.nav.familie.ef.søknad.featuretoggle.FeatureToggleService | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import no.nav.familie.unleash.DefaultUnleashService | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import java.net.URI | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@ConfigurationProperties("funksjonsbrytere") | ||
@Configuration | ||
class FeatureToggleConfig( | ||
private val enabled: Boolean, | ||
val unleash: Unleash, | ||
@Value("\${UNLEASH_SERVER_API_URL}") private val apiUrl: String, | ||
@Value("\${UNLEASH_SERVER_API_TOKEN}") private val apiToken: String, | ||
@Value("\${NAIS_APP_NAME}") private val appName: String, | ||
) { | ||
|
||
data class Unleash( | ||
val uri: URI, | ||
val environment: String, | ||
val applicationName: String, | ||
) | ||
|
||
private val log: Logger = LoggerFactory.getLogger(this::class.java) | ||
|
||
@Bean | ||
fun featureToggle(): FeatureToggleService = | ||
if (enabled) { | ||
lagUnleashFeatureToggleService() | ||
} else { | ||
log.warn( | ||
"Funksjonsbryter-funksjonalitet er skrudd AV. " + | ||
"Gir standardoppførsel for alle funksjonsbrytere, dvs 'false'", | ||
) | ||
lagDummyFeatureToggleService() | ||
} | ||
|
||
private fun lagUnleashFeatureToggleService(): FeatureToggleService { | ||
val unleash = DefaultUnleash( | ||
UnleashConfig.builder() | ||
.appName(unleash.applicationName) | ||
.unleashAPI(unleash.uri) | ||
.unleashContextProvider(lagUnleashContextProvider()) | ||
.build(), | ||
ByEnvironmentStrategy(), | ||
) | ||
|
||
return object : FeatureToggleService { | ||
override fun isEnabled(toggleId: String, defaultValue: Boolean): Boolean { | ||
return unleash.isEnabled(toggleId, defaultValue) | ||
} | ||
} | ||
fun strategies(): List<Strategy> { | ||
return listOf(ByEnvironmentStrategy()) | ||
} | ||
|
||
private fun lagUnleashContextProvider(): UnleashContextProvider { | ||
return UnleashContextProvider { | ||
UnleashContext.builder() | ||
// .userId("a user") // Må legges til en gang i fremtiden | ||
.environment(unleash.environment) | ||
.appName(unleash.applicationName) | ||
.build() | ||
} | ||
} | ||
|
||
private fun lagDummyFeatureToggleService(): FeatureToggleService { | ||
return object : FeatureToggleService { | ||
override fun isEnabled(toggleId: String, defaultValue: Boolean): Boolean { | ||
if (unleash.environment == "local") { | ||
return when (toggleId) { | ||
"familie.ef.soknad.feilsituasjon" -> false | ||
else -> true | ||
} | ||
} | ||
return defaultValue | ||
} | ||
} | ||
@Bean | ||
fun defaultUnleashService(strategies: List<Strategy>): DefaultUnleashService { | ||
return DefaultUnleashService(apiUrl, apiToken, appName, strategies) | ||
} | ||
} |
12 changes: 9 additions & 3 deletions
12
src/main/kotlin/no/nav/familie/ef/søknad/featuretoggle/FeatureToggleService.kt
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,10 +1,16 @@ | ||
package no.nav.familie.ef.søknad.featuretoggle | ||
|
||
interface FeatureToggleService { | ||
import no.nav.familie.unleash.DefaultUnleashService | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class FeatureToggleService(val defaultUnleashService: DefaultUnleashService) { | ||
|
||
fun isEnabled(toggleId: String): Boolean { | ||
return isEnabled(toggleId, false) | ||
return defaultUnleashService.isEnabled(toggleId) | ||
} | ||
|
||
fun isEnabled(toggleId: String, defaultValue: Boolean): Boolean | ||
fun isEnabled(toggleId: String, defaultValue: Boolean): Boolean { | ||
return defaultUnleashService.isEnabled(toggleId, defaultValue) | ||
} | ||
} |
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
55 changes: 0 additions & 55 deletions
55
src/test/kotlin/no/nav/familie/ef/søknad/api/FeatureToggleControllerIntegrationTest.kt
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
src/test/kotlin/no/nav/familie/ef/søknad/api/FeatureToggleControllerTest.kt
This file was deleted.
Oops, something went wrong.
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