-
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 41bd21a
Showing
11 changed files
with
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,30 @@ | ||
# Gatehouse | ||
|
||
## Configuration | ||
|
||
The app configuration has three levels of precedence. Any values repeated at a higher level will override those at a lower | ||
level. | ||
The levels are, in order of precedence: | ||
|
||
### 1. SSM parameters | ||
Secret and private settings are stored as | ||
[AWS SSM parameters](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html), | ||
named in the format: | ||
`/<stage>/identity/gatehouse/<param key>` | ||
where `param key` is a slash-separated | ||
[Hocon](https://github.com/lightbend/config/blob/main/HOCON.md) key. | ||
|
||
Eg. | ||
`/CODE/identity/gatehouse/play/http/secret/key` | ||
would give us a `play.http.secret.key` value. | ||
|
||
Secrets are stored as `SecureString` parameters. | ||
Private settings are stored as `String` parameters. | ||
|
||
### 2. Stage-specific settings | ||
Settings that aren't private but vary between deployment stages are set in the stage-specific config files in | ||
the `conf` directory. These might be values that we expose in browsers, for example. | ||
|
||
### 3. Global settings | ||
Finally, settings that aren't private and are the same for all deployment stages are set in the `conf/application.conf` | ||
file. |
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,52 @@ | ||
package load | ||
|
||
import com.gu.conf.{ | ||
ComposedConfigurationLocation, | ||
ConfigurationLoader, | ||
ResourceConfigurationLocation, | ||
SSMConfigurationLocation | ||
} | ||
import com.gu.{AppIdentity, AwsIdentity} | ||
import com.typesafe.config.Config | ||
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" | ||
|
||
private def buildConfig(context: Context): Try[Config] = { | ||
val credentialsProvider = DefaultCredentialsProvider.create() | ||
val isDev = context.environment.mode == Mode.Dev | ||
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 | ||
} | ||
|
||
override def load(context: Context): Application = { | ||
LoggerConfigurator(context.environment.classLoader).foreach { | ||
_.configure(context.environment, context.initialConfiguration, Map.empty) | ||
LoggerConfigurator(context.environment.classLoader) foreach { _.configure(context.environment) } | ||
buildConfig(context) 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,3 @@ | ||
# 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] |