aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/config.scala
blob: be814089223c60700588bce5171d632cd0b5e077 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package xyz.driver.core

import java.io.File
import com.typesafe.config.{Config, ConfigFactory}

object config {

  def loadDefaultConfig: Config = {
    val configDefaults = ConfigFactory.load(this.getClass.getClassLoader, "application.conf")

    scala.sys.env.get("APPLICATION_CONFIG").orElse(scala.sys.props.get("application.config")) match {

      case Some(filename) =>
        val configFile = new File(filename)
        if (configFile.exists()) {
          ConfigFactory.parseFile(configFile).withFallback(configDefaults)
        } else {
          throw new IllegalStateException(s"No config found at $filename")
        }

      case None => configDefaults
    }
  }
}