Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/flytte kotlin clients #52

Merged
merged 67 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
50e2073
Genesis commit
maccyber Feb 16, 2023
c9a19a7
Workflow for paw-pdl-client
jstnhlj Feb 16, 2023
d651579
working-directory
jstnhlj Feb 17, 2023
45c687c
Temp fjern paths for å trigge kjøring
jstnhlj Feb 17, 2023
352e16f
Version & paths
jstnhlj Feb 17, 2023
8839a3f
Update build.gradle.kts
maccyber Feb 17, 2023
b553ee9
r: bruker expedia graphql PDL klient
maccyber Feb 17, 2023
27f42d6
Merge branch 'main' of https://github.com/navikt/paw-kotlin-clients
maccyber Feb 17, 2023
f0151b7
r: oppdaterer versjon
maccyber Feb 17, 2023
fbcee6a
r: oppdaterer versjon
maccyber Feb 17, 2023
4db5f34
PdlClient: inn-parameter med default-verdi til slutt
jstnhlj Feb 20, 2023
21c9109
r: endrer rekkefølge på http-klient parameter
maccyber Feb 23, 2023
2fc0d85
Oppdaterer README
jstnhlj Feb 28, 2023
758e171
paw-aareg-client
jstnhlj Mar 27, 2023
d001231
Update build.gradle.kts
maccyber Mar 27, 2023
6b2fb94
oppdaterer ktor versjon
maccyber Mar 27, 2023
c517da9
Update README.md
maccyber Mar 31, 2023
546e139
Fom kan ikke være valgfri
maccyber Apr 3, 2023
1598a73
Ikke send med Nav-Consumer-Token + kast exception
jstnhlj Apr 17, 2023
385748b
Kommenter ut feilende tester
jstnhlj Apr 17, 2023
b9489ab
Linting
jstnhlj Apr 17, 2023
512f3c7
0.1.4
jstnhlj Apr 17, 2023
c7a3050
Håndterer ingen perioder i ansettelseperioder
maccyber Apr 17, 2023
1e661c3
Revert: Håndterer ingen perioder i ansettelseperioder
maccyber Apr 17, 2023
2962ed6
Revert: Håndterer ingen perioder i ansettelseperioder
maccyber Apr 17, 2023
c04f758
Logger riktig status ved suksess
maccyber Apr 18, 2023
c2bc61f
Endre stillingsprosent i arbeidsavtale til å være optional
maccyber Apr 19, 2023
32efc94
Legger til callId og consumerId
maccyber Jun 9, 2023
2403c89
Merge pull request #1 from navikt/pdl_call_id
maccyber Jun 29, 2023
8abf34c
Fix lint
maccyber Jun 29, 2023
f5cdae7
Legger til workflow permissions til write packages
maccyber Oct 3, 2023
3b531cf
Oppdaterer klient og legger til hentOpphold
maccyber Oct 3, 2023
f77c7eb
Fjerne ubrukt import
maccyber Oct 3, 2023
de3238c
La til 'hentPerson'
nilsmsa Dec 20, 2023
3cc8694
La til initiell støtte for å hente basis info om en person (fødselsda…
nilsmsa Dec 20, 2023
3da9449
Fikset linter feil
nilsmsa Dec 20, 2023
cf84967
Oppdaterte versjonsnummeret
nilsmsa Dec 20, 2023
1f82d7a
endret hentPerson til å inlkudere forenkletStatus folk.reg. status is…
nilsmsa Dec 21, 2023
2490d4f
Utvidet hentPerson (igjen)
nilsmsa Dec 21, 2023
75cad65
La til 'utflyttingsDato' i 'hentPerson'
nilsmsa Jan 2, 2024
3f7a194
La til 'utenlandskAdresse'
nilsmsa Jan 3, 2024
7a45419
Fikset 'historisk' alltid false for 'hentPerson'
nilsmsa Jan 3, 2024
63a1c15
La til støtte for å hente fødselsdato og år
nilsmsa Jan 12, 2024
1ea6333
Endret til autogenerert versjonsnummer
nilsmsa Jan 12, 2024
225681d
Flyttet default versjonsnummer til gradle.properties
nilsmsa Jan 12, 2024
d42a412
Oppdaterer avhengigheter og legger til test for hentPerson
maccyber Mar 9, 2024
c85dcc5
Legger til eget kall for forenkletstatus
maccyber Mar 20, 2024
d0a94a6
Oppdaterer skjema og rydder
maccyber Mar 20, 2024
32c5d43
Legger til hentForenkletStatusBolk
maccyber Mar 20, 2024
f6f8c0e
Endret garphQL lib til API siden ex fra denne pakken eksponeres
nilsmsa Mar 22, 2024
1657668
La til behandlilngsnummer i header
nilsmsa May 13, 2024
423f05d
Fikset test behandlingnummer hardkodet i selve klienten
nilsmsa May 13, 2024
2bba3ca
Legger til historikk på inn- og utflytting
maccyber Jun 6, 2024
7150096
Legger ved historikk flagg i opphold og folkeregistrerpersonstatus
maccyber Jun 6, 2024
45cc58b
Legger ved historikk flagg i opphold og folkeregistrerpersonstatus
maccyber Jun 6, 2024
1df5a95
La til metadata for opphold til folkregstatus i hentPerson
nilsmsa Jun 10, 2024
ca5aa0e
La til statsborgerskap i hentPerson
nilsmsa Jun 24, 2024
91d3b8a
Oppdaterte test json for hentPerson
nilsmsa Jun 24, 2024
f9f4079
Oppdaterte avhengigheter
nilsmsa Jul 4, 2024
e804fd1
Oppdaterte avhengigheter
nilsmsa Jul 4, 2024
34cfdd2
Fikset kotlin versjonskonflikt
nilsmsa Jul 4, 2024
08042c2
Legger til HentPersonBolk
robertkittilsen Aug 8, 2024
536a07e
La til historikk param på hentIdenter
nilsmsa Oct 18, 2024
c5009ba
Klargjort for flytting til monorepo
naviktthomas Oct 25, 2024
247777d
Merge remote-tracking branch 'other/flytte-kode'
naviktthomas Oct 25, 2024
3b594a2
Oppdatert etter flytting av kotlin-clients
naviktthomas Oct 25, 2024
dbb4098
Oppdaterte apps til å bruke nye client-libs
naviktthomas Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions apps/api-start-stopp-perioder/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import org.gradle.configurationcache.extensions.capitalized
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask

plugins {
Expand All @@ -23,6 +21,7 @@ dependencies {
implementation(project(":lib:kafka"))
implementation(project(":lib:hoplite-config"))
implementation(project(":lib:kafka-key-generator-client"))
implementation(project(":lib:pdl-client"))
implementation(project(":domain:arbeidssoeker-regler"))
implementation(libs.bundles.ktorServerWithNettyAndMicrometer)
implementation(libs.micrometer.registryPrometheus)
Expand All @@ -36,7 +35,6 @@ dependencies {
implementation(libs.nav.common.auditLog)
implementation(libs.nav.common.log)
implementation(libs.poao.tilgangClient)
implementation(libs.paw.pdl.client)
implementation(libs.logbackClassic)
implementation(libs.logstashLogbackEncoder)
implementation(libs.kafka.clients)
Expand Down Expand Up @@ -93,8 +91,8 @@ jib {
environment = mapOf(
"IMAGE_WITH_VERSION" to "${image ?: project.name}:${project.version}",
"OTEL_INSTRUMENTATION_METHODS_INCLUDE" to ("io.ktor.server.routing.Routing[interceptor,executeResult];" +
"io.ktor.server.netty.NettyApplicationCallHandler[handleRequest,exceptionCaught];") +
"io.ktor.serialization.jackson.JacksonConverter[deserialize,serializeNullable]"
"io.ktor.server.netty.NettyApplicationCallHandler[handleRequest,exceptionCaught];") +
"io.ktor.serialization.jackson.JacksonConverter[deserialize,serializeNullable]"
)
jvmFlags = listOf("-XX:ActiveProcessorCount=4", "-XX:+UseZGC", "-XX:+ZGenerational")
}
Expand All @@ -107,7 +105,7 @@ mapOf(
"${layout.projectDirectory}/src/main/resources/openapi/opplysninger.yaml" to "${generatedCodePackageName}.opplysningermottatt",
"${layout.projectDirectory}/src/main/resources/openapi/startstopp.yaml" to "${generatedCodePackageName}.startstopp"
).map { (openApiDocFile, pkgName) ->
val taskName = "generate${pkgName.capitalized()}"
val taskName = "generate${pkgName.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }}"
tasks.register(taskName, GenerateTask::class) {
generatorName.set("kotlin-server")
library = "ktor"
Expand Down
2 changes: 1 addition & 1 deletion apps/bekreftelse-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {

// Serialization
implementation(libs.ktor.serialization.jackson)
implementation(libs.ktor.serialization.json)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.jackson.datatypeJsr310)

// Authentication
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package no.nav.paw.bekreftelse.api.model

import no.nav.paw.bekreftelse.api.exception.UgyldigBearerTokenException
import no.nav.paw.bekreftelse.api.model.ResolveToken.AzureToken
import no.nav.paw.bekreftelse.api.model.ResolveToken.IdPortenToken
import no.nav.paw.bekreftelse.api.model.ResolveToken.TokenXToken
import no.nav.security.token.support.core.context.TokenValidationContext
import no.nav.security.token.support.core.jwt.JwtToken
import java.util.*
Expand Down Expand Up @@ -39,14 +36,11 @@ data object OID : Claim<UUID>("oid", UUID::fromString)
data object Name : Claim<String>("name", { it })
data object NavIdent : Claim<String>("NAVident", { it })

private sealed class ResolveToken(
val issuer: Issuer,
val claims: List<Claim<*>>
) {
data object IdPortenToken : ResolveToken(IdPorten, listOf(PID))
data object TokenXToken : ResolveToken(TokenX, listOf(PID))
data object AzureToken : ResolveToken(Azure, listOf(OID, Name, NavIdent))
}
sealed class ResolveToken(val issuer: Issuer, val claims: List<Claim<*>>)

data object IdPortenToken : ResolveToken(IdPorten, listOf(PID))
data object TokenXToken : ResolveToken(TokenX, listOf(PID))
data object AzureToken : ResolveToken(Azure, listOf(OID, Name, NavIdent))

private val validTokens: List<ResolveToken> = listOf(IdPortenToken, TokenXToken, AzureToken)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ val KafkaConsumerPlugin: ApplicationPlugin<KafkaConsumerPluginConfig> =
application.log.info("Stopper Kafka Consumer")
pollingFlag.set(false)
consumeJob?.cancel()
consumer.unsubscribe()
consumer.close(shutDownTimeout)
}

Expand Down
2 changes: 1 addition & 1 deletion apps/bekreftelse-tjeneste/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {

// Serialization
implementation(libs.ktor.serialization.jackson)
implementation(libs.ktor.serialization.json)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.jackson.datatypeJsr310)

// Tooling
Expand Down
2 changes: 1 addition & 1 deletion apps/bekreftelse-utgang/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {

// Serialization
implementation(libs.ktor.serialization.jackson)
implementation(libs.ktor.serialization.json)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.jackson.datatypeJsr310)

// Tooling
Expand Down
5 changes: 2 additions & 3 deletions apps/hendelselogg-backup/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.gradle.configurationcache.extensions.capitalized
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
Expand Down Expand Up @@ -107,7 +106,7 @@ val generatedCodeOutputDir = "${layout.buildDirectory.get()}/generated/"
mapOf(
"${layout.projectDirectory}/src/main/resources/openapi/Brukerstoette.yaml" to "${generatedCodePackageName}.brukerstoette"
).map { (openApiDocFile, pkgName) ->
val taskName = "generate${pkgName.capitalized()}"
val taskName = "generate${pkgName.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }}"
tasks.register(taskName, GenerateTask::class) {
generatorName.set("kotlin-server")
library = "ktor"
Expand Down Expand Up @@ -142,7 +141,7 @@ mapOf(
mapOf(
"${layout.projectDirectory}/src/main/resources/openapi/oppslags-api.yaml" to "${generatedCodePackageName}.oppslagsapi"
).map { (openApiDocFile, pkgName) ->
val taskName = "generate${pkgName.capitalized()}"
val taskName = "generate${pkgName.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }}"
tasks.register(taskName, GenerateTask::class) {
generatorName.set("kotlin")
library = "jvm-ktor"
Expand Down
2 changes: 1 addition & 1 deletion apps/kafka-key-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ val jvmMajorVersion: String by project
dependencies {
// PAW
implementation(project(":lib:hoplite-config"))
implementation(libs.paw.pdl.client)
implementation(project(":lib:pdl-client"))

// NAV
implementation(libs.nav.common.log)
Expand Down
6 changes: 3 additions & 3 deletions apps/utgang-pdl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ dependencies {
implementation(project(":domain:arbeidssoekerregisteret-kotlin"))
implementation(project(":domain:arbeidssoeker-regler"))

implementation(project(":lib:kafka-key-generator-client"))
implementation(project(":lib:hoplite-config"))
implementation(project(":lib:kafka"))
implementation(project(":lib:kafka-streams"))
implementation(project(":lib:hoplite-config"))
implementation(project(":lib:kafka-key-generator-client"))
implementation(project(":lib:pdl-client"))

api(libs.arrow.core.core)

implementation(libs.kafka.streams.core)
implementation(libs.paw.pdl.client)

implementation(libs.bundles.ktorServerWithNettyAndMicrometer)
implementation(libs.micrometer.registryPrometheus)
Expand Down
4 changes: 1 addition & 3 deletions domain/arbeidssoeker-regler/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("org.openapi.generator")
Expand All @@ -11,8 +9,8 @@ val baseImage: String by project
val jvmMajorVersion: String by project

dependencies {
implementation(project(":lib:pdl-client"))
implementation(project(":domain:interne-hendelser"))
implementation(libs.paw.pdl.client)
api(libs.micrometer.registryPrometheus)
api(libs.arrow.core.core)
testImplementation(libs.ktor.server.testJvm)
Expand Down
17 changes: 10 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[versions]
pawPdlClientVersion = "24.10.18.41-1"
pawAaregClientVersion = "24.07.04.18-1"
noNavSecurityVersion = "5.0.5"
noNavCommonVersion = "3.2024.05.23_05.46-2b29fa343e8e"
arbeidssokerregisteretVersion = "1.9348086045.48-1"
bekreftelseSchemaVersion = "24.10.21.12-1"
arrowVersion = "1.2.4"
arrowJacksonIntegrationVersion = "0.14.1"
noNavCommonVersion = "3.2024.05.23_05.46-2b29fa343e8e"
noNavSecurityVersion = "5.0.5"
comSksamuelHopliteVersion = "2.8.2"
graphqlClientVersion = "7.1.1"
orgApacheKafkaVersion = "3.7.0"
ioConfluentKafkaVersion = "7.7.1"
orgApacheAvroVersion = "1.12.0"
Expand All @@ -27,6 +26,8 @@ coroutinesVersion = "1.9.0"
postgresDriverVersion = "42.7.4"
flywayVersion = "10.20.0"
hikariVersion = "6.0.0"
kotlinxCoroutinesVersion = "1.8.1"
kotlinxSerializationJsonVersion = "1.7.3"
ktorVersion = "2.3.12"

[libraries]
Expand All @@ -36,6 +37,8 @@ arrow-core-serialization = { group = "io.arrow-kt", name = "arrow-core-serializa
arrow-integration-jackson = { group = "io.arrow-kt", name = "arrow-integrations-jackson-module", version.ref = "arrowJacksonIntegrationVersion" }
logbackClassic = { group = "ch.qos.logback", name = "logback-classic", version.ref = "logbackVersion" }
logstashLogbackEncoder = { group = "net.logstash.logback", name = "logstash-logback-encoder", version.ref = "logstashVersion" }
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesVersion" }
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerializationJsonVersion" }
ktor-client-contentNegotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktorVersion" }
ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktorVersion" }
ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktorVersion" }
Expand All @@ -57,14 +60,12 @@ ktor-server-testJvm = { group = "io.ktor", name = "ktor-server-tests-jvm", versi
ktor-serialization-core = { group = "io.ktor", name = "ktor-serialization", version.ref = "ktorVersion" }
ktor-serialization-jvm = { group = "io.ktor", name = "ktor-serialization-jvm", version.ref = "ktorVersion" }
ktor-serialization-jackson = { group = "io.ktor", name = "ktor-serialization-jackson", version.ref = "ktorVersion" }
ktor-serialization-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktorVersion" }
ktor-serialization-kotlinx-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktorVersion" }
opentelemetry-api = { group = "io.opentelemetry", name = "opentelemetry-api", version.ref = "otelTargetSdkVersion" }
opentelemetry-ktor = { group = "io.opentelemetry.instrumentation", name = "opentelemetry-ktor-2.0", version.ref = "otelInstrumentationKtorVersion" }
opentelemetry-annotations = { group = "io.opentelemetry.instrumentation", name = "opentelemetry-instrumentation-annotations", version.ref = "otelInstrumentationVersion" }
micrometerCore = { group = "io.micrometer", name = "micrometer-core", version.ref = "micrometerVersion" }
micrometer-registryPrometheus = { group = "io.micrometer", name = "micrometer-registry-prometheus", version.ref = "micrometerVersion" }
paw-pdl-client = { group = "no.nav.paw", name = "pdl-client", version.ref = "pawPdlClientVersion" }
paw-aareg-client = { group = "no.nav.paw", name = "aareg-client", version.ref = "pawAaregClientVersion" }
paw-schema-main = { group = "no.nav.paw.arbeidssokerregisteret.api", name = "main-avro-schema", version.ref = "arbeidssokerregisteretVersion" }
kafka-clients = { group = "org.apache.kafka", name = "kafka-clients", version.ref = "orgApacheKafkaVersion" }
kafka-streams-core = { group = "org.apache.kafka", name = "kafka-streams", version.ref = "orgApacheKafkaVersion" }
Expand All @@ -80,6 +81,8 @@ nav-common-log = { group = "no.nav.common", name = "log", version.ref = "noNavCo
nav-common-auditLog = { group = "no.nav.common", name = "audit-log", version.ref = "noNavCommonVersion" }
nav-security-tokenValidationKtorV2 = { group = "no.nav.security", name = "token-validation-ktor-v2", version.ref = "noNavSecurityVersion" }
nav-security-tokenClientCore = { group = "no.nav.security", name = "token-client-core", version.ref = "noNavSecurityVersion" }
graphql-client = { group = "com.expediagroup", name = "graphql-kotlin-client", version.ref = "graphqlClientVersion" }
graphql-ktor-client = { group = "com.expediagroup", name = "graphql-kotlin-ktor-client", version.ref = "graphqlClientVersion" }
hoplite-core = { group = "com.sksamuel.hoplite", name = "hoplite-core", version.ref = "comSksamuelHopliteVersion" }
hoplite-toml = { group = "com.sksamuel.hoplite", name = "hoplite-toml", version.ref = "comSksamuelHopliteVersion" }
hoplite-yaml = { group = "com.sksamuel.hoplite", name = "hoplite-yaml", version.ref = "comSksamuelHopliteVersion" }
Expand Down
41 changes: 41 additions & 0 deletions lib/aareg-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# paw-aareg-client

Henter arbeidsforhold fra Arbeidsgiver- og arbeidstakerregisteret ([aareg](https://navikt.github.io/aareg/)).

Se URL-er på https://github.com/navikt/aareg-services

Se dokumentasjon for aareg på https://aareg-services.dev.intern.nav.no/swagger-ui/index.html

### Bruk av paw-aareg-client

**_gradle.build.kts_**

```kts
val tokenproviderVersion: String by project
val aaregClientVersion: String by project

dependencies {
implementation("no.nav.paw:tokenprovider:$tokenproviderVersion")
implementation("no.nav.paw:aareg-client:$aaregClientVersion")
}
```

### Klienten instansieres slik

```kt
import kotlinx.coroutines.runBlocking
import no.nav.paw.tokenprovider.OAuth2TokenProvider
import no.nav.paw.aareg.AaregClient

fun main() {
val url = "https://modapp-q1.adeo.no/aareg-services"
val tokenProvider = OAuth2TokenProvider(
// Token config
)

val aaregClient = AaregClient(url) { tokenProvider.getToken() }

val arbeidsforhold = runBlocking { aaregClient.hentArbeidsforhold("fnr", "callId") }
println(arbeidsforhold)
}
```
28 changes: 28 additions & 0 deletions lib/aareg-client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
}

val jvmMajorVersion: String by project

dependencies {
api(libs.kotlinx.serialization.json)

implementation(libs.ktor.client.contentNegotiation)
implementation(libs.ktor.client.okhttp)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.ktor.client.logging)

testImplementation(libs.bundles.testLibsWithUnitTesting)
testImplementation(libs.ktor.client.mock)
}

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

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
53 changes: 53 additions & 0 deletions lib/aareg-client/src/main/kotlin/no/nav/paw/aareg/AaregClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package no.nav.paw.aareg

import io.ktor.client.call.body
import io.ktor.client.plugins.ResponseException
import io.ktor.client.request.bearerAuth
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.statement.bodyAsText
import io.ktor.http.ContentType
import io.ktor.http.contentType
import io.ktor.serialization.JsonConvertException
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.net.ConnectException

/**
* klient for å hente ut aktive arbeidsforhold på en person
*/

class AaregClient(
private val url: String,
private val getAccessToken: () -> String
) {
private val sikkerLogger: Logger = LoggerFactory.getLogger("tjenestekall")
private val logger: Logger = LoggerFactory.getLogger("paw-aareg-client")
private val httpClient = createHttpClient()

suspend fun hentArbeidsforhold(ident: String, callId: String): List<Arbeidsforhold> {
val token = getAccessToken()
try {
val payload = httpClient.get(url) {
contentType(ContentType.Application.Json)
bearerAuth(token)
header("Nav-Call-Id", callId)
header("Nav-Personident", ident)
}.also {
logger.info("Hentet arbeidsforhold fra aareg med status=${it.status}")
sikkerLogger.debug("Svar fra aareg-API: " + it.bodyAsText())
}.body<List<Arbeidsforhold>>()
return payload
} catch (responseException: ResponseException) {
logger.error("Hente arbeidsforhold callId=[$callId] feilet med http-kode ${responseException.response.status}")
throw responseException
} catch (connectException: ConnectException) {
logger.error("Hente arbeidsforhold callId=[$callId] feilet:", connectException)
throw connectException
} catch (jsonConvertException: JsonConvertException) {
logger.error("Hente arbeidsforhold callId=[$callId] feilet, kunne ikke lese JSON")
sikkerLogger.error("Hente arbeidsforhold callId=[$callId] feilet", jsonConvertException)
throw jsonConvertException
}
}
}
Loading