Skip to content

Commit

Permalink
bump sosialhjelp-common (#337)
Browse files Browse the repository at this point in the history
* proxiedWebClientBuilder dras inn i idportenclientConfig og kommuneinfoclientConfig
  • Loading branch information
martintveter committed Mar 16, 2021
1 parent 91b44af commit 35e66f9
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 29 deletions.
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 proxiedWebClientBuilder: WebClient.Builder,
private val clientProperties: ClientProperties
) {

@Bean
fun kommuneInfoClient(restTemplate: RestTemplate, clientProperties: ClientProperties): KommuneInfoClient {
fun kommuneInfoClient(): KommuneInfoClient {
return KommuneInfoClientImpl(
restTemplate,
toFiksProperties(clientProperties)
proxiedWebClientBuilder.build(),
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")
@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 proxiedWebClientBuilder: WebClient.Builder,
@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 = proxiedWebClientBuilder.build(),
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 @@ -69,6 +69,7 @@ class NorgClientImpl(
}
}
.bodyToMono<String>()

.block()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 {

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

@Bean
fun proxiedWebClientBuilder(): WebClient.Builder =
WebClient.builder()
.clientConnector(getReactorClientHttpConnector(proxyUrl))

}

@Profile("mock|mock-alt|local")
@Configuration
class MockProxiedWebClientConfig {

@Bean
fun proxiedWebClientBuilder(): WebClient.Builder =
WebClient.builder()
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))

}
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
17 changes: 17 additions & 0 deletions src/main/kotlin/no/nav/sosialhjelp/innsyn/utils/HttpClientUtil.kt
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)
}
1 change: 1 addition & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</appender>

<logger name="no.nav.sosialhjelp.innsyn" level="DEBUG"/>
<logger name="no.nav.sosialhjelp.idporten" level="DEBUG"/>
<logger name="org.springframework" level="INFO"/>
<logger name="org.springframework.security" level="INFO"/>
<logger name="org.springframework.web" level="INFO"/>
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 = "proxiedWebClientBuilder", relaxed = true)
private lateinit var proxiedWebClientBuilder: WebClient.Builder

@MockkBean
private lateinit var proxiedWebClientConfig: ProxiedWebClientConfig

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

Expand Down

0 comments on commit 35e66f9

Please sign in to comment.