46 lines
1.3 KiB
Kotlin
46 lines
1.3 KiB
Kotlin
package be.simplenotes.config
|
|
|
|
import java.util.*
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
class ConfigLoader {
|
|
//region Config loading
|
|
private val properties: Properties = javaClass
|
|
.getResource("/application.properties")
|
|
.openStream()
|
|
.use {
|
|
Properties().apply { load(it) }
|
|
}
|
|
|
|
private val env = System.getenv()
|
|
|
|
private fun value(key: String): String =
|
|
env[key.toUpperCase().replace(".", "_")]
|
|
?: properties.getProperty(key)
|
|
?: error("Missing config key $key")
|
|
//endregion
|
|
|
|
val jwtConfig
|
|
get() = JwtConfig(
|
|
secret = value("jwt.secret"),
|
|
validity = value("jwt.validity").toLong(),
|
|
timeUnit = TimeUnit.HOURS,
|
|
)
|
|
|
|
val dataSourceConfig
|
|
get() = DataSourceConfig(
|
|
jdbcUrl = value("jdbcUrl"),
|
|
driverClassName = value("driverClassName"),
|
|
username = value("username"),
|
|
password = value("password"),
|
|
maximumPoolSize = value("maximumPoolSize").toInt(),
|
|
connectionTimeout = value("connectionTimeout").toLong()
|
|
)
|
|
|
|
val serverConfig
|
|
get() = ServerConfig(
|
|
host = value("host"),
|
|
port = value("port").toInt(),
|
|
)
|
|
}
|