diff --git a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/Application.kt b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/Application.kt index d6f179e9..eb7ae4f9 100644 --- a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/Application.kt +++ b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/Application.kt @@ -19,6 +19,8 @@ import no.nav.paw.bekreftelse.api.plugins.configureTracing import no.nav.paw.bekreftelse.api.routes.bekreftelseRoutes import no.nav.paw.bekreftelse.api.routes.metricsRoutes import no.nav.paw.bekreftelse.api.routes.swaggerRoutes +import no.nav.paw.config.env.appNameOrDefaultForLocal +import no.nav.paw.config.env.currentRuntimeEnvironment import no.nav.paw.config.hoplite.loadNaisOrLocalConfiguration import no.nav.paw.health.route.healthRoutes import org.slf4j.LoggerFactory @@ -29,7 +31,7 @@ fun main() { val applicationConfig = loadNaisOrLocalConfiguration(APPLICATION_CONFIG_FILE_NAME) val serverConfig = loadNaisOrLocalConfiguration(SERVER_CONFIG_FILE_NAME) - logger.info("Starter: ${applicationConfig.appId}") + logger.info("Starter: ${currentRuntimeEnvironment.appNameOrDefaultForLocal()}") val dependencies = createDependencies(applicationConfig) diff --git a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/Dependencies.kt b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/Dependencies.kt index 3da02b27..13cdbd1e 100644 --- a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/Dependencies.kt +++ b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/Dependencies.kt @@ -20,7 +20,7 @@ import no.nav.poao_tilgang.client.PoaoTilgangHttpClient import org.apache.kafka.streams.KafkaStreams fun createDependencies(applicationConfig: ApplicationConfig): Dependencies { - val azureM2MTokenClient = azureAdM2MTokenClient(applicationConfig.naisEnv, applicationConfig.azureM2M) + val azureM2MTokenClient = azureAdM2MTokenClient(applicationConfig.runtimeEnvironment, applicationConfig.azureM2M) val kafkaKeysClient = kafkaKeysClient(applicationConfig.kafkaKeysClient) { azureM2MTokenClient.createMachineToMachineToken(applicationConfig.kafkaKeysClient.scope) diff --git a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/config/ApplicationConfig.kt b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/config/ApplicationConfig.kt index a5c404f7..90e259d9 100644 --- a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/config/ApplicationConfig.kt +++ b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/config/ApplicationConfig.kt @@ -1,9 +1,7 @@ package no.nav.paw.bekreftelse.api.config -import no.nav.paw.config.env.NaisEnv -import no.nav.paw.config.env.currentAppId -import no.nav.paw.config.env.currentAppName -import no.nav.paw.config.env.currentNaisEnv +import no.nav.paw.config.env.RuntimeEnvironment +import no.nav.paw.config.env.currentRuntimeEnvironment import no.nav.paw.config.kafka.KafkaConfig import no.nav.paw.kafkakeygenerator.auth.AzureM2MConfig import no.nav.paw.kafkakeygenerator.client.KafkaKeyConfig @@ -20,9 +18,7 @@ data class ApplicationConfig( val kafkaKeysClient: KafkaKeyConfig, val kafkaClients: KafkaConfig, // Env - val naisEnv: NaisEnv = currentNaisEnv, - val appId: String = currentAppId ?: "UNSPECIFIED", - val appName: String = currentAppName ?: "UNSPECIFIED", + val runtimeEnvironment: RuntimeEnvironment = currentRuntimeEnvironment, val hostname: String = InetAddress.getLocalHost().hostName ) diff --git a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/model/BekreftelseRequest.kt b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/model/BekreftelseRequest.kt index c6990bf1..925f8b22 100644 --- a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/model/BekreftelseRequest.kt +++ b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/model/BekreftelseRequest.kt @@ -5,7 +5,9 @@ import no.nav.paw.bekreftelse.melding.v1.vo.Bruker import no.nav.paw.bekreftelse.melding.v1.vo.BrukerType import no.nav.paw.bekreftelse.melding.v1.vo.Metadata import no.nav.paw.bekreftelse.melding.v1.vo.Svar -import no.nav.paw.config.env.currentAppName +import no.nav.paw.config.env.appImageOrDefaultForLocal +import no.nav.paw.config.env.currentRuntimeEnvironment +import no.nav.paw.config.env.namespaceOrDefaultForLocal import java.time.Instant import java.util.* @@ -23,7 +25,7 @@ fun BekreftelseRequest.toHendelse( brukerId: String, brukerType: BrukerType ) = Bekreftelse.newBuilder() - .setNamespace("paw") // TODO Hente fra config? + .setNamespace(currentRuntimeEnvironment.namespaceOrDefaultForLocal()) .setId(bekreftelseId) .setPeriodeId(periodeId) .setSvar( @@ -36,7 +38,7 @@ fun BekreftelseRequest.toHendelse( .setType(brukerType) .build() ) - .setKilde(currentAppName) + .setKilde(currentRuntimeEnvironment.appImageOrDefaultForLocal()) .setTidspunkt(Instant.now()) .build() ) diff --git a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/plugins/HTTP.kt b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/plugins/HTTP.kt index e2a69c80..6f9aeca4 100644 --- a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/plugins/HTTP.kt +++ b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/plugins/HTTP.kt @@ -10,7 +10,8 @@ import io.ktor.server.plugins.statuspages.StatusPages import io.ktor.server.routing.IgnoreTrailingSlash import no.nav.paw.bekreftelse.api.config.ApplicationConfig import no.nav.paw.bekreftelse.api.config.AutorisasjonConfig -import no.nav.paw.config.env.NaisEnv +import no.nav.paw.config.env.Local +import no.nav.paw.config.env.Nais import no.nav.paw.error.handler.handleException fun Application.configureHTTP(applicationConfig: ApplicationConfig) { @@ -23,16 +24,12 @@ fun Application.configureHTTP(applicationConfig: ApplicationConfig) { install(CORS) { val origins = applicationConfig.autorisasjon.getCorsAllowOrigins() - when (applicationConfig.naisEnv) { - NaisEnv.ProdGCP -> { + when (applicationConfig.runtimeEnvironment) { + is Nais -> { origins.forEach { allowHost(it) } } - NaisEnv.DevGCP -> { - origins.forEach { allowHost(it) } - } - - NaisEnv.Local -> anyHost() + is Local -> anyHost() } allowMethod(HttpMethod.Options) diff --git a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/utils/KafkaSerialization.kt b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/utils/KafkaSerialization.kt index f61ce85b..76fd01c2 100644 --- a/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/utils/KafkaSerialization.kt +++ b/apps/bekreftelse-api/src/main/kotlin/no/nav/paw/bekreftelse/api/utils/KafkaSerialization.kt @@ -6,48 +6,49 @@ import com.fasterxml.jackson.module.kotlin.readValue import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde import no.nav.paw.bekreftelse.api.model.InternState import no.nav.paw.bekreftelse.melding.v1.Bekreftelse -import no.nav.paw.config.env.NaisEnv -import no.nav.paw.config.env.currentNaisEnv +import no.nav.paw.config.env.ProdGcp +import no.nav.paw.config.env.RuntimeEnvironment +import no.nav.paw.config.env.currentRuntimeEnvironment import org.apache.kafka.common.serialization.Deserializer import org.apache.kafka.common.serialization.Serde import org.apache.kafka.common.serialization.Serializer -inline fun buildJsonSerializer(naisEnv: NaisEnv, objectMapper: ObjectMapper) = object : Serializer { +inline fun buildJsonSerializer(runtimeEnvironment: RuntimeEnvironment, objectMapper: ObjectMapper) = object : Serializer { override fun serialize(topic: String?, data: T): ByteArray { if (data == null) return byteArrayOf() try { return objectMapper.writeValueAsBytes(data) } catch (e: Exception) { - if (naisEnv == NaisEnv.ProdGCP && e is JsonProcessingException) e.clearLocation() + if (runtimeEnvironment is ProdGcp && e is JsonProcessingException) e.clearLocation() throw e } } } -inline fun buildJsonDeserializer(naisEnv: NaisEnv, objectMapper: ObjectMapper) = object : Deserializer { +inline fun buildJsonDeserializer(runtimeEnvironment: RuntimeEnvironment, objectMapper: ObjectMapper) = object : Deserializer { override fun deserialize(topic: String?, data: ByteArray?): T? { if (data == null) return null try { return objectMapper.readValue(data) } catch (e: Exception) { - if (naisEnv == NaisEnv.ProdGCP && e is JsonProcessingException) e.clearLocation() + if (runtimeEnvironment is ProdGcp && e is JsonProcessingException) e.clearLocation() throw e } } } -inline fun buildJsonSerde(naisEnv: NaisEnv, objectMapper: ObjectMapper) = object : Serde { +inline fun buildJsonSerde(runtimeEnvironment: RuntimeEnvironment, objectMapper: ObjectMapper) = object : Serde { override fun serializer(): Serializer { - return buildJsonSerializer(naisEnv, objectMapper) + return buildJsonSerializer(runtimeEnvironment, objectMapper) } override fun deserializer(): Deserializer { - return buildJsonDeserializer(naisEnv, objectMapper) + return buildJsonDeserializer(runtimeEnvironment, objectMapper) } } inline fun buildJsonSerde(): Serde { - return buildJsonSerde(currentNaisEnv, buildObjectMapper) + return buildJsonSerde(currentRuntimeEnvironment, buildObjectMapper) } fun buildInternStateSerde() = buildJsonSerde() diff --git a/apps/hendelselogg-backup/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/backup/brukerstoette/HttpClients.kt b/apps/hendelselogg-backup/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/backup/brukerstoette/HttpClients.kt index 753097fb..815a70d5 100644 --- a/apps/hendelselogg-backup/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/backup/brukerstoette/HttpClients.kt +++ b/apps/hendelselogg-backup/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/backup/brukerstoette/HttpClients.kt @@ -6,7 +6,7 @@ import io.ktor.client.HttpClient import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.serialization.jackson.jackson import no.nav.common.token_client.client.AzureAdMachineToMachineTokenClient -import no.nav.paw.config.env.currentNaisEnv +import no.nav.paw.config.env.currentRuntimeEnvironment import no.nav.paw.config.hoplite.loadNaisOrLocalConfiguration import no.nav.paw.kafkakeygenerator.auth.AzureM2MConfig import no.nav.paw.kafkakeygenerator.auth.azureAdM2MTokenClient @@ -14,7 +14,7 @@ import no.nav.paw.kafkakeygenerator.client.KafkaKeysClient import no.nav.paw.kafkakeygenerator.client.createKafkaKeyGeneratorClient fun initClients(azureConfig: AzureM2MConfig): Pair { - val azureTokenClient = azureAdM2MTokenClient(currentNaisEnv, azureConfig) + val azureTokenClient = azureAdM2MTokenClient(currentRuntimeEnvironment, azureConfig) val kafkaKeysClient = createKafkaKeyGeneratorClient(azureTokenClient) val oppslagApiClient = oppslagsApiClient(azureTokenClient) return kafkaKeysClient to oppslagApiClient diff --git a/apps/hendelselogg-backup/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/backup/initKtor.kt b/apps/hendelselogg-backup/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/backup/initKtor.kt index 431ce951..e556138e 100644 --- a/apps/hendelselogg-backup/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/backup/initKtor.kt +++ b/apps/hendelselogg-backup/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/backup/initKtor.kt @@ -23,8 +23,8 @@ import no.nav.paw.arbeidssoekerregisteret.backup.api.brukerstoette.models.Feil import no.nav.paw.arbeidssoekerregisteret.backup.brukerstoette.BrukerstoetteService import no.nav.paw.arbeidssoekerregisteret.backup.health.configureHealthRoutes import no.nav.paw.arbeidssoekerregisteret.backup.health.installMetrics -import no.nav.paw.config.env.NaisEnv -import no.nav.paw.config.env.currentNaisEnv +import no.nav.paw.config.env.ProdGcp +import no.nav.paw.config.env.currentRuntimeEnvironment import no.nav.security.token.support.v2.IssuerConfig import no.nav.security.token.support.v2.TokenSupportConfig import no.nav.security.token.support.v2.TokenValidationContextPrincipal @@ -50,7 +50,7 @@ fun initKtor( routing { swaggerUI(path = "docs/brukerstoette", swaggerFile = "openapi/Brukerstoette.yaml") configureHealthRoutes(prometheusMeterRegistry) - if (currentNaisEnv == NaisEnv.ProdGCP) { + if (currentRuntimeEnvironment is ProdGcp) { authenticate("azure") { configureBrukerstoetteRoutes(brukerstoetteService) } diff --git a/apps/utgang-formidlingsgruppe/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/app/Startup.kt b/apps/utgang-formidlingsgruppe/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/app/Startup.kt index d0622894..c2b079b0 100644 --- a/apps/utgang-formidlingsgruppe/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/app/Startup.kt +++ b/apps/utgang-formidlingsgruppe/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/app/Startup.kt @@ -7,8 +7,9 @@ import io.micrometer.prometheusmetrics.PrometheusMeterRegistry import kotlinx.coroutines.runBlocking import no.nav.paw.arbeidssokerregisteret.app.helse.Helse import no.nav.paw.arbeidssokerregisteret.app.helse.initKtor -import no.nav.paw.config.env.NaisEnv -import no.nav.paw.config.env.currentNaisEnv +import no.nav.paw.config.env.ProdGcp +import no.nav.paw.config.env.RuntimeEnvironment +import no.nav.paw.config.env.currentRuntimeEnvironment import no.nav.paw.config.hoplite.loadNaisOrLocalConfiguration import no.nav.paw.config.kafka.KafkaConfig import no.nav.paw.config.kafka.streams.KafkaStreamsFactory @@ -31,8 +32,8 @@ val applicationConfiguration: ApplicationConfiguration get() = typealias kafkaKeyFunction = (String) -> KafkaKeysResponse? -fun formidlingsGruppeTopic(env: NaisEnv) = - "teamarenanais.aapen-arena-formidlingsgruppeendret-v1-${if (env == NaisEnv.ProdGCP) "p" else "q"}" +fun formidlingsGruppeTopic(env: RuntimeEnvironment) = + "teamarenanais.aapen-arena-formidlingsgruppeendret-v1-${if (env is ProdGcp) "p" else "q"}" fun main() { val logger = LoggerFactory.getLogger("app") @@ -64,7 +65,7 @@ fun main() { "aktivePerioder", idAndRecordKeyFunction, periodeTopic, - formidlingsGruppeTopic(currentNaisEnv), + formidlingsGruppeTopic(currentRuntimeEnvironment), appCfg.hendelseloggTopic ) val kafkaStreams = KafkaStreams( diff --git a/apps/utgang-pdl/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/utgang/pdl/clients/pdl/PdlClient.kt b/apps/utgang-pdl/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/utgang/pdl/clients/pdl/PdlClient.kt index b99fba04..4cbeca35 100644 --- a/apps/utgang-pdl/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/utgang/pdl/clients/pdl/PdlClient.kt +++ b/apps/utgang-pdl/src/main/kotlin/no/nav/paw/arbeidssoekerregisteret/utgang/pdl/clients/pdl/PdlClient.kt @@ -4,7 +4,7 @@ import io.ktor.client.HttpClient import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.serialization.jackson.jackson import kotlinx.coroutines.runBlocking -import no.nav.paw.config.env.currentNaisEnv +import no.nav.paw.config.env.currentRuntimeEnvironment import no.nav.paw.config.hoplite.loadNaisOrLocalConfiguration import no.nav.paw.kafkakeygenerator.auth.AzureM2MConfig import no.nav.paw.kafkakeygenerator.auth.azureAdM2MTokenClient @@ -65,7 +65,7 @@ fun interface PdlHentForenkletStatus { private fun createPdlClient(): PdlClient { val azureM2MConfig = loadNaisOrLocalConfiguration("azure_m2m.toml") - val m2mTokenClient = azureAdM2MTokenClient(currentNaisEnv, azureM2MConfig) + val m2mTokenClient = azureAdM2MTokenClient(currentRuntimeEnvironment, azureM2MConfig) val pdlConfig = loadNaisOrLocalConfiguration(PDL_CONFIG_FILE) return PdlClient(pdlConfig.url, pdlConfig.tema, createHttpClient()) { diff --git a/lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/NaisEnv.kt b/lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/NaisEnv.kt deleted file mode 100644 index 53392bf5..00000000 --- a/lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/NaisEnv.kt +++ /dev/null @@ -1,33 +0,0 @@ -package no.nav.paw.config.env - -enum class NaisEnv( - val clusterName: String, - val namespace: String?, - val appName: String? -) { - Local("local", "local-namespace", "local-app"), - DevGCP( - clusterName = "dev-gcp", - namespace = currentNamespace, - appName = currentAppName - ), - ProdGCP( - clusterName = "prod-gcp", - namespace = currentNamespace, - appName = currentAppName - ) -} - -val currentNaisEnv: NaisEnv - get() = - when (System.getenv("NAIS_CLUSTER_NAME")) { - NaisEnv.DevGCP.clusterName -> NaisEnv.DevGCP - NaisEnv.ProdGCP.clusterName -> NaisEnv.ProdGCP - else -> NaisEnv.Local - } - -val currentAppId: String? get() = System.getenv("NAIS_APP_IMAGE") // F.eks. europe-north1-docker.pkg.dev/nais-management-233d/paw/paw-microfrontend-toggler:24.06.27.57-1 - -val currentAppName: String? get() = System.getenv("NAIS_APP_NAME") // F.eks. paw-microfrontend-toggler - -val currentNamespace: String? get() = System.getenv("NAIS_NAMESPACE") \ No newline at end of file diff --git a/lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/RuntimeEnvironment.kt b/lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/RuntimeEnvironment.kt new file mode 100644 index 00000000..5babb993 --- /dev/null +++ b/lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/RuntimeEnvironment.kt @@ -0,0 +1,52 @@ +package no.nav.paw.config.env + +sealed interface RuntimeEnvironment + +data object Local : RuntimeEnvironment + +sealed interface Nais : RuntimeEnvironment { + val clusterName: String + val namespace: String + val appName: String + val appImage: String +} +sealed interface DevGcp : Nais + +sealed interface ProdGcp : Nais + + +private class DevGCPImpl( + override val clusterName: String, + override val namespace: String, + override val appName: String, + override val appImage: String +) : DevGcp + +private class ProdGCPImpl( + override val clusterName: String, + override val namespace: String, + override val appName: String, + override val appImage: String +) : ProdGcp + +const val NAIS_PROD_CLUSER_NAME = "prod-gcp" +const val NAIS_DEV_CLUSER_NAME = "dev-gcp" + +val currentRuntimeEnvironment: RuntimeEnvironment = currentRuntimeEnvironment() + +private fun currentRuntimeEnvironment(): RuntimeEnvironment { + val namespace = { currentNamespace ?: error("NAIS_NAMESPACE is not set") } + val appName = { currentAppName ?: error("NAIS_APP_NAME is not set") } + val appImage = { currentAppImage ?: error("NAIS_APP_IMAGE is not set") } + return when (val clusterName = System.getenv("NAIS_CLUSTER_NAME")) { + NAIS_PROD_CLUSER_NAME -> ProdGCPImpl(clusterName, namespace(), appName(), appImage()) + NAIS_DEV_CLUSER_NAME -> DevGCPImpl(clusterName, namespace(), appName(), appImage()) + else -> Local + } +} + +private val currentAppImage: String? get() = System.getenv("NAIS_APP_IMAGE") // F.eks. europe-north1-docker.pkg.dev/nais-management-233d/paw/paw-microfrontend-toggler:24.06.27.57-1 + +private val currentAppName: String? get() = System.getenv("NAIS_APP_NAME") // F.eks. paw-microfrontend-toggler + +private val currentNamespace: String? get() = System.getenv("NAIS_NAMESPACE") \ No newline at end of file diff --git a/lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/RuntimeEnvironmentExtensions.kt b/lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/RuntimeEnvironmentExtensions.kt new file mode 100644 index 00000000..b0c39200 --- /dev/null +++ b/lib/hoplite-config/src/main/kotlin/no/nav/paw/config/env/RuntimeEnvironmentExtensions.kt @@ -0,0 +1,21 @@ +package no.nav.paw.config.env + +fun RuntimeEnvironment.namespaceOrDefaultForLocal(default: String = "local-namespace") = when (this) { + is Nais -> namespace + else -> default +} + +fun RuntimeEnvironment.clusterNameOrDefaultForLocal(default: String = "local") = when (this) { + is Nais -> clusterName + else -> default +} + +fun RuntimeEnvironment.appNameOrDefaultForLocal(default: String = "local-app") = when (this) { + is Nais -> appName + else -> default +} + +fun RuntimeEnvironment.appImageOrDefaultForLocal(default: String = "local-image") = when (this) { + is Nais -> appImage + else -> default +} \ No newline at end of file diff --git a/lib/kafka-key-generator-client/src/main/kotlin/no/nav/paw/kafkakeygenerator/auth/AzureAdMachineToMachineTokenClientFactory.kt b/lib/kafka-key-generator-client/src/main/kotlin/no/nav/paw/kafkakeygenerator/auth/AzureAdMachineToMachineTokenClientFactory.kt index c7277d74..3f2f4e80 100644 --- a/lib/kafka-key-generator-client/src/main/kotlin/no/nav/paw/kafkakeygenerator/auth/AzureAdMachineToMachineTokenClientFactory.kt +++ b/lib/kafka-key-generator-client/src/main/kotlin/no/nav/paw/kafkakeygenerator/auth/AzureAdMachineToMachineTokenClientFactory.kt @@ -5,14 +5,15 @@ import com.nimbusds.jose.jwk.RSAKey import no.nav.common.token_client.builder.AzureAdTokenClientBuilder import no.nav.common.token_client.cache.CaffeineTokenCache import no.nav.common.token_client.client.AzureAdMachineToMachineTokenClient -import no.nav.paw.config.env.NaisEnv +import no.nav.paw.config.env.Local +import no.nav.paw.config.env.RuntimeEnvironment import java.security.KeyPairGenerator import java.security.interfaces.RSAPrivateKey import java.security.interfaces.RSAPublicKey -fun azureAdM2MTokenClient(naisEnv: NaisEnv, azureProviderConfig: AzureM2MConfig): AzureAdMachineToMachineTokenClient = - when (naisEnv) { - NaisEnv.Local -> AzureAdTokenClientBuilder.builder() +fun azureAdM2MTokenClient(runtimeEnvironment: RuntimeEnvironment, azureProviderConfig: AzureM2MConfig): AzureAdMachineToMachineTokenClient = + when (runtimeEnvironment) { + is Local -> AzureAdTokenClientBuilder.builder() .withClientId(azureProviderConfig.clientId) .withPrivateJwk(createMockRSAKey("azure")) .withTokenEndpointUrl(azureProviderConfig.tokenEndpointUrl) diff --git a/lib/kafka-key-generator-client/src/main/kotlin/no/nav/paw/kafkakeygenerator/client/Factory.kt b/lib/kafka-key-generator-client/src/main/kotlin/no/nav/paw/kafkakeygenerator/client/Factory.kt index b091bd76..de38cf71 100644 --- a/lib/kafka-key-generator-client/src/main/kotlin/no/nav/paw/kafkakeygenerator/client/Factory.kt +++ b/lib/kafka-key-generator-client/src/main/kotlin/no/nav/paw/kafkakeygenerator/client/Factory.kt @@ -4,7 +4,7 @@ import io.ktor.client.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.serialization.jackson.* import no.nav.common.token_client.client.AzureAdMachineToMachineTokenClient -import no.nav.paw.config.env.currentNaisEnv +import no.nav.paw.config.env.currentRuntimeEnvironment import no.nav.paw.config.hoplite.loadNaisOrLocalConfiguration import no.nav.paw.kafkakeygenerator.auth.AzureM2MConfig import no.nav.paw.kafkakeygenerator.auth.azureAdM2MTokenClient @@ -12,7 +12,7 @@ import no.nav.paw.kafkakeygenerator.auth.azureAdM2MTokenClient fun createKafkaKeyGeneratorClient(m2mTokenClient: AzureAdMachineToMachineTokenClient? = null): KafkaKeysClient { val kafkaKeyConfig = loadNaisOrLocalConfiguration("kafka_key_generator_client_config.toml") val m2mTC = m2mTokenClient ?: azureAdM2MTokenClient( - currentNaisEnv, + currentRuntimeEnvironment, loadNaisOrLocalConfiguration("azure_m2m.toml") ) return kafkaKeysClient(kafkaKeyConfig) {