summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas2024-11-01 13:56:54 +0100
committerGitHub2024-11-01 13:56:54 +0100
commit6cdbd35e644727bc01e2e81d5deab82750b463cc (patch)
tree52b35d9331cd94b07936265dd54f30d737755164
parentd258d9081b1ecdd4f6cc51c55ae25c1e2e057423 (diff)
feat: Allow configuring basic auth for the rest uri (#75)
-rw-r--r--README.md2
-rw-r--r--deploy/docker-compose.yaml2
-rw-r--r--deploy/env-sample.env2
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/config/AppConfigProperties.kt2
-rw-r--r--src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt20
-rw-r--r--src/test/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSenderTest.kt6
6 files changed, 27 insertions, 7 deletions
diff --git a/README.md b/README.md
index 258c13b..45efef9 100644
--- a/README.md
+++ b/README.md
@@ -197,6 +197,8 @@ Werden sowohl REST als auch Kafka-Endpunkt konfiguriert, wird nur der REST-Endpu
Folgende Umgebungsvariablen müssen gesetzt sein, damit ein bwHC-MTB-File an das bwHC-Backend gesendet wird:
* `APP_REST_URI`: URI der zu benutzenden API der bwHC-Backend-Instanz. z.B.: `http://localhost:9000/bwhc/etl/api`
+* `APP_REST_USERNAME`: Basic-Auth-Benutzername für bwHC-Backend
+* `APP_REST_PASSWORD`: Basic-Auth-Passwort für bwHC-Backend
#### Kafka-Topics
diff --git a/deploy/docker-compose.yaml b/deploy/docker-compose.yaml
index 4641ca6..2180786 100644
--- a/deploy/docker-compose.yaml
+++ b/deploy/docker-compose.yaml
@@ -18,6 +18,8 @@ services:
APP_KAFKA_GROUP_ID: ${DNPM_KAFKA_GROUP_ID}
APP_KAFKA_RESPONSE_TOPIC: ${DNPM_KAFKA_RESPONSE_TOPIC}
APP_REST_URI: ${DNPM_BWHC_REST_URI}
+ APP_REST_USERNAME: ${DNPM_BWHC_REST_USERNAME}
+ APP_REST_PASSWORD: ${DNPM_BWHC_REST_PASSWORD}
APP_SECURITY_ADMIN_USER: ${DNPM_ADMIN_USER}
APP_SECURITY_ADMIN_PASSWORD: ${DNPM_ADMIN_PASSWORD}
SPRING_DATASOURCE_URL: ${DNPM_DATASOURCE_URL}
diff --git a/deploy/env-sample.env b/deploy/env-sample.env
index 04a3f8f..9c06341 100644
--- a/deploy/env-sample.env
+++ b/deploy/env-sample.env
@@ -28,6 +28,8 @@ DNPM_DATASOURCE_URL=jdbc:mariadb://dnpm-monitor-db:3306/$DNPM_MARIADB_DB
## TARGET SYSTEMS CONFIG
# in case of direct access to bwhc enter endpoint url here
DNPM_BWHC_REST_URI=
+DNPM_BWHC_REST_USERNAME=
+DNPM_BWHC_REST_PASSWORD=
# produce mtb files to this topic - values 'false' disabling kafka processing
DNPM_KAFKA_TOPIC=false
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
diff --git a/src/test/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSenderTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSenderTest.kt
index 9cc1437..9b6332a 100644
--- a/src/test/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSenderTest.kt
+++ b/src/test/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSenderTest.kt
@@ -48,7 +48,7 @@ class RestMtbFileSenderTest {
@BeforeEach
fun setup() {
val restTemplate = RestTemplate()
- val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile")
+ val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile", null, null)
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(1)).build()
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
@@ -90,7 +90,7 @@ class RestMtbFileSenderTest {
@MethodSource("mtbFileRequestWithResponseSource")
fun shouldRetryOnMtbFileHttpRequestError(requestWithResponse: RequestWithResponse) {
val restTemplate = RestTemplate()
- val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile")
+ val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile", null, null)
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)
@@ -119,7 +119,7 @@ class RestMtbFileSenderTest {
@MethodSource("deleteRequestWithResponseSource")
fun shouldRetryOnDeleteHttpRequestError(requestWithResponse: RequestWithResponse) {
val restTemplate = RestTemplate()
- val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile")
+ val restTargetProperties = RestTargetProperties("http://localhost:9000/mtbfile", null, null)
val retryTemplate = RetryTemplateBuilder().customPolicy(SimpleRetryPolicy(3)).build()
this.mockRestServiceServer = MockRestServiceServer.createServer(restTemplate)