mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-01-19 18:44:45 +00:00
Load config with ConfigSource.default to allow environment variables or java opts to override config values
This commit is contained in:
parent
cada786010
commit
0bb681babc
|
|
@ -183,16 +183,6 @@ object Server {
|
|||
loggerContext.reset()
|
||||
configurator.doConfigure(loggerConfigPath)
|
||||
|
||||
Config.result match {
|
||||
case Left(failures) =>
|
||||
logger.error("Loading config failed")
|
||||
failures.toList.foreach { failure =>
|
||||
logger.error(failure.toString)
|
||||
}
|
||||
sys.exit(1)
|
||||
case Right(_) =>
|
||||
}
|
||||
|
||||
val builder = OParser.builder[CliConfig]
|
||||
|
||||
val parser = {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import scala.reflect.ClassTag
|
|||
import pureconfig.generic.auto._ // intellij: this is not unused
|
||||
|
||||
object Config {
|
||||
private val logger = org.log4s.getLogger
|
||||
|
||||
// prog.home is defined when we are running from SBT pack
|
||||
val directory: String = System.getProperty("prog.home") match {
|
||||
case null =>
|
||||
|
|
@ -53,18 +55,34 @@ object Config {
|
|||
private val source = {
|
||||
val configFile = Paths.get(directory, "psforever.conf").toFile
|
||||
if (configFile.exists)
|
||||
ConfigSource.file(configFile).withFallback(ConfigSource.defaultApplication)
|
||||
ConfigSource.file(configFile).withFallback(ConfigSource.default)
|
||||
else
|
||||
ConfigSource.defaultApplication
|
||||
ConfigSource.default
|
||||
}
|
||||
|
||||
val result: Result[AppConfig] = source.load[AppConfig]
|
||||
|
||||
// Raw config object - prefer app when possible
|
||||
lazy val config: TypesafeConfig = source.config().toOption.get
|
||||
lazy val config: TypesafeConfig = source.config() match {
|
||||
case Right(config) => config
|
||||
case Left(failures) => {
|
||||
logger.error("Loading config failed")
|
||||
failures.toList.foreach { failure =>
|
||||
logger.error(failure.toString)
|
||||
}
|
||||
sys.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Typed config object
|
||||
lazy val app: AppConfig = result.toOption.get
|
||||
lazy val app: AppConfig = source.load[AppConfig] match {
|
||||
case Right(config) => config
|
||||
case Left(failures) => {
|
||||
logger.error("Loading config failed")
|
||||
failures.toList.foreach { failure =>
|
||||
logger.error(failure.toString)
|
||||
}
|
||||
sys.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case class AppConfig(
|
||||
|
|
|
|||
Loading…
Reference in a new issue