-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
732df86
commit c398929
Showing
10 changed files
with
48 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,51 @@ | ||
package load | ||
|
||
import com.gu.conf.{ | ||
ComposedConfigurationLocation, | ||
ConfigurationLoader, | ||
ResourceConfigurationLocation, | ||
SSMConfigurationLocation | ||
} | ||
import com.gu.{AppIdentity, AwsIdentity} | ||
import play.api.* | ||
import play.api.ApplicationLoader.Context | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider | ||
|
||
import scala.util.{Failure, Success, Try} | ||
|
||
class AppLoader extends ApplicationLoader { | ||
|
||
private val appName = "gatehouse" | ||
|
||
override def load(context: Context): Application = { | ||
LoggerConfigurator(context.environment.classLoader).foreach { | ||
_.configure(context.environment, context.initialConfiguration, Map.empty) | ||
val credentialsProvider = DefaultCredentialsProvider.create() | ||
val isDev = context.environment.mode == Mode.Dev | ||
LoggerConfigurator(context.environment.classLoader) foreach { _.configure(context.environment) } | ||
|
||
val loadedConfig = | ||
for { | ||
identity <- | ||
if (isDev) | ||
Success(AwsIdentity(app = appName, stack = "identity", stage = "DEV", region = "eu-west-1")) | ||
else | ||
AppIdentity.whoAmI(defaultAppName = appName, credentialsProvider) | ||
config <- Try(ConfigurationLoader.load(identity, credentialsProvider) { case identity: AwsIdentity => | ||
ComposedConfigurationLocation( | ||
List( | ||
SSMConfigurationLocation.default(identity), | ||
ResourceConfigurationLocation(s"${identity.stage}.conf"), | ||
) | ||
) | ||
}) | ||
} yield config | ||
|
||
loadedConfig match { | ||
case Success(config) => | ||
val newContext = | ||
context.copy(initialConfiguration = Configuration(config).withFallback(context.initialConfiguration)) | ||
new AppComponents(newContext).application | ||
case Failure(exception) => | ||
throw exception | ||
} | ||
new AppComponents(context).application | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include "application.conf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include "application.conf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include "application.conf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
# https://www.playframework.com/documentation/latest/Configuration | ||
include file("/etc/gatehouse/stage.conf") | ||
|
||
play.application.loader=load.AppLoader | ||
|
||
play.application.loader = load.AppLoader | ||
play.filters.hosts.routeModifiers.whiteList = [anyhost] | ||
play.http.secret.key = "changeme" |