From 0356fdfa41511681f2ba9acb3ccc9d3cb334c59e Mon Sep 17 00:00:00 2001 From: Jostein Holje Date: Fri, 1 Dec 2023 14:59:37 +0100 Subject: [PATCH] Bruk unleash-next --- .env-example | 2 +- build.gradle.kts | 4 +++- gradle.properties | 1 + src/main/kotlin/no/nav/paw/Application.kt | 4 ++-- src/main/kotlin/no/nav/paw/config/Config.kt | 11 +++++++---- .../consumers/ArbeidssokerRegistreringConsumer.kt | 4 ++-- .../kotlin/no/nav/paw/plugins/DependencyInjection.kt | 12 ++++-------- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.env-example b/.env-example index 658b816..8db0634 100644 --- a/.env-example +++ b/.env-example @@ -13,6 +13,6 @@ NAIS_DATABASE_PAW_ARBEIDSSOKER_PROFILERING_PROFILERING_USERNAME=admin NAIS_DATABASE_PAW_ARBEIDSSOKER_PROFILERING_PROFILERING_PASSWORD=admin AAREG_URL=http://localhost:8090/aareg AAREG_SCOPE=api://dev-gcp.paw.paw-arbeidssoker-profilering/.default -UNLEASH_URL=https://unleash.nais.io/api/ +UNLEASH_SERVER_API_URL=https://paw-unleash-api.nav.cloud.nais.io/api TOKEN_X_WELL_KNOWN_URL=http://localhost:8081/default/.well-known/openid-configuration TOKEN_X_CLIENT_ID=paw-arbeidssoker-profilering diff --git a/build.gradle.kts b/build.gradle.kts index ea250c4..f388df1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,6 +23,7 @@ val dotenv_kotlin_version: String by project val nocommons_version: String by project val mock_oauth2_server_version: String by project val avro_version: String by project +val unleash_version: String by project plugins { kotlin("jvm") version "1.8.10" @@ -98,7 +99,8 @@ dependencies { // NAV common implementation("no.nav.common:token-client:$nav_common_modules_version") implementation("no.nav.common:kafka:$nav_common_modules_version") - implementation("no.nav.common:feature-toggle:$nav_common_modules_version") + + implementation("io.getunleash:unleash-client-java:$unleash_version") // NAV security implementation("no.nav.security:token-validation-ktor-v2:$token_support_version") diff --git a/gradle.properties b/gradle.properties index 8f56f8d..df17094 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,6 +16,7 @@ dotenv_kotlin_version=6.4.1 nocommons_version=0.15.0 mock_oauth2_server_version=0.5.8 avro_version=1.11.0 +unleash_version=9.1.1 kotlin.code.style=official kotlin.incremental=true diff --git a/src/main/kotlin/no/nav/paw/Application.kt b/src/main/kotlin/no/nav/paw/Application.kt index c45c3c2..1119071 100644 --- a/src/main/kotlin/no/nav/paw/Application.kt +++ b/src/main/kotlin/no/nav/paw/Application.kt @@ -4,6 +4,8 @@ import io.ktor.server.application.Application import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import io.ktor.server.routing.routing +import javax.sql.DataSource +import kotlin.concurrent.thread import no.nav.paw.config.Config import no.nav.paw.config.migrateDatabase import no.nav.paw.kafka.consumers.ArbeidssokerRegistreringConsumer @@ -16,8 +18,6 @@ import no.nav.paw.routes.apiRoutes import no.nav.paw.routes.internalRoutes import no.nav.paw.routes.swaggerRoutes import org.koin.ktor.ext.inject -import javax.sql.DataSource -import kotlin.concurrent.thread fun main() { embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module) diff --git a/src/main/kotlin/no/nav/paw/config/Config.kt b/src/main/kotlin/no/nav/paw/config/Config.kt index 404665f..2dc19cc 100644 --- a/src/main/kotlin/no/nav/paw/config/Config.kt +++ b/src/main/kotlin/no/nav/paw/config/Config.kt @@ -2,6 +2,7 @@ package no.nav.paw.config import io.github.cdimascio.dotenv.dotenv import no.nav.security.token.support.v2.RequiredClaims +import io.getunleash.util.UnleashConfig val dotenv = dotenv { ignoreIfMissing = true } @@ -14,10 +15,12 @@ data class Config( dotenv["NAIS_DATABASE_PAW_ARBEIDSSOKER_PROFILERING_PROFILERING_PASSWORD"] ), val naisEnv: NaisEnv = NaisEnv.current(), - val unleashClientConfig: UnleashClientConfig = UnleashClientConfig( - dotenv["UNLEASH_URL"], - dotenv["NAIS_APP_NAME"] - ), + val unleashClientConfig: UnleashConfig = UnleashConfig.builder() + .appName(dotenv["NAIS_APP_NAME"]) + .instanceId(dotenv["NAIS_APP_NAME"]) + .unleashAPI(dotenv["UNLEASH_SERVER_API_URL"]) + .apiKey(dotenv["UNLEASH_SERVER_API_TOKEN"]) + .build(), val authentication: List = listOf( AuthProvider( name = "tokenx", diff --git a/src/main/kotlin/no/nav/paw/kafka/consumers/ArbeidssokerRegistreringConsumer.kt b/src/main/kotlin/no/nav/paw/kafka/consumers/ArbeidssokerRegistreringConsumer.kt index c13a024..5e05391 100644 --- a/src/main/kotlin/no/nav/paw/kafka/consumers/ArbeidssokerRegistreringConsumer.kt +++ b/src/main/kotlin/no/nav/paw/kafka/consumers/ArbeidssokerRegistreringConsumer.kt @@ -2,7 +2,7 @@ package no.nav.paw.kafka.consumers import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue -import no.nav.common.featuretoggle.UnleashClient +import io.getunleash.Unleash import no.nav.paw.domain.ArbeidssokerRegistrert import no.nav.paw.services.ProfileringService import no.nav.paw.utils.CallId.leggTilCallId @@ -14,7 +14,7 @@ class ArbeidssokerRegistreringConsumer( private val topic: String, private val consumer: KafkaConsumer, private val profileringService: ProfileringService, - private val unleashClient: UnleashClient, + private val unleashClient: Unleash, private val objectMapper: ObjectMapper ) { diff --git a/src/main/kotlin/no/nav/paw/plugins/DependencyInjection.kt b/src/main/kotlin/no/nav/paw/plugins/DependencyInjection.kt index 3567c65..18595b1 100644 --- a/src/main/kotlin/no/nav/paw/plugins/DependencyInjection.kt +++ b/src/main/kotlin/no/nav/paw/plugins/DependencyInjection.kt @@ -8,14 +8,12 @@ import com.fasterxml.jackson.module.kotlin.registerKotlinModule import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig import io.confluent.kafka.serializers.KafkaAvroSerializer import io.confluent.kafka.serializers.KafkaAvroSerializerConfig +import io.getunleash.Unleash import io.ktor.client.HttpClient import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.serialization.jackson.jackson import io.ktor.server.application.Application import io.ktor.server.application.install -import no.nav.common.featuretoggle.ByClusterStrategy -import no.nav.common.featuretoggle.UnleashClient -import no.nav.common.featuretoggle.UnleashClientImpl import no.nav.common.kafka.producer.util.KafkaProducerClientBuilder import no.nav.common.kafka.util.KafkaPropertiesBuilder import no.nav.common.kafka.util.KafkaPropertiesPreset @@ -59,11 +57,9 @@ fun Application.configureDependencyInjection(config: Config) { } } - single { - UnleashClientImpl( - config.unleashClientConfig.url, - config.unleashClientConfig.appName, - listOf(ByClusterStrategy()) + single { + UnleashDefault( + config.unleashClientConfig ) }