Skip to content

Commit

Permalink
Omdøping av all kode for bekreftelse-API
Browse files Browse the repository at this point in the history
  • Loading branch information
naviktthomas committed Sep 11, 2024
1 parent 1aabe24 commit 0d3e426
Show file tree
Hide file tree
Showing 44 changed files with 413 additions and 288 deletions.
106 changes: 106 additions & 0 deletions apps/bekreftelse-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("org.openapi.generator")
id("com.google.cloud.tools.jib")
application
}

val jvmMajorVersion: String by project
val baseImage: String by project
val image: String? by project

dependencies {
// Project
implementation(project(":lib:hoplite-config"))
implementation(project(":lib:kafka-streams"))
implementation(project(":lib:kafka-key-generator-client"))
implementation(project(":domain:bekreftelse-interne-hendelser"))
implementation(project(":domain:bekreftelsesmelding-schema"))

// Server
implementation(ktorServer.bundles.withNettyAndMicrometer)
implementation(ktorServer.contentNegotiation)
implementation(ktorServer.statusPages)
implementation(ktorServer.cors)
implementation(ktorServer.callId)
implementation(ktorServer.auth)

// Client
implementation(ktorClient.core)
implementation(ktorClient.cio)
implementation(ktorClient.contentNegotiation)

// Serialization
implementation(ktor.serializationJackson)
implementation(ktor.serializationJson)
implementation(jackson.datatypeJsr310)

// Authentication
implementation(navSecurity.tokenValidationKtorV2)

// Authorization
implementation(poao.tilgangClient)

// Documentation
implementation(ktorServer.swagger)

// Logging
implementation(loggingLibs.logbackClassic)
implementation(loggingLibs.logstashLogbackEncoder)
implementation(navCommon.log)
implementation(navCommon.auditLog)

// Instrumentation
implementation(micrometer.registryPrometheus)
implementation(otel.api)
implementation(otel.annotations)

// Kafka
implementation(orgApacheKafka.kafkaStreams)
implementation(apacheAvro.kafkaStreamsAvroSerde)

// Test
testImplementation(ktorServer.testJvm)
testImplementation(testLibs.bundles.withUnitTesting)
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(jvmMajorVersion))
}
}

application {
mainClass.set("no.nav.paw.rapportering.api.ApplicationKt")
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
freeCompilerArgs.add("-Xcontext-receivers")
}
}

tasks.withType(Jar::class) {
manifest {
attributes["Implementation-Version"] = project.version
attributes["Main-Class"] = application.mainClass.get()
attributes["Implementation-Title"] = rootProject.name
}
}

jib {
from.image = "$baseImage:$jvmMajorVersion"
to.image = "${image ?: project.name}:${project.version}"
container {
environment = mapOf(
"IMAGE_WITH_VERSION" to "${image ?: project.name}:${project.version}"
)
jvmFlags = listOf("-XX:ActiveProcessorCount=4", "-XX:+UseZGC", "-XX:+ZGenerational")
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.paw.rapportering.api
package no.nav.paw.bekreftelse.api

import io.ktor.server.application.Application
import io.ktor.server.engine.addShutdownHook
Expand All @@ -11,17 +11,17 @@ import no.nav.paw.config.kafka.KAFKA_STREAMS_CONFIG_WITH_SCHEME_REG
import no.nav.paw.config.kafka.KafkaConfig
import no.nav.paw.kafkakeygenerator.auth.AzureM2MConfig
import no.nav.paw.kafkakeygenerator.client.KafkaKeyConfig
import no.nav.paw.rapportering.api.config.APPLICATION_CONFIG_FILE_NAME
import no.nav.paw.rapportering.api.config.ApplicationConfig
import no.nav.paw.rapportering.api.plugins.configureAuthentication
import no.nav.paw.rapportering.api.plugins.configureHTTP
import no.nav.paw.rapportering.api.plugins.configureLogging
import no.nav.paw.rapportering.api.plugins.configureMetrics
import no.nav.paw.rapportering.api.plugins.configureOtel
import no.nav.paw.rapportering.api.plugins.configureSerialization
import no.nav.paw.rapportering.api.routes.healthRoutes
import no.nav.paw.rapportering.api.routes.rapporteringRoutes
import no.nav.paw.rapportering.api.routes.swaggerRoutes
import no.nav.paw.bekreftelse.api.config.APPLICATION_CONFIG_FILE_NAME
import no.nav.paw.bekreftelse.api.config.ApplicationConfig
import no.nav.paw.bekreftelse.api.plugins.configureAuthentication
import no.nav.paw.bekreftelse.api.plugins.configureHTTP
import no.nav.paw.bekreftelse.api.plugins.configureLogging
import no.nav.paw.bekreftelse.api.plugins.configureMetrics
import no.nav.paw.bekreftelse.api.plugins.configureOtel
import no.nav.paw.bekreftelse.api.plugins.configureSerialization
import no.nav.paw.bekreftelse.api.routes.healthRoutes
import no.nav.paw.bekreftelse.api.routes.bekreftelseRoutes
import no.nav.paw.bekreftelse.api.routes.swaggerRoutes
import org.slf4j.LoggerFactory

fun main() {
Expand Down Expand Up @@ -64,13 +64,13 @@ fun Application.module(
routing {
healthRoutes(dependencies.prometheusMeterRegistry, dependencies.health)
swaggerRoutes()
rapporteringRoutes(
kafkaKeyClient = dependencies.kafkaKeyClient,
rapporteringStateStore = dependencies.rapporteringStateStore,
rapporteringStateStoreName = applicationConfig.rapporteringStateStoreName,
bekreftelseRoutes(
kafkaKeyClient = dependencies.kafkaKeysClient,
bekreftelseStateStore = dependencies.bekreftelseStateStore,
stateStoreName = applicationConfig.bekreftelseStateStoreName,
kafkaStreams = dependencies.kafkaStreams,
httpClient = dependencies.httpClient,
rapporteringProducer = dependencies.rapporteringProducer,
bekreftelseProducer = dependencies.bekreftelseProducer,
autorisasjonService = dependencies.autorisasjonService
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.paw.rapportering.api
package no.nav.paw.bekreftelse.api

object ApplicationInfo {
val id = System.getenv("IMAGE_WITH_VERSION") ?: "UNSPECIFIED"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package no.nav.paw.rapportering.api
package no.nav.paw.bekreftelse.api

import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
import io.ktor.client.HttpClient
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.serialization.jackson.jackson
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import io.micrometer.prometheusmetrics.PrometheusConfig
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import no.nav.paw.config.kafka.KafkaConfig
import no.nav.paw.config.kafka.streams.KafkaStreamsFactory
import no.nav.paw.kafkakeygenerator.auth.AzureM2MConfig
import no.nav.paw.kafkakeygenerator.auth.azureAdM2MTokenClient
import no.nav.paw.kafkakeygenerator.client.KafkaKeyConfig
import no.nav.paw.kafkakeygenerator.client.KafkaKeysClient
import no.nav.paw.kafkakeygenerator.client.kafkaKeysKlient
import no.nav.paw.rapportering.api.config.ApplicationConfig
import no.nav.paw.rapportering.api.kafka.RapporteringProducer
import no.nav.paw.rapportering.api.kafka.RapporteringTilgjengeligState
import no.nav.paw.rapportering.api.kafka.RapporteringTilgjengeligStateSerde
import no.nav.paw.rapportering.api.kafka.appTopology
import no.nav.paw.rapportering.api.services.AutorisasjonService
import no.nav.paw.kafkakeygenerator.client.kafkaKeysClient
import no.nav.paw.bekreftelse.api.config.ApplicationConfig
import no.nav.paw.bekreftelse.api.kafka.BekreftelseProducer
import no.nav.paw.bekreftelse.api.kafka.InternState
import no.nav.paw.bekreftelse.api.kafka.InternStateSerde
import no.nav.paw.bekreftelse.api.kafka.appTopology
import no.nav.paw.bekreftelse.api.services.AutorisasjonService
import no.nav.poao_tilgang.client.PoaoTilgangCachedClient
import no.nav.poao_tilgang.client.PoaoTilgangHttpClient
import org.apache.kafka.common.serialization.Serdes
Expand All @@ -41,7 +41,8 @@ fun createDependencies(
val logger = LoggerFactory.getLogger("rapportering-api")

val azureM2MTokenClient = azureAdM2MTokenClient(applicationConfig.naisEnv, azureM2MConfig)
val kafkaKeyClient = kafkaKeysKlient(kafkaKeyConfig) {

val kafkaKeysClient = kafkaKeysClient(kafkaKeyConfig) {
azureM2MTokenClient.createMachineToMachineToken(kafkaKeyConfig.scope)
}

Expand All @@ -60,16 +61,16 @@ fun createDependencies(
val streamsBuilder = StreamsBuilder()
.addStateStore(
Stores.keyValueStoreBuilder(
Stores.persistentKeyValueStore(applicationConfig.rapporteringStateStoreName),
Stores.persistentKeyValueStore(applicationConfig.bekreftelseStateStoreName),
Serdes.Long(),
RapporteringTilgjengeligStateSerde(),
InternStateSerde(),
)
)

val topology = streamsBuilder.appTopology(
prometheusRegistry = prometheusMeterRegistry,
rapporteringHendelseLoggTopic = applicationConfig.rapporteringHendelseLoggTopic,
rapporteringStateStoreName = applicationConfig.rapporteringStateStoreName,
bekreftelseHendelseLoggTopic = applicationConfig.bekreftelseHendelseLoggTopic,
bekreftelseStateStoreName = applicationConfig.bekreftelseStateStoreName,
)

val kafkaStreams = KafkaStreams(
Expand All @@ -86,16 +87,16 @@ fun createDependencies(

kafkaStreams.start()

val rapporteringStateStore: ReadOnlyKeyValueStore<Long, RapporteringTilgjengeligState> = kafkaStreams.store(
val bekreftelseStateStore: ReadOnlyKeyValueStore<Long, InternState> = kafkaStreams.store(
StoreQueryParameters.fromNameAndType(
applicationConfig.rapporteringStateStoreName,
applicationConfig.bekreftelseStateStoreName,
QueryableStoreTypes.keyValueStore()
)
)

val health = Health(kafkaStreams)

val rapporteringProducer = RapporteringProducer(kafkaConfig, applicationConfig)
val bekreftelseProducer = BekreftelseProducer(kafkaConfig, applicationConfig)


val poaoTilgangClient = PoaoTilgangCachedClient(
Expand All @@ -108,24 +109,24 @@ fun createDependencies(
val autorisasjonService = AutorisasjonService(poaoTilgangClient)

return Dependencies(
kafkaKeyClient,
kafkaKeysClient,
httpClient,
kafkaStreams,
prometheusMeterRegistry,
rapporteringStateStore,
bekreftelseStateStore,
health,
rapporteringProducer,
bekreftelseProducer,
autorisasjonService
)
}

data class Dependencies(
val kafkaKeyClient: KafkaKeysClient,
val kafkaKeysClient: KafkaKeysClient,
val httpClient: HttpClient,
val kafkaStreams: KafkaStreams,
val prometheusMeterRegistry: PrometheusMeterRegistry,
val rapporteringStateStore: ReadOnlyKeyValueStore<Long, RapporteringTilgjengeligState>,
val bekreftelseStateStore: ReadOnlyKeyValueStore<Long, InternState>,
val health: Health,
val rapporteringProducer: RapporteringProducer,
val bekreftelseProducer: BekreftelseProducer,
val autorisasjonService: AutorisasjonService
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.paw.rapportering.api
package no.nav.paw.bekreftelse.api

import io.ktor.http.HttpStatusCode
import org.apache.kafka.streams.KafkaStreams
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.paw.rapportering.api.config
package no.nav.paw.bekreftelse.api.config

import no.nav.paw.config.env.NaisEnv
import no.nav.paw.config.env.currentNaisEnv
Expand All @@ -9,9 +9,9 @@ const val APPLICATION_CONFIG_FILE_NAME = "application_config.toml"
data class ApplicationConfig(
val applicationIdSuffix: String,
val producerId: String,
val rapporteringTopic: String,
val rapporteringHendelseLoggTopic: String,
val rapporteringStateStoreName: String,
val bekreftelseTopic: String,
val bekreftelseHendelseLoggTopic: String,
val bekreftelseStateStoreName: String,
val authProviders: AuthProviders,
val naisEnv: NaisEnv = currentNaisEnv,
val hostname: String = InetAddress.getLocalHost().hostName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package no.nav.paw.rapportering.api.domain.request
package no.nav.paw.bekreftelse.api.domain

import java.util.*

data class RapporteringRequest(
data class BekreftelseRequest(
// Identitetsnummer må sendes med hvis det er en veileder som rapporterer
val identitetsnummer: String? = null,
val rapporteringsId: UUID,
val bekreftelseId: UUID,
val harJobbetIDennePerioden: Boolean,
val vilFortsetteSomArbeidssoeker: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package no.nav.paw.bekreftelse.api.domain

data class TilgjengeligeBekreftelserRequest(
val identitetsnummer: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package no.nav.paw.bekreftelse.api.domain

import java.time.Instant
import java.util.*

data class TilgjengeligBekreftelse(
val periodeId: UUID,
val bekreftelseId: UUID,
val gjelderFra: Instant,
val gjelderTil: Instant,
)

typealias TilgjengeligBekreftelserResponse = List<TilgjengeligBekreftelse>

fun List<no.nav.paw.bekreftelse.internehendelser.BekreftelseTilgjengelig>.toResponse(): TilgjengeligBekreftelserResponse =
this.map {
TilgjengeligBekreftelse(
periodeId = it.periodeId,
bekreftelseId = it.bekreftelseId,
gjelderFra = it.gjelderFra,
gjelderTil = it.gjelderTil
)
}

Loading

0 comments on commit 0d3e426

Please sign in to comment.