Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/actions/checkout-4
Browse files Browse the repository at this point in the history
  • Loading branch information
olekvernberg authored Sep 14, 2023
2 parents a42028e + c0c9f7d commit 6c851a3
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 188 deletions.
3 changes: 2 additions & 1 deletion .deploy/nais-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ spec:
rules:
- application: familie-ef-mottak
external:
- host: unleash.nais.io
- host: familie-integrasjoner.dev-fss-pub.nais.io
- host: pdl-api.dev-fss-pub.nais.io
- host: familie-ef-mottak.dev-fss-pub.nais.io
- host: teamfamilie-unleash-api.nav.cloud.nais.io
envFrom:
- secret: familie
- secret: ef-soknad-api
- secret: familie-ef-soknad-api-unleash-api-token
env:
- name: SPRING_PROFILES_ACTIVE
value: dev
3 changes: 2 additions & 1 deletion .deploy/nais-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ spec:
rules:
- application: familie-ef-mottak
external:
- host: unleash.nais.io
- host: familie-integrasjoner.prod-fss-pub.nais.io
- host: pdl-api.prod-fss-pub.nais.io
- host: familie-ef-mottak.prod-fss-pub.nais.io
- host: teamfamilie-unleash-api.nav.cloud.nais.io
envFrom:
- secret: familie
- secret: ef-soknad-api
- secret: familie-ef-soknad-api-unleash-api-token
env:
- name: SPRING_PROFILES_ACTIVE
value: prod
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<okhttp3.version>4.9.1</okhttp3.version> <!-- overskriver spring sin versjon, blir brukt av mock-oauth2-server -->

<fasterxml.version>2.15.2</fasterxml.version>
<felles.version>2.20230210162649_a258d57-SPRING_BOOT_3</felles.version>
<felles.version>2.20230905101454_06fa3d7</felles.version>
<kontrakter.version>3.0_20230509152247_36d24db</kontrakter.version>
<start-class>no.nav.familie.ef.søknad.ApplicationKt</start-class>
<!--suppress UnresolvedMavenProperty Ligger som secret i github-->
Expand Down Expand Up @@ -111,11 +111,6 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.getunleash</groupId>
<artifactId>unleash-client-java</artifactId>
<version>8.3.0</version>
</dependency>

<!-- Interne avhengigheter -->
<dependency>
Expand All @@ -128,6 +123,11 @@
<artifactId>http-client</artifactId>
<version>${felles.version}</version>
</dependency>
<dependency>
<groupId>no.nav.familie.felles</groupId>
<artifactId>unleash</artifactId>
<version>${felles.version}</version>
</dependency>
<dependency>
<groupId>no.nav.security</groupId>
<artifactId>token-validation-spring</artifactId>
Expand Down
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)
}
}
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)
}
}
6 changes: 1 addition & 5 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ health:
indicator:
detailed: true

funksjonsbrytere:
unleash:
enabled: true
unleash:
uri: https://unleash.nais.io/api/
environment: ${NAIS_CLUSTER_NAME:}
applicationName: ${NAIS_APP_NAME:}

management:
endpoint:
Expand Down

This file was deleted.

This file was deleted.

11 changes: 4 additions & 7 deletions src/test/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ familie:
mottak:
uri: http://localhost:8092/api

funksjonsbrytere:
enabled: false
unleash:
uri: http://localhost:4242/api
environment: local
applicationName: familie-ef-soknad-api

cors:
allowed_origins:
- "http://localhost:3000"
Expand Down Expand Up @@ -51,3 +44,7 @@ TOKEN_X_PRIVATE_JWK: '{
"kid" : "mock-oauth2-server-key",
"n" : ""
}'

UNLEASH_SERVER_API_URL: http://localhost:4242/api
UNLEASH_SERVER_API_TOKEN: token
NAIS_APP_NAME: familie-ef-mottak

0 comments on commit 6c851a3

Please sign in to comment.