Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dragutin-nav committed Apr 21, 2024
1 parent 2cb76e0 commit 68dabca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import no.nav.common.health.HealthCheckUtils
import no.nav.common.rest.client.RestClient
import no.nav.common.rest.client.RestUtils
import no.nav.common.types.identer.Fnr
import no.nav.common.utils.AuthUtils.bearerToken
import no.nav.common.utils.UrlUtils
import no.nav.veilarbvedtaksstotte.client.person.dto.CvDto
import no.nav.veilarbvedtaksstotte.client.person.dto.CvErrorStatus
Expand All @@ -23,15 +24,15 @@ import org.springframework.http.HttpStatus
import org.springframework.web.server.ResponseStatusException
import java.util.function.Supplier

class VeilarbpersonClientImpl(private val veilarbpersonUrl: String, private val userTokenSupplier: Supplier<String>) :
class VeilarbpersonClientImpl(private val veilarbpersonUrl: String, private val machineToMachineTokenSupplier: Supplier<String>) :
VeilarbpersonClient {

private val client: OkHttpClient = RestClient.baseClient()

override fun hentPersonNavn(fnr: String): PersonNavn {
val request = Request.Builder()
.url(UrlUtils.joinPaths(veilarbpersonUrl, "/api/v3/person/hent-navn"))
.header(HttpHeaders.AUTHORIZATION, userTokenSupplier.get())
.header(HttpHeaders.AUTHORIZATION, bearerToken(machineToMachineTokenSupplier.get()))
.post(
PersonRequest(Fnr.of(fnr), BehandlingsNummer.VEDTAKSTOTTE.value).toJson()
.toRequestBody(RestUtils.MEDIA_TYPE_JSON)
Expand All @@ -46,7 +47,7 @@ class VeilarbpersonClientImpl(private val veilarbpersonUrl: String, private val
override fun hentCVOgJobbprofil(fnr: String): CvDto {
val request = Request.Builder()
.url(UrlUtils.joinPaths(veilarbpersonUrl, "/api/v3/person/hent-cv_jobbprofil"))
.header(HttpHeaders.AUTHORIZATION, userTokenSupplier.get())
.header(HttpHeaders.AUTHORIZATION, bearerToken(machineToMachineTokenSupplier.get()))
.post(
PersonRequest(Fnr.of(fnr), BehandlingsNummer.VEDTAKSTOTTE.value).toJson()
.toRequestBody(RestUtils.MEDIA_TYPE_JSON)
Expand All @@ -68,7 +69,7 @@ class VeilarbpersonClientImpl(private val veilarbpersonUrl: String, private val
override fun hentMålform(fnr: Fnr): Målform {
val request = Request.Builder()
.url(UrlUtils.joinPaths(veilarbpersonUrl, "api/v3/person/hent-malform"))
.header(HttpHeaders.AUTHORIZATION, userTokenSupplier.get())
.header(HttpHeaders.AUTHORIZATION, bearerToken(machineToMachineTokenSupplier.get()))
.post(
PersonRequest(fnr, BehandlingsNummer.VEDTAKSTOTTE.value).toJson()
.toRequestBody(RestUtils.MEDIA_TYPE_JSON)
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/no/nav/veilarbvedtaksstotte/config/ClientConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ class ClientConfig {
}

@Bean
fun personClient(oboContexService: OboContexService): VeilarbpersonClient {
val clientCluster = if (isProduction) "prod-fss" else "dev-fss"
val userTokenSupplier = oboContexService.userTokenSupplier(
veilarbperson.invoke(clientCluster)
)
return VeilarbpersonClientImpl(naisPreprodOrNaisAdeoIngress("veilarbperson", true), userTokenSupplier)
fun personClient(tokenClient: AzureAdMachineToMachineTokenClient): VeilarbpersonClient {
val veilarbperson = veilarbperson.invoke(if (isProduction) "prod-fss" else "dev-fss")
val url = UrlUtils.createServiceUrl(veilarbperson.serviceName, veilarbperson.namespace, false)
return VeilarbpersonClientImpl(url){ tokenClient.createMachineToMachineToken(tokenScope(veilarbperson)) }
}

@Bean
Expand Down

0 comments on commit 68dabca

Please sign in to comment.