-
Notifications
You must be signed in to change notification settings - Fork 3
/
AppLoader.scala
37 lines (29 loc) · 1.45 KB
/
AppLoader.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import com.gu.conf.{ConfigurationLoader, FileConfigurationLocation, SSMConfigurationLocation}
import com.gu.{AppIdentity, AwsIdentity, DevIdentity}
import play.api.ApplicationLoader.Context
import play.api.{Application, ApplicationLoader, Configuration, LoggerConfigurator}
import software.amazon.awssdk.auth.credentials.{AwsCredentialsProvider, DefaultCredentialsProvider, ProfileCredentialsProvider}
import java.io.File
class AppLoader extends ApplicationLoader {
override def load(context: Context): Application = {
startLogging(context)
val appName = "atom-workshop"
val identity: AppIdentity = AppIdentity.whoAmI(appName)
val credentials: AwsCredentialsProvider = identity match {
case _: DevIdentity => ProfileCredentialsProvider.create("composer")
case _ => DefaultCredentialsProvider.create()
}
val loadedConfig = ConfigurationLoader.load(identity, credentials) {
case identity: AwsIdentity => SSMConfigurationLocation.default(identity)
case _: DevIdentity =>
val home = System.getProperty("user.home")
FileConfigurationLocation(new File(s"$home/.gu/$appName.conf"))
}
new AppComponents(context.copy(initialConfiguration = context.initialConfiguration.withFallback(Configuration(loadedConfig))), identity).application
}
private def startLogging(context: Context): Unit = {
LoggerConfigurator(context.environment.classLoader).foreach {
_.configure(context.environment)
}
}
}