Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fun main(args: Array<String>) {
),
args,
).withDefaults()
.withEnv()
} catch (ex: IllegalArgumentException) {
logger.error("No configuration file was found.")
logger.error("Usage: radar-gateway <config-file>")
Expand All @@ -27,7 +28,6 @@ fun main(args: Array<String>) {

try {
config.validate()
config.checkEnvironmentVars()
} catch (ex: IllegalStateException) {
logger.error("Configuration incomplete: {}", ex.message)
exitProcess(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.radarbase.gateway.config

import org.radarbase.gateway.inject.ManagementPortalEnhancerFactory
import org.radarbase.jersey.config.ConfigLoader.copyOnChange
import org.radarbase.jersey.enhancer.EnhancerFactory

data class GatewayConfig(
Expand Down Expand Up @@ -29,7 +30,13 @@ data class GatewayConfig(
auth.validate()
}

fun checkEnvironmentVars() {
s3.checkEnvironmentVars()
}
fun withEnv(): GatewayConfig = this.copyOnChange(
s3,
{
it.withEnv()
},
{
copy(s3 = it)
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,40 @@ import org.radarbase.gateway.utils.Env.AWS_DEFAULT_REGION
import org.radarbase.gateway.utils.Env.AWS_ENDPOINT_URL_S3
import org.radarbase.gateway.utils.Env.AWS_S3_BUCKET_NAME
import org.radarbase.gateway.utils.Env.AWS_SECRET_ACCESS_KEY
import org.radarbase.jersey.config.ConfigLoader.copyEnv
import org.radarbase.jersey.config.ConfigLoader.copyOnChange

data class S3StorageConfig(
var url: String? = null,
var accessKey: String? = null,
var secretKey: String? = null,
var bucketName: String? = null,
var region: String? = null,
var path: S3StoragePathConfig = S3StoragePathConfig(),
val url: String? = null,
val accessKey: String? = null,
val secretKey: String? = null,
val bucketName: String? = null,
val region: String? = null,
val path: S3StoragePathConfig = S3StoragePathConfig(),
) {
fun checkEnvironmentVars() {
url ?: run {
url = System.getenv(AWS_ENDPOINT_URL_S3)
fun withEnv(): S3StorageConfig = this
.copyEnv(AWS_ENDPOINT_URL_S3) {
copy(url = it)
}
accessKey ?: run {
accessKey = System.getenv(AWS_ACCESS_KEY_ID)
.copyEnv(AWS_ACCESS_KEY_ID) {
copy(accessKey = it)
}
secretKey ?: run {
secretKey = System.getenv(AWS_SECRET_ACCESS_KEY)
.copyEnv(AWS_SECRET_ACCESS_KEY) {
copy(secretKey = it)
}
bucketName ?: run {
bucketName = System.getenv(AWS_S3_BUCKET_NAME)
.copyEnv(AWS_S3_BUCKET_NAME) {
copy(bucketName = it)
}
region ?: run {
region = System.getenv(AWS_DEFAULT_REGION)
.copyEnv(AWS_DEFAULT_REGION) {
copy(region = it)
}
path.checkEnvironmentVars()
}
.copyOnChange(
path,
{
it.withEnv()
},
{
copy(path = it)
},
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.radarbase.gateway.config

import org.radarbase.gateway.utils.Env.AWS_S3_PATH_PREFIX
import org.radarbase.jersey.config.ConfigLoader.copyEnv

data class S3StoragePathConfig(
var prefix: String? = null,
var collectPerDay: Boolean = true,
val prefix: String? = null,
val collectPerDay: Boolean = true,
) {
fun checkEnvironmentVars() {
prefix ?: run {
prefix = System.getenv(AWS_S3_PATH_PREFIX)
fun withEnv(): S3StoragePathConfig = this
.copyEnv(AWS_S3_PATH_PREFIX) {
copy(prefix = it)
}
}
}
Loading