Skip to content

Commit

Permalink
Gå direkte mot Goys enn via dp-proxy for oppgaveopprettelser.
Browse files Browse the repository at this point in the history
  • Loading branch information
geiralund committed Apr 30, 2024
1 parent 54a1bcf commit cae2c91
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import no.nav.dagpenger.mottak.behov.person.SkjermingOppslag
import no.nav.dagpenger.mottak.behov.person.createPersonOppslag
import no.nav.dagpenger.mottak.behov.saksbehandling.arena.ArenaApiClient
import no.nav.dagpenger.mottak.behov.saksbehandling.arena.ArenaBehovLøser
import no.nav.dagpenger.mottak.behov.saksbehandling.gosys.GosysClient
import no.nav.dagpenger.mottak.behov.saksbehandling.gosys.OpprettGosysOppgaveLøser
import no.nav.dagpenger.mottak.behov.saksbehandling.gosys.UnleashGosysClient
import no.nav.dagpenger.mottak.db.InnsendingPostgresRepository
import no.nav.dagpenger.mottak.db.PostgresDataSourceBuilder
import no.nav.dagpenger.mottak.observers.FerdigstiltInnsendingObserver
Expand All @@ -35,7 +35,7 @@ internal class ApplicationBuilder(env: Map<String, String>) : RapidsConnection.S
private val safClient = SafClient(Config.properties)
private val arenaApiClient = ArenaApiClient(Config.properties)
private val journalpostApiClient = JournalpostApiClient(tokenProvider = Config.properties.dokarkivTokenProvider)
private val gosysOppslag = UnleashGosysClient(Config.properties, unleash)
private val gosysOppslag = GosysClient(Config.properties)
private val ferdigstiltInnsendingObserver = FerdigstiltInnsendingObserver(Config.kafkaProducerProperties)

private val rapidsConnection =
Expand Down
7 changes: 1 addition & 6 deletions mediator/src/main/kotlin/no/nav/dagpenger/mottak/Unleash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import io.getunleash.DefaultUnleash
import io.getunleash.FakeUnleash
import io.getunleash.Unleash
import io.getunleash.util.UnleashConfig
import mu.KotlinLogging
import no.nav.dagpenger.mottak.Config.properties
import java.net.InetAddress

private val logger = KotlinLogging.logger { }

val unleash: Unleash by lazy {
if (properties.getOrNull(Key("UNLEASH_SERVER_API_URL", stringType)) == null) return@lazy FakeUnleash()
DefaultUnleash(
Expand All @@ -25,8 +22,6 @@ val unleash: Unleash by lazy {
"prod-gcp" -> "production"
else -> "development"
},
).build().also {
logger.info { "Unleash er konfigurert" }
},
).build(),
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.dagpenger.mottak.behov.saksbehandling.gosys

import com.natpryce.konfig.Configuration
import io.getunleash.Unleash
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.DefaultRequest
Expand All @@ -16,8 +15,6 @@ import io.ktor.http.HttpMethod
import io.ktor.serialization.jackson.JacksonConverter
import mu.KotlinLogging
import no.nav.dagpenger.mottak.Config.dpGosysTokenProvider
import no.nav.dagpenger.mottak.Config.dpProxyTokenProvider
import no.nav.dagpenger.mottak.Config.dpProxyUrl
import no.nav.dagpenger.mottak.Config.gosysUrl
import no.nav.dagpenger.mottak.behov.JsonMapper
import java.time.LocalDate
Expand All @@ -43,58 +40,6 @@ internal data class GosysOppgaveRequest(

internal data class GosysOppgaveResponse(val id: String)

internal class UnleashGosysClient(config: Configuration, private val unleash: Unleash) : GosysOppslag {
private val gosysClient = GosysClient(config)
private val proxyClient = GosysProxyClient(config)

override suspend fun opprettOppgave(oppgave: GosysOppgaveRequest): String {
return if (unleash.isEnabled("bruk-gosys-direkte")) {
gosysClient.opprettOppgave(oppgave)
} else {
proxyClient.opprettOppgave(oppgave)
}
}
}

internal class GosysProxyClient(config: Configuration) : GosysOppslag {
companion object {
private val logger = KotlinLogging.logger {}
}

private val tokenProvider = config.dpProxyTokenProvider

private val proxyGosysClient =
HttpClient {
expectSuccess = true
install(DefaultRequest) {
this.url("${config.dpProxyUrl()}/proxy/v1/gosys/oppgaver")
}
install(ContentNegotiation) {
register(ContentType.Application.Json, JacksonConverter(JsonMapper.jacksonJsonAdapter))
}
install(HttpTimeout) {
requestTimeoutMillis = 2.minutes.inWholeMilliseconds
}
}

override suspend fun opprettOppgave(oppgave: GosysOppgaveRequest): String {
return try {
logger.info { "Forsøker å opprette oppgave i gosys for sak med journalpostId ${oppgave.journalpostId}" }
proxyGosysClient.request {
header("X-Correlation-ID", oppgave.journalpostId)
header(HttpHeaders.Authorization, "Bearer ${tokenProvider.invoke()}")
header(HttpHeaders.ContentType, "application/json")
header(HttpHeaders.Accept, "application/json")
method = HttpMethod.Post
setBody(oppgave)
}.body<GosysOppgaveResponse>().id
} catch (e: Exception) {
logger.error { "Kunne ikke opprette gosys oppgave for journalpost med id ${oppgave.journalpostId}" }
throw e
}
}
}

internal class GosysClient(config: Configuration) : GosysOppslag {
companion object {
private val logger = KotlinLogging.logger {}
Expand Down

0 comments on commit cae2c91

Please sign in to comment.