1
0
mirror of https://github.com/pcvolkmer/etl-processor.git synced 2025-04-19 17:26:51 +00:00

feat: Allow configuring basic auth for the rest uri (#75)

This commit is contained in:
Niklas 2024-11-01 13:56:54 +01:00 committed by GitHub
parent d258d9081b
commit 6cdbd35e64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 7 deletions

View File

@ -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

View File

@ -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}

View File

@ -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

View File

@ -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"

View File

@ -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
}
}

View File

@ -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)