Skip to content

Commit

Permalink
Bytt til ny url for spk, bruk maskinporten-token
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfofanov committed Nov 28, 2024
1 parent 99d543e commit e673b5c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class WebClientConfig {
}

@Bean
fun spkWebClient(
fun spk2025WebClient(
client: HttpClient,
maskinportenTokenClient: MaskinportenTokenClient,
@Value("\${oftp.2025.spk.endpoint.url}") baseUrl: String,
Expand All @@ -61,6 +61,14 @@ class WebClientConfig {
return opprettWebClient(client, baseUrl, maskinportenTokenClient, scope)
}

@Bean
fun spkPre2025Client(
client: HttpClient,
maskinportenTokenClient: MaskinportenTokenClient,
@Value("\${oftp.pre2025.spk.endpoint.url}") baseUrl: String,
@Value("\${oftp.pre2025.spk.endpoint.maskinportenscope}") scope: String,
): WebClient = opprettWebClient(client, baseUrl, maskinportenTokenClient, scope)

private fun opprettWebClient(
client: HttpClient,
baseUrl: String,
Expand Down Expand Up @@ -131,26 +139,6 @@ class WebClientConfig {
.build()
}

@Bean
fun restGatewayWebClient(
@Value("\${pen.fss.gateway.url}") baseUrl: String,
@Value("\${pen.fss.gateway.scope}") fssGatewayScope: String,
builder: WebClient.Builder,
httpClient: HttpClient,
adClient: AADClient
): WebClient = builder
.baseUrl(baseUrl)
.clientConnector(ReactorClientHttpConnector(httpClient))
.filter { request, next ->
next.exchange(
ClientRequest.from(request)
.headers { it.setBearerAuth(adClient.getToken(fssGatewayScope)) }
.build()
)
}
.filter { request, next -> addCorrelationId(next, request) }
.build()

companion object {
private const val CONNECT_TIMEOUT_MILLIS = 3000
const val READ_TIMEOUT_SECONDS = 45
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,25 @@ import no.nav.tjenestepensjon.simulering.model.domain.TPOrdningIdDto
import no.nav.tjenestepensjon.simulering.v2.models.domain.SivilstandCodeEnum
import no.nav.tjenestepensjon.simulering.v2.models.request.SimulerPensjonRequestV2
import no.nav.tjenestepensjon.simulering.v2.models.response.SimulerOffentligTjenestepensjonResponse
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.bodyToMono

@Service
class RestClient(
private val restGatewayWebClient: WebClient,
@Value("\${oftp.before2025.spk.maskinportenscope}") private val scope: String,
) {
class RestClient(private val spkPre2025Client: WebClient) {

fun getResponse(request: SimulerPensjonRequestV2, tpOrdning: TPOrdningIdDto): SimulerOffentligTjenestepensjonResponse = restGatewayWebClient
fun getResponse(request: SimulerPensjonRequestV2, tpOrdning: TPOrdningIdDto): SimulerOffentligTjenestepensjonResponse = spkPre2025Client
.post()
.uri("/medlem/pensjon/prognose/v1")
.header("scope", scope)
.uri("/nav/pensjon/prognose/v1")
.bodyValue(request)
.retrieve()
.bodyToMono<SimulerOffentligTjenestepensjonResponse>()
.block()
?: SimulerOffentligTjenestepensjonResponse(request.sisteTpnr, tpOrdning.tpId)

fun ping(): String = restGatewayWebClient
fun ping(): String = spkPre2025Client
.post()
.uri("/medlem/pensjon/prognose/v1")
.header("scope", scope)
.uri("/nav/pensjon/prognose/v1")
.bodyValue(dummyRequest())
.retrieve()
.bodyToMono(String::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
import org.springframework.web.reactive.function.client.bodyToMono

@Service
class SPKTjenestepensjonClient(private val spkWebClient: WebClient) : TjenestepensjonV2025Client, Pingable {
class SPKTjenestepensjonClient(private val spk2025WebClient: WebClient) : TjenestepensjonV2025Client, Pingable {
private val log = KotlinLogging.logger {}

override fun simuler(request: SimulerTjenestepensjonRequestDto): Result<SimulertTjenestepensjon> {
try {
val response = spkWebClient
val response = spk2025WebClient
.post()
.uri(SIMULER_PATH)
.bodyValue(SPKMapper.mapToRequest(request))
Expand All @@ -41,7 +41,7 @@ class SPKTjenestepensjonClient(private val spkWebClient: WebClient) : Tjenestepe

override fun ping(): PingResponse {
try {
val response = spkWebClient.get()
val response = spk2025WebClient.get()
.uri(PING_PATH)
.retrieve()
.bodyToMono<String>()
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/application-dev-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ klp:
spk:
name: SPK
implementation: REST
simuleringUrl: https://api.preprod.spk.no/medlem/pensjon/prognose/v1
simuleringUrl: https://api.test.spk.no/nav/pensjon/prognose/v1
stillingsprosentUrl: https://partner-gw-test.spk.no/nav/SimulereTjenestepensjon
storebrand:
name: STOREBRAND
Expand All @@ -45,3 +45,8 @@ oftp:
endpoint:
url: https://api.test.spk.no
maskinportenscope: spk:nav
pre2025:
spk:
endpoint:
url: https://api.test.spk.no
maskinportenscope: spk:nav
6 changes: 4 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ oftp:
endpoint:
url: https://api.prod.spk.no
maskinportenscope: spk:nav
before2025:
pre2025:
spk:
maskinportenscope: spk:nav
endpoint:
url: https://api.prod.spk.no
maskinportenscope: spk:nav
6 changes: 4 additions & 2 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ oftp:
endpoint:
url: http://localhost:8080
maskinportenscope: spk:nav
before2025:
pre2025:
spk:
maskinportenscope: spk:nav
endpoint:
url: https://api.test.spk.no
maskinportenscope: spk:nav

0 comments on commit e673b5c

Please sign in to comment.