diff options
| author | Niklas | 2024-11-01 13:56:54 +0100 |
|---|---|---|
| committer | GitHub | 2024-11-01 13:56:54 +0100 |
| commit | 6cdbd35e644727bc01e2e81d5deab82750b463cc (patch) | |
| tree | 52b35d9331cd94b07936265dd54f30d737755164 /src/main/kotlin | |
| parent | d258d9081b1ecdd4f6cc51c55ae25c1e2e057423 (diff) | |
feat: Allow configuring basic auth for the rest uri (#75)
Diffstat (limited to 'src/main/kotlin')
| -rw-r--r-- | src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt | 2 | ||||
| -rw-r--r-- | src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt | 20 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt index d951c60..dd7e461 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt @@ -69,6 +69,8 @@ data class GPasConfigProperties( @ConfigurationProperties(RestTargetProperties.NAME) data class RestTargetProperties( val uri: String?, + val username: String?, + val password: String?, ) { companion object { const val NAME = "app.rest" diff --git a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt index e1aecb7..58459b9 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt @@ -40,8 +40,7 @@ class RestMtbFileSender( override fun send(request: MtbFileSender.MtbFileRequest): MtbFileSender.Response { try { return retryTemplate.execute<MtbFileSender.Response, Exception> { - val headers = HttpHeaders() - headers.contentType = MediaType.APPLICATION_JSON + val headers = getHttpHeaders() val entityReq = HttpEntity(request.mtbFile, headers) val response = restTemplate.postForEntity( "${restTargetProperties.uri}/MTBFile", @@ -70,8 +69,7 @@ class RestMtbFileSender( override fun send(request: MtbFileSender.DeleteRequest): MtbFileSender.Response { try { return retryTemplate.execute<MtbFileSender.Response, Exception> { - val headers = HttpHeaders() - headers.contentType = MediaType.APPLICATION_JSON + val headers = getHttpHeaders() val entityReq = HttpEntity(null, headers) restTemplate.delete( "${restTargetProperties.uri}/Patient/${request.patientId}", @@ -94,4 +92,18 @@ class RestMtbFileSender( return this.restTargetProperties.uri.orEmpty() } + private fun getHttpHeaders(): HttpHeaders { + val username = restTargetProperties.username + val password = restTargetProperties.password + val headers = HttpHeaders() + headers.setContentType(MediaType.APPLICATION_JSON) + + if (username.isNullOrBlank() || password.isNullOrBlank()) { + return headers + } + + headers.setBasicAuth(username, password) + return headers + } + }
\ No newline at end of file |
