Skip to content

Commit

Permalink
Replaces yaml with env variable. Defaults added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewan Donovan committed Feb 3, 2025
1 parent f37943e commit 1995268
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 21 deletions.
3 changes: 3 additions & 0 deletions helm_deploy/hmpps-learner-records-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ generic-service:
PFX_FILE_PASSWORD: "PFX_FILE_PASSWORD"
UK_PRN: "UK_PRN"
VENDOR_ID: "VENDOR_ID"
LRS_CONNECT_TIMEOUT: 20
LRS_WRITE_TIMEOUT: 20
LRS_READ_TIMEOUT: 20

allowlist:
groups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import org.springframework.context.annotation.Configuration
@Configuration
class AppConfig {
fun ukprn(): String = System.getenv("UK_PRN") ?: throw IllegalArgumentException("UK_PRN environment variable not found.")

fun password(): String = System.getenv("ORG_PASSWORD") ?: throw IllegalArgumentException("ORG_PASSWORD environment variable not found.")

fun vendorId(): String = System.getenv("VENDOR_ID") ?: throw IllegalArgumentException("VENDOR_ID environment variable not found.")
fun lrsConnectTimeout(): Long = (System.getenv("LRS_CONNECT_TIMEOUT") ?: "20").toLong()
fun lrsWriteTimeout(): Long = (System.getenv("LRS_WRITE_TIMEOUT") ?: "20").toLong()
fun lrsReadTimeout(): Long = (System.getenv("LRS_READ_TIMEOUT") ?: "20").toLong()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.logging.HttpLoggingInterceptor.Level
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
import retrofit2.Retrofit
Expand All @@ -14,9 +15,8 @@ import java.util.concurrent.TimeUnit
class HttpClientConfiguration(
@Value("\${lrs.pfx-path}") val pfxFilePath: String,
@Value("\${lrs.base-url}") val baseUrl: String,
@Value("\${lrs.connectTimeoutSeconds}") val connectTimeoutSeconds: Int,
@Value("\${lrs.writeTimeoutSeconds}") val writeTimeoutSeconds: Int,
@Value("\${lrs.readTimeoutSeconds}") val readTimeoutSeconds: Int,
@Autowired
private val appConfig: AppConfig,
) {
fun buildSSLHttpClient(): OkHttpClient {
log.info("Building HTTP client with SSL")
Expand All @@ -29,9 +29,9 @@ class HttpClientConfiguration(
val trustManager = sslContextConfiguration.getTrustManager()

val httpClientBuilder = OkHttpClient.Builder()
.connectTimeout(connectTimeoutSeconds.toLong(), TimeUnit.SECONDS)
.writeTimeout(writeTimeoutSeconds.toLong(), TimeUnit.SECONDS)
.readTimeout(readTimeoutSeconds.toLong(), TimeUnit.SECONDS)
.connectTimeout(appConfig.lrsConnectTimeout(), TimeUnit.SECONDS)
.writeTimeout(appConfig.lrsWriteTimeout(), TimeUnit.SECONDS)
.readTimeout(appConfig.lrsReadTimeout(), TimeUnit.SECONDS)
.sslSocketFactory(sslContext.socketFactory, trustManager)
.addInterceptor(loggingInterceptor)

Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ hmpps-auth:
lrs:
base-url: "https://cmp-ws.dev.lrs.education.gov.uk"
pfx-path: "WebServiceClientCert.pfx"
connectTimeoutSeconds: 20
writeTimeoutSeconds: 20
readTimeoutSeconds: 20
3 changes: 0 additions & 3 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ hmpps-auth:
lrs:
base-url: "http://lrs-api:8080"
pfx-path: "WebServiceClientCert.pfx"
connectTimeoutSeconds: 20
writeTimeoutSeconds: 20
readTimeoutSeconds: 20
3 changes: 0 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,3 @@ management:
lrs:
base-url: ${lrs.base-url}
pfx-path: ${lrs.pfx-path}
connectTimeoutSeconds: 20
writeTimeoutSeconds: 20
readTimeoutSeconds: 20
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class HmppsBoldLrsExceptionHandlerTest : IntegrationTestBase() {
}

@Test
fun `should catch timeout exceptions (SocketTimeoutException) and return Gateway Timeout`() {
fun `should catch timeout exceptions (SocketTimeoutException) and return Request Timeout`() {
val expectedResponse = HmppsBoldLrsExceptionHandler.ErrorResponse(
status = HttpStatus.REQUEST_TIMEOUT,
errorCode = "Request Timeout",
Expand Down
3 changes: 0 additions & 3 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ hmpps-auth:
lrs:
base-url: "http://localhost:8082"
pfx-path: "WebServiceClientCert.pfx"
connectTimeoutSeconds: 3
writeTimeoutSeconds: 3
readTimeoutSeconds: 3

0 comments on commit 1995268

Please sign in to comment.