Skip to content

Commit

Permalink
Fix withEnv mechanism
Browse files Browse the repository at this point in the history
Ensures base config in dashboard.yml is overwritten by environmental variables.
  • Loading branch information
pvannierop committed Mar 7, 2024
1 parent 6377c6d commit 1459c01
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -32,6 +29,7 @@ data class DashboardApiConfig(
val database: DatabaseConfig = DatabaseConfig(),
) {
fun withEnv(): DashboardApiConfig = copy(
service = service.withEnv(),
auth = auth.withEnv(),
database = database.withEnv(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ data class DashboardServiceConfig(
val enableCors: Boolean? = false,
val tokenExpiryTimeInMinutes: Long = 15,
val persistentTokenExpiryInMin: Long = 3.days.inWholeMinutes,
)
) {
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,
)
}

0 comments on commit 1459c01

Please sign in to comment.