From 1459c010db089b2b6abc07cffb797928a9193956 Mon Sep 17 00:00:00 2001 From: Pim van Nierop Date: Thu, 7 Mar 2024 08:57:44 +0100 Subject: [PATCH] Fix withEnv mechanism Ensures base config in dashboard.yml is overwritten by environmental variables. --- .../org/radarbase/datadashboard/api/DashboardApi.kt | 2 +- .../datadashboard/api/config/DashboardApiConfig.kt | 4 +--- .../api/config/DashboardServiceConfig.kt | 11 ++++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/DashboardApi.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/DashboardApi.kt index 0d1e746..b8aced4 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/DashboardApi.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/DashboardApi.kt @@ -40,7 +40,7 @@ object Main { } val config: DashboardApiConfig = ConfigLoader.loadConfig("dashboard.yml", args) - val resources = ConfigLoader.loadResources(config.service.resourceConfig, config) + val resources = ConfigLoader.loadResources(config.service.resourceConfig, config.withEnv()) GrizzlyServer(config.service.baseUri, resources).run { listen() diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardApiConfig.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardApiConfig.kt index 451897d..aea7171 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardApiConfig.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardApiConfig.kt @@ -18,11 +18,8 @@ package org.radarbase.datadashboard.api.config -import org.radarbase.datadashboard.api.enhancer.DashBoardApiEnhancerFactory import org.radarbase.jersey.auth.AuthConfig -import org.radarbase.jersey.enhancer.EnhancerFactory import org.radarbase.jersey.hibernate.config.DatabaseConfig -import java.net.URI data class DashboardApiConfig( val service: DashboardServiceConfig = DashboardServiceConfig(), @@ -32,6 +29,7 @@ data class DashboardApiConfig( val database: DatabaseConfig = DatabaseConfig(), ) { fun withEnv(): DashboardApiConfig = copy( + service = service.withEnv(), auth = auth.withEnv(), database = database.withEnv(), ) diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardServiceConfig.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardServiceConfig.kt index 5cb44a8..4e08ba0 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardServiceConfig.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardServiceConfig.kt @@ -31,4 +31,13 @@ data class DashboardServiceConfig( val enableCors: Boolean? = false, val tokenExpiryTimeInMinutes: Long = 15, val persistentTokenExpiryInMin: Long = 3.days.inWholeMinutes, -) \ No newline at end of file +) { + fun withEnv(): DashboardServiceConfig = copy( + baseUri = URI.create(System.getenv("RADAR_DATA_DASHBOARD_BASE_URI") ?: baseUri.toString()), + advertisedBaseUri = URI.create(System.getenv("RADAR_DATA_DASHBOARD_ADVERTISED_BASE_URI") ?: advertisedBaseUri.toString()), + frontendBaseUri = URI.create(System.getenv("RADAR_DATA_DASHBOARD_FRONTEND_BASE_URI") ?: frontendBaseUri.toString()), + enableCors = System.getenv("RADAR_DATA_DASHBOARD_ENABLE_CORS")?.toBoolean() ?: enableCors, + tokenExpiryTimeInMinutes = System.getenv("RADAR_DATA_DASHBOARD_TOKEN_EXPIRY_TIME_IN_MINUTES")?.toLong() ?: tokenExpiryTimeInMinutes, + persistentTokenExpiryInMin = System.getenv("RADAR_DATA_DASHBOARD_PERSISTENT_TOKEN_EXPIRY_IN_MIN")?.toLong() ?: persistentTokenExpiryInMin, + ) +} \ No newline at end of file