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

bump sosialhjelp-common #337

Merged
merged 23 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Versions {
const val kotlin = "1.4.21"
const val coroutines = "1.4.2"
const val springBoot = "2.4.3"
const val sosialhjelpCommon = "1.1c8e196"
const val sosialhjelpCommon = "1.8f11108"
const val logback = "1.2.3"
const val logstash = "6.5"
const val filformat = "1.2021.03.02-10.58-415c44e55124"
Expand Down Expand Up @@ -82,6 +82,7 @@ dependencies {
// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:${Versions.coroutines}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:${Versions.coroutines}")

// Spring
implementation("org.springframework.boot:spring-boot-starter-web:${Versions.springBoot}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,29 @@ import no.nav.sosialhjelp.innsyn.config.ClientProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import org.springframework.web.client.RestTemplate
import org.springframework.web.reactive.function.client.WebClient

@Profile("!mock")
@Configuration
class KommuneInfoClientConfig {
class KommuneInfoClientConfig(
private val proxiedWebClient: WebClient,
private val clientProperties: ClientProperties
) {

@Bean
fun kommuneInfoClient(restTemplate: RestTemplate, clientProperties: ClientProperties): KommuneInfoClient {
fun kommuneInfoClient(): KommuneInfoClient {
return KommuneInfoClientImpl(
restTemplate,
toFiksProperties(clientProperties)
proxiedWebClient,
fiksProperties()
)
}

private fun toFiksProperties(clientProperties: ClientProperties): FiksProperties {
private fun fiksProperties(): FiksProperties {
return FiksProperties(
clientProperties.fiksDigisosEndpointUrl + FiksPaths.PATH_KOMMUNEINFO,
clientProperties.fiksDigisosEndpointUrl + FiksPaths.PATH_ALLE_KOMMUNEINFO,
clientProperties.fiksIntegrasjonId,
clientProperties.fiksIntegrasjonpassord
clientProperties.fiksDigisosEndpointUrl + FiksPaths.PATH_KOMMUNEINFO,
clientProperties.fiksDigisosEndpointUrl + FiksPaths.PATH_ALLE_KOMMUNEINFO,
clientProperties.fiksIntegrasjonId,
clientProperties.fiksIntegrasjonpassord
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,37 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import org.springframework.web.client.RestTemplate
import org.springframework.web.reactive.function.client.WebClient

@Profile("!mock")
siljee marked this conversation as resolved.
Show resolved Hide resolved
@Configuration
class IdPortenClientConfig(
@Value("\${no.nav.sosialhjelp.idporten.token_url}") private val tokenUrl: String,
@Value("\${no.nav.sosialhjelp.idporten.client_id}") private val clientId: String,
@Value("\${no.nav.sosialhjelp.idporten.scope}") private val scope: String,
@Value("\${no.nav.sosialhjelp.idporten.config_url}") private val configUrl: String,
@Value("\${no.nav.sosialhjelp.idporten.truststore_type}") private val truststoreType: String,
@Value("\${no.nav.sosialhjelp.idporten.truststore_filepath}") private val truststoreFilepath: String
private val proxiedWebClient: WebClient,
@Value("\${no.nav.sosialhjelp.idporten.token_url}") private val tokenUrl: String,
@Value("\${no.nav.sosialhjelp.idporten.client_id}") private val clientId: String,
@Value("\${no.nav.sosialhjelp.idporten.scope}") private val scope: String,
@Value("\${no.nav.sosialhjelp.idporten.config_url}") private val configUrl: String,
@Value("\${no.nav.sosialhjelp.idporten.truststore_type}") private val truststoreType: String,
@Value("\${no.nav.sosialhjelp.idporten.truststore_filepath}") private val truststoreFilepath: String,
) {

@Bean
fun idPortenClient(restTemplate: RestTemplate): IdPortenClient {
fun idPortenClient(): IdPortenClient {
return IdPortenClient(
restTemplate = restTemplate,
idPortenProperties = idPortenProperties()
webClient = proxiedWebClient,
idPortenProperties = idPortenProperties()
)
}

fun idPortenProperties(): IdPortenProperties {
return IdPortenProperties(
tokenUrl = tokenUrl,
clientId = clientId,
scope = scope,
configUrl = configUrl,
truststoreType = truststoreType,
truststoreFilepath = truststoreFilepath,
virksomhetSertifikatPath = getenv("VIRKSERT_STI", "/var/run/secrets/nais.io/virksomhetssertifikat")
tokenUrl = tokenUrl,
clientId = clientId,
scope = scope,
configUrl = configUrl,
truststoreType = truststoreType,
truststoreFilepath = truststoreFilepath,
virksomhetSertifikatPath = getenv("VIRKSERT_STI", "/var/run/secrets/nais.io/virksomhetssertifikat")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import no.nav.sosialhjelp.innsyn.utils.IntegrationUtils.forwardHeaders
import no.nav.sosialhjelp.innsyn.utils.logger
import no.nav.sosialhjelp.innsyn.utils.mdc.MDCUtils
import no.nav.sosialhjelp.innsyn.utils.objectMapper
import no.nav.sosialhjelp.innsyn.utils.withStatusCode
import org.springframework.context.annotation.Profile
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
Expand Down Expand Up @@ -69,6 +70,7 @@ class NorgClientImpl(
}
}
.bodyToMono<String>()

siljee marked this conversation as resolved.
Show resolved Hide resolved
.block()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package no.nav.sosialhjelp.innsyn.config

import no.nav.sosialhjelp.innsyn.utils.getReactorClientHttpConnector
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Profile("!(mock|mock-alt|local)")
@Configuration
class ProxiedWebClientConfig(
private val webClientBuilder: WebClient.Builder
) {

@Value("\${HTTPS_PROXY}")
private lateinit var proxyUrl: String

@Bean
fun proxiedWebClient(): WebClient =
webClientBuilder
.clientConnector(getReactorClientHttpConnector(proxyUrl))
.build()

}

@Profile("mock|mock-alt|local")
@Configuration
class MockProxiedWebClientConfig(
private val webClientBuilder: WebClient.Builder
) {

@Bean
fun proxiedWebClient(): WebClient =
webClientBuilder
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.build()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package no.nav.sosialhjelp.innsyn.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class WebClientConfig(
private val webClientBuilder: WebClient.Builder,
) {
@Bean
fun webClient(): WebClient =
webClientBuilder
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import no.nav.sosialhjelp.selftest.Importance
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component

@Profile("!mock")
@Profile("!(mock | local)")
@Component
class StsCheck(
clientProperties: ClientProperties,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package no.nav.sosialhjelp.innsyn.utils

import org.springframework.http.client.reactive.ReactorClientHttpConnector
import reactor.netty.http.client.HttpClient
import reactor.netty.transport.ProxyProvider
import java.net.URL

fun getReactorClientHttpConnector(proxyUrl: String): ReactorClientHttpConnector {
val uri = URL(proxyUrl)

val httpClient: HttpClient = HttpClient.create()
.proxy { proxy ->
proxy.type(ProxyProvider.Proxy.HTTP).host(uri.host).port(uri.port)
}

return ReactorClientHttpConnector(httpClient)
}
5 changes: 5 additions & 0 deletions src/main/kotlin/no/nav/sosialhjelp/innsyn/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.slf4j.MDC
import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.HttpStatus
import org.springframework.web.client.HttpStatusCodeException
import org.springframework.web.reactive.function.client.WebClientResponseException
import java.io.IOException
import java.sql.Timestamp
import java.time.Instant
Expand Down Expand Up @@ -138,6 +140,9 @@ val ErrorMessage.feilmeldingUtenFnr: String?
return this.message?.feilmeldingUtenFnr
}

fun withStatusCode(t: Throwable): HttpStatus? =
martintveter marked this conversation as resolved.
Show resolved Hide resolved
(t as? WebClientResponseException)?.statusCode

fun runAsyncWithMDC(runnable: Runnable, executor: ExecutorService): CompletableFuture<Void> {
val previous: Map<String, String> = MDC.getCopyOfContextMap()
return CompletableFuture.runAsync(Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package no.nav.sosialhjelp.innsyn

import com.ninjasquad.springmockk.MockkBean
import no.nav.sosialhjelp.idporten.client.IdPortenClient
import no.nav.sosialhjelp.innsyn.config.ProxiedWebClientConfig
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import org.springframework.web.client.RestTemplate
import org.springframework.web.reactive.function.client.WebClient

@SpringBootTest(classes = [TestApplication::class], webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles(profiles = ["no-redis"])
Expand All @@ -14,6 +16,12 @@ class ApplicationContextTest {
@MockkBean
private lateinit var idPortenClient: IdPortenClient

@MockkBean(name = "proxiedWebClient")
private lateinit var proxiedWebClient: WebClient

@MockkBean
private lateinit var proxiedWebClientConfig: ProxiedWebClientConfig

@MockkBean(name = "stsRestTemplate")
private lateinit var stsRestTemplate: RestTemplate

Expand Down