Skip to content

Commit

Permalink
bumper r&r og tbd-libs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsteinsland committed Nov 12, 2024
1 parent 8c97c99 commit 74e47e3
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 120 deletions.
20 changes: 8 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
val ktorVersion = "2.3.12"
val rapidsAndRiversVersion = "2024111211071731406062.648687519469"
val tbdLibsVersion = "2024.11.12-11.09-16cf2599"
val ktorVersion = "3.0.1"
val postgresqlVersion = "42.7.2"
val wiremockVersion = "3.3.1"
val junitJupiterVersion = "5.11.3"
Expand All @@ -16,18 +18,13 @@ plugins {
}

dependencies {
implementation("com.github.navikt:rapids-and-rivers:2024020509001707120042.dc369a80c1f8")
implementation("io.ktor:ktor-server-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-server-call-id:$ktorVersion")
implementation("io.ktor:ktor-server-status-pages-jvm:$ktorVersion")
implementation("com.github.navikt:rapids-and-rivers:$rapidsAndRiversVersion")
implementation("io.ktor:ktor-server-auth-jwt:$ktorVersion") {
exclude(group = "junit")
}

implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.ktor:ktor-serialization-jackson:$ktorVersion")

implementation("org.postgresql:postgresql:$postgresqlVersion")
implementation("com.zaxxer:HikariCP:$hikariCPVersion")
implementation("org.flywaydb:flyway-core:$flywayVersion")
Expand All @@ -41,13 +38,12 @@ dependencies {
testImplementation("org.testcontainers:testcontainers:$testcontainersVersion")
testImplementation("org.testcontainers:junit-jupiter:$testcontainersVersion")

testImplementation("org.junit.jupiter:junit-jupiter:$junitJupiterVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

testImplementation("io.ktor:ktor-server-test-host:$ktorVersion") {
exclude(group = "org.eclipse.jetty")
}
testImplementation("com.github.navikt.tbd-libs:naisful-test-app:$tbdLibsVersion")
testImplementation("org.skyscreamer:jsonassert:$jsonAssertVersion")

testImplementation("org.junit.jupiter:junit-jupiter:$junitJupiterVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

repositories {
Expand Down
54 changes: 9 additions & 45 deletions src/main/kotlin/no/nav/helse/spokelse/App.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
package no.nav.helse.spokelse

import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.http.HttpStatusCode.Companion.InternalServerError
import io.ktor.serialization.jackson.*
import io.ktor.client.engine.cio.CIO
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.plugins.callid.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.statuspages.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import no.nav.helse.rapids_rivers.RapidApplication
import no.nav.helse.rapids_rivers.RapidsConnection
import no.nav.helse.spokelse.gamleutbetalinger.GamleUtbetalingerDao
import no.nav.helse.spokelse.grunnlag.grunnlagApi
import no.nav.helse.spokelse.tbdutbetaling.HelsesjekkRiver
import no.nav.helse.spokelse.tbdutbetaling.TbdUtbetalingApi
import no.nav.helse.spokelse.tbdutbetaling.TbdUtbetalingConsumer
import no.nav.helse.spokelse.tbdutbetaling.TbdUtbetalingDao
import no.nav.helse.spokelse.tbdutbetaling.TbdUtbetalingApi
import no.nav.helse.spokelse.utbetalteperioder.UtbetaltePerioder
import no.nav.helse.spokelse.utbetalteperioder.UtbetaltePerioderRiver
import no.nav.helse.spokelse.utbetalteperioder.utbetaltePerioderApi
import org.slf4j.LoggerFactory
import org.slf4j.event.Level
import java.util.*

private val sikkerlogg = LoggerFactory.getLogger("tjenestekall")
internal fun Map<String, String>.hent(key: String) = get(key) ?: throw IllegalStateException("Mangler config for $key")
Expand All @@ -38,8 +26,6 @@ fun main() {
}

fun launchApplication(env: Map<String, String>) {
val builder = RapidApplication.Builder(RapidApplication.RapidApplicationConfig.fromEnv(env))

val auth = Auth.auth(
name = "ourissuer",
clientId = env.getValue("AZURE_APP_CLIENT_ID"),
Expand All @@ -54,8 +40,12 @@ fun launchApplication(env: Map<String, String>) {
val utbetaltePerioder = UtbetaltePerioder(env, HttpClient(CIO), TbdUtbetalingApi(tbdUtbetalingDao), gamleUtbetalingerDao)

val tbdUtbetalingConsumer = TbdUtbetalingConsumer(env, tbdUtbetalingDao, observers = listOf(tbdUtbetalingDao, gamleUtbetalingerDao))
builder.withKtorModule { spokelse(env, auth, gamleUtbetalingerDao, TbdUtbetalingApi(tbdUtbetalingDao), ApplicationIdAllowlist) }
.build()
RapidApplication.create(
env = env,
builder = {
withKtorModule { spokelse(env, auth, gamleUtbetalingerDao, TbdUtbetalingApi(tbdUtbetalingDao), ApplicationIdAllowlist) }
}
)
.apply {
registerRivers(tbdUtbetalingDao, utbetaltePerioder)
register(tbdUtbetalingConsumer)
Expand All @@ -79,32 +69,6 @@ internal fun RapidsConnection.registerRivers(
internal fun Application.spokelse(env: Map<String, String>, auth: Auth, gamleUtbetalingerDao: GamleUtbetalingerDao, tbdUtbetalingApi: TbdUtbetalingApi, apiTilgangsstyring: ApiTilgangsstyring) {
val httpClient = HttpClient(CIO)
azureAdAppAuthentication(auth)
requestResponseTracing(sikkerlogg)
install(ContentNegotiation) {
jackson {
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
registerModule(JavaTimeModule())
}
}
install(CallId) {
header("x-callId")
verify { it.isNotEmpty() }
generate { UUID.randomUUID().toString() }
}
install(CallLogging) {
logger = sikkerlogg
level = Level.INFO
disableDefaultColors()
callIdMdc("callId")
filter { call -> setOf("/isalive", "/isready", "/metrics").none { call.request.path().contains(it) } }
}

install(StatusPages) {
exception<Throwable> { call, cause ->
sikkerlogg.error("Feil ved håndtering av ${call.request.httpMethod.value} - ${call.request.path()}", cause)
call.respond(InternalServerError)
}
}
routing {
authenticate {
grunnlagApi(gamleUtbetalingerDao, tbdUtbetalingApi, apiTilgangsstyring)
Expand Down
44 changes: 0 additions & 44 deletions src/main/kotlin/no/nav/helse/spokelse/RequestResponseTracing.kt

This file was deleted.

6 changes: 2 additions & 4 deletions src/main/kotlin/no/nav/helse/spokelse/grunnlag/GrunnlagApi.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package no.nav.helse.spokelse.grunnlag

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.navikt.tbd_libs.rapids_and_rivers.isMissingOrNull
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.util.pipeline.*
import no.nav.helse.rapids_rivers.isMissingOrNull
import no.nav.helse.spokelse.ApiTilgangsstyring
import no.nav.helse.spokelse.gamleutbetalinger.GamleUtbetalingerDao
import no.nav.helse.spokelse.gamleutbetalinger.GammelUtbetaling.Companion.somFpVedtak
Expand All @@ -24,7 +22,7 @@ private val objectMapper = jacksonObjectMapper()
private fun String.asLocalDateOrNull() = kotlin.runCatching { LocalDate.parse(this) }.getOrNull()

internal fun Route.grunnlagApi(gamleUtbetalingerDao: GamleUtbetalingerDao, tbdUtbetalingApi: TbdUtbetalingApi, tilgangsstyrings: ApiTilgangsstyring) {
suspend fun PipelineContext<Unit, ApplicationCall>.respond(fødselsnummer: String, fom: LocalDate?) {
suspend fun RoutingContext.respond(fødselsnummer: String, fom: LocalDate?) {
tilgangsstyrings.grunnlag(call)
val time = measureTimeMillis {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.helse.spokelse.tbdutbetaling

import com.fasterxml.jackson.databind.JsonNode
import no.nav.helse.rapids_rivers.isMissingOrNull
import com.github.navikt.tbd_libs.rapids_and_rivers.isMissingOrNull
import no.nav.helse.spokelse.tbdutbetaling.Melding.Companion.erAnnullering
import no.nav.helse.spokelse.tbdutbetaling.Melding.Companion.event

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package no.nav.helse.spokelse.tbdutbetaling

import com.fasterxml.jackson.databind.JsonNode
import no.nav.helse.rapids_rivers.*
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
import com.github.navikt.tbd_libs.rapids_and_rivers.River
import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDateTime
import com.github.navikt.tbd_libs.rapids_and_rivers.isMissingOrNull
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageContext
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageMetadata
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import io.micrometer.core.instrument.MeterRegistry
import org.slf4j.LoggerFactory
import org.slf4j.event.Level
import org.slf4j.event.Level.ERROR
Expand Down Expand Up @@ -33,7 +40,7 @@ internal class HelsesjekkRiver(
}.register(this)
}

override fun onPacket(packet: JsonMessage, context: MessageContext) {
override fun onPacket(packet: JsonMessage, context: MessageContext, metadata: MessageMetadata, meterRegistry: MeterRegistry) {
if (!packet.utførHelsesjekk) return

val systemParticipatingServices = packet["system_participating_services"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package no.nav.helse.spokelse.tbdutbetaling

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import net.logstash.logback.argument.StructuredArguments.keyValue
import no.nav.helse.rapids_rivers.RapidsConnection
import no.nav.helse.spokelse.tbdutbetaling.Annullering.Companion.annullering
import no.nav.helse.spokelse.tbdutbetaling.Melding.Companion.erAnnullering
import no.nav.helse.spokelse.tbdutbetaling.Melding.Companion.erUtbetaling
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.helse.spokelse.tbdutbetaling

import com.fasterxml.jackson.databind.JsonNode
import no.nav.helse.rapids_rivers.isMissingOrNull
import com.github.navikt.tbd_libs.rapids_and_rivers.isMissingOrNull
import no.nav.helse.spokelse.grunnlag.FpVedtak
import no.nav.helse.spokelse.grunnlag.Utbetalingsperiode
import no.nav.helse.spokelse.tbdutbetaling.Melding.Companion.erUtbetaling
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.helse.spokelse.tbdutbetaling

import com.fasterxml.jackson.databind.JsonNode
import no.nav.helse.rapids_rivers.asLocalDate
import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDate
import java.time.LocalDate

internal data class Utbetalingslinje(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package no.nav.helse.spokelse.utbetalteperioder

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.navikt.tbd_libs.rapids_and_rivers.isMissingOrNull
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import no.nav.helse.rapids_rivers.isMissingOrNull
import org.intellij.lang.annotations.Language
import org.slf4j.MDC
import java.time.LocalDate
import java.util.*

internal class Infotrygd(private val httpClient: HttpClient, private val scope :String, private val accessToken: AccessToken, private val url: String) {
suspend fun hent(personidentifikatorer: Set<Personidentifikator>, fom: LocalDate, tom: LocalDate): List<SpøkelsePeriode> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package no.nav.helse.spokelse.utbetalteperioder

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
import com.github.navikt.tbd_libs.rapids_and_rivers.River
import com.github.navikt.tbd_libs.rapids_and_rivers.withMDC
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageContext
import com.github.navikt.tbd_libs.rapids_and_rivers_api.MessageMetadata
import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import io.micrometer.core.instrument.MeterRegistry
import kotlinx.coroutines.runBlocking
import no.nav.helse.rapids_rivers.*

internal class UtbetaltePerioderRiver(
rapidsConnection: RapidsConnection,
Expand All @@ -18,7 +24,7 @@ internal class UtbetaltePerioderRiver(
}.register(this)
}

override fun onPacket(packet: JsonMessage, context: MessageContext) {
override fun onPacket(packet: JsonMessage, context: MessageContext, metadata: MessageMetadata, meterRegistry: MeterRegistry) {
withMDC("callId" to packet["@id"].asText()) {
val request = objectMapper.readTree(packet.toJson())
runBlocking { utbetaltePerioder.hent(request) }
Expand Down
17 changes: 12 additions & 5 deletions src/test/kotlin/no/nav/helse/spokelse/AbstractE2ETest.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package no.nav.helse.spokelse

import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.github.navikt.tbd_libs.naisful.test.naisfulTestApp
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.testing.*
import io.micrometer.prometheusmetrics.PrometheusConfig
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import kotlinx.coroutines.runBlocking
import no.nav.helse.spokelse.ApplicationIdAllowlist.applicationId
import no.nav.helse.spokelse.gamleutbetalinger.GamleUtbetalingerDao
Expand Down Expand Up @@ -77,15 +82,17 @@ internal abstract class AbstractE2ETest {
timeout: Int = 5,
authorized: Boolean = true
) {
testApplication {
this.application {
naisfulTestApp(
testApplicationModule = {
spokelse(env, auth, gamleUtbetalingerDao, TbdUtbetalingApi(tbdUtbetalingDao), object: ApiTilgangsstyring {
override fun utbetaltePerioder(call: ApplicationCall) { check(call.applicationId == "fp_object_id") }
override fun utbetaltePerioderAap(call: ApplicationCall) { check(call.applicationId == "fp_object_id") }
override fun grunnlag(call: ApplicationCall) { check(call.applicationId == "fp_object_id") }
})
}

},
objectMapper = jacksonObjectMapper().registerModule(JavaTimeModule()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS),
meterRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT),
) {
Awaitility.await().atMost(timeout.toLong(), TimeUnit.SECONDS).untilAsserted {
val response = runBlocking {
client.request("/$path") {
Expand Down

0 comments on commit 74e47e3

Please sign in to comment.