From 22084d0af96cd7631d1261c2adf261bb9f39eed5 Mon Sep 17 00:00:00 2001 From: Damien Bailly Date: Thu, 1 Feb 2018 10:42:34 +0000 Subject: [PATCH 1/3] Fix SwaggerUI --- src/main/g8/build.sbt | 8 ++- src/main/g8/docker/docker-compose-perf.yml | 2 +- src/main/g8/docker/docker-compose.yml | 3 +- ...\"norm,word,Camel\"$IntegrationTest.scala" | 41 +++++------- .../core/config/ConfigHelper.scala" | 44 ------------ .../resources/$name;format=\"norm\"$.yml" | 0 src/main/g8/play/src/main/resources/env.conf | 2 + src/main/g8/play/src/main/resources/play.conf | 17 ++++- .../core/api/routers/CoreRouter.scala" | 36 +++++----- .../core/api/routers/routers.scala" | 67 +++++++++++++++++++ .../$name;format=\"norm,word\"$.yml" | 0 .../core/api/routers/CoreRouterSpec.scala" | 32 ++------- .../g8/project/ProjectDockerBuildPlugin.scala | 6 ++ src/main/g8/project/ProjectPlugin.scala | 4 +- 14 files changed, 143 insertions(+), 119 deletions(-) delete mode 100644 "src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/config/ConfigHelper.scala" rename "src/main/g8/play/src/main/resources/$name;format=\"norm,word\"$.yml" => "src/main/g8/play/src/main/resources/$name;format=\"norm\"$.yml" (100%) create mode 100644 "src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/routers.scala" delete mode 100644 "src/main/g8/play/src/test/resources/$name;format=\"norm,word\"$.yml" diff --git a/src/main/g8/build.sbt b/src/main/g8/build.sbt index 8513f0c..44a355a 100644 --- a/src/main/g8/build.sbt +++ b/src/main/g8/build.sbt @@ -13,10 +13,12 @@ lazy val $name;format="norm,word"$ = (project in file(".")) .disablePlugins(HeaderPlugin) lazy val play = (project in file("play")) - .enablePlugins(ProjectDockerBuildPlugin) + .enablePlugins(ProjectPlugin, ProjectDockerBuildPlugin) .enablePlay .enableIntegrationTests .settings( + name := "$name;format="norm"$", + buildInfoPackage := s"\${organization.value}.$name;format="norm,word"$.build", libraryDependencies ++= Seq( Cats.core, guice, @@ -38,9 +40,11 @@ lazy val testCommon = (project in file("testCommon")) ) lazy val perf = (project in file("perf")) - .enablePlugins(ProjectDockerBuildPlugin) + .enablePlugins(ProjectPlugin, ProjectDockerBuildPlugin) .enableIntegrationTests .settings( + name := "$name;format="norm"$-perf", + buildInfoPackage := s"\${organization.value}.$name;format="norm,word"$.perf.build", libraryDependencies ++= Seq( Cats.core, GatlingDependencies.app, diff --git a/src/main/g8/docker/docker-compose-perf.yml b/src/main/g8/docker/docker-compose-perf.yml index c0a8b0d..a122558 100644 --- a/src/main/g8/docker/docker-compose-perf.yml +++ b/src/main/g8/docker/docker-compose-perf.yml @@ -5,7 +5,7 @@ version: "2.1" services: perf: - image: $name;format="norm,word"$/perf + image: $organisation;format="norm"$/$name;format="norm"$-perf depends_on: play: condition: service_healthy diff --git a/src/main/g8/docker/docker-compose.yml b/src/main/g8/docker/docker-compose.yml index 7322822..97001ce 100644 --- a/src/main/g8/docker/docker-compose.yml +++ b/src/main/g8/docker/docker-compose.yml @@ -6,7 +6,7 @@ version: "2.1" # **All** services within this file should be defined with healthchecks services: play: - image: $name;format="norm,word"$/play + image: $organisation;format="norm"$/$name;format="norm"$ healthcheck: test: ["CMD", "wget", "-qO", "-", "http://localhost:9000/health"] interval: 5s @@ -16,6 +16,7 @@ services: APP_HOST: "0.0.0.0" APP_PORT: "9000" APPLICATION_SECRET: change_me + ALLOWED_HOST: \${ALLOWED_HOST} ports: - "9000:9000" networks: diff --git "a/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,word,Camel\"$IntegrationTest.scala" "b/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,word,Camel\"$IntegrationTest.scala" index 1652043..7a5360f 100644 --- "a/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,word,Camel\"$IntegrationTest.scala" +++ "b/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,word,Camel\"$IntegrationTest.scala" @@ -9,7 +9,7 @@ object Docker extends Tag("Docker") class $name;format="norm,Camel"$IntegrationTest @Inject() extends RestApiIntegrationTest { "When application is running" - { "Health-check" - { - "should always return status okay" taggedAs (Docker) in { + "should always return status okay" taggedAs Docker in { wsClient .url(s"\$appUrl/health") .addHttpHeaders(Http.HeaderNames.HOST -> "localhost") @@ -21,7 +21,7 @@ class $name;format="norm,Camel"$IntegrationTest @Inject() extends RestApiIntegra } } "Build info" - { - "should return a JSON object with current version" taggedAs (Docker) in { + "should return a JSON object with current version" taggedAs Docker in { wsClient .url(s"\$appUrl/version") .addHttpHeaders(Http.HeaderNames.HOST -> "localhost") @@ -33,46 +33,41 @@ class $name;format="norm,Camel"$IntegrationTest @Inject() extends RestApiIntegra } } "OpenAPI specs" - { - "should return the yaml specs" taggedAs (Docker) in { + "should return the yaml specs" taggedAs Docker in { wsClient - .url(s"\$appUrl/specs.yml") - .addHttpHeaders(Http.HeaderNames.HOST -> "localhost") + .url(s"\$appUrl/$name;format="norm"$.yml") .get() - .map(res => { - res.status shouldEqual 200 - }) + .map(res => res.status shouldEqual 200) } - "should redirect to the API docs" taggedAs (Docker) in { + "should redirect to the API docs" taggedAs Docker in { wsClient .url(s"\$appUrl/docs") - .addHttpHeaders(Http.HeaderNames.HOST -> "localhost") .withFollowRedirects(false) .get() - .map(res => { + .map { res => res.status shouldEqual 303 res .header("Location") - .get shouldEqual "/docs/index.html?url=/specs.yml" - }) + .get shouldEqual "/assets/lib/swagger-ui/index.html?url=%2F$name;format="norm"$.yml" + } } - "should show the API docs" taggedAs (Docker) in { + "should show the API docs" taggedAs Docker in { wsClient - .url(s"\$appUrl/docs?url=/specs.yml") - .addHttpHeaders(Http.HeaderNames.HOST -> "localhost") + .url(s"\$appUrl/assets/lib/swagger-ui/index.html?url=/$name;format="norm"$.yml") .get() - .map(res => { - res.status shouldEqual 200 - }) + .map(res => res.status shouldEqual 200) } - "default route should re-direct to API docs" taggedAs (Docker) in { + "default route should re-direct to API docs" taggedAs Docker in { wsClient .url(s"\$appUrl/") - .addHttpHeaders(Http.HeaderNames.HOST -> "localhost") .withFollowRedirects(false) .get() - .map(res => { + .map { res => res.status shouldEqual 303 - }) + res + .header("Location") + .get shouldEqual "/assets/lib/swagger-ui/index.html?url=%2F$name;format="norm"$.yml" + } } } } diff --git "a/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/config/ConfigHelper.scala" "b/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/config/ConfigHelper.scala" deleted file mode 100644 index 3b30a71..0000000 --- "a/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/config/ConfigHelper.scala" +++ /dev/null @@ -1,44 +0,0 @@ -package $organisation_domain$.$organisation;format="norm,word"$.$name;format="norm,word"$.core.config - -import scala.util.Try - -import com.typesafe.config.{Config, ConfigFactory} - -/** - * Utility and helper functions for managing validated configuration. - */ -object ConfigHelper { - - /** - * Helper function to load Typesafe configuration data with environment - * variables overridden. - * - * @param resourceName resource name that is to be loaded (e.g. - * "application.conf") - * @param required required environment variable map - * @param optional optional environment variable map - * @return failure or loaded Typesafe configuration instance with environment - * variable overrides applied - */ - def validateWithEnvironmentOverrides( - resourceName: String - )( - required: Map[String, String], - optional: Map[String, String] - ): Try[Config] = { - Try { - val requiredObject = - required.map { case (key, value) => s"env.required.\$key=\$value" } - val optionalObject = - optional.map { case (key, value) => s"env.optional.\$key=\$value" } - val overrideConfig = - ConfigFactory.parseString( - (requiredObject ++ optionalObject).mkString("\n") - ) - - overrideConfig - .withFallback(ConfigFactory.parseResourcesAnySyntax(resourceName)) - .resolve() - } - } -} diff --git "a/src/main/g8/play/src/main/resources/$name;format=\"norm,word\"$.yml" "b/src/main/g8/play/src/main/resources/$name;format=\"norm\"$.yml" similarity index 100% rename from "src/main/g8/play/src/main/resources/$name;format=\"norm,word\"$.yml" rename to "src/main/g8/play/src/main/resources/$name;format=\"norm\"$.yml" diff --git a/src/main/g8/play/src/main/resources/env.conf b/src/main/g8/play/src/main/resources/env.conf index 4c08ba0..f29ce03 100644 --- a/src/main/g8/play/src/main/resources/env.conf +++ b/src/main/g8/play/src/main/resources/env.conf @@ -36,5 +36,7 @@ env { TEST_ACTOR_MESSAGE_SERIALISATION = \${?TEST_ACTOR_MESSAGE_SERIALISATION} # Whether Java serialisation should be used or not USE_JAVA_SERIALISATION = \${?USE_JAVA_SERIALISATION} + # The host address which will be added to allowed hosts which will be used both in integration tests and production + ALLOWED_HOST = \${?ALLOWED_HOST} } } diff --git a/src/main/g8/play/src/main/resources/play.conf b/src/main/g8/play/src/main/resources/play.conf index 741c6a9..0deb81d 100644 --- a/src/main/g8/play/src/main/resources/play.conf +++ b/src/main/g8/play/src/main/resources/play.conf @@ -9,7 +9,22 @@ play { } http.secret.key = "\${?env.required.APPLICATION_SECRET}" modules.enabled += "$organisation_domain$.$organisation;format="norm,word"$.$name;format="norm,word"$.core.CoreModule" - filters.enabled += "$organisation_domain$.$organisation;format="norm,word"$.$name;format="norm,word"$.core.api.filters.ErrorHandlingFilter" + + filters { + headers { + contentSecurityPolicy = "default-src 'self' 'sha256-nhwGBMLdamxIibfUBcAZV1BeJ3oFoeNBYiIbKkxRyuY='; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' https://online.swagger.io data:" + # If true, allow an action to use .withHeaders to replace one or more of the security headers + allowActionSpecificHeaders = false + } + hosts { + allowed = [ + \${?env.optional.ALLOWED_HOST}, + ".", + "localhost" + ] + } + enabled += "$organisation_domain$.$organisation;format="norm,word"$.$name;format="norm,word"$.core.api.filters.ErrorHandlingFilter" + } } environment { diff --git "a/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouter.scala" "b/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouter.scala" index 6d0ee29..b86a7d9 100644 --- "a/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouter.scala" +++ "b/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouter.scala" @@ -2,6 +2,8 @@ package $organisation_domain$.$organisation;format="norm,word"$.$name;format="no import javax.inject.{Inject, Singleton} +import scala.concurrent.ExecutionContext + import play.api.routing.Router.Routes import play.api.routing.SimpleRouter import play.api.routing.sird._ @@ -14,27 +16,21 @@ class CoreRouter @Inject()( buildInfoController: BuildInfoController, assetsController: controllers.Assets, defaultController: controllers.Default +)( + implicit executor: ExecutionContext ) extends SimpleRouter { - override def routes: Routes = { - - // Base Routes - case GET(p"/health") => healthCheckController.health - case GET(p"/version") => buildInfoController.info - - // Swagger Documentation and Specification routes - case GET(p"/specs.yml") => - assetsController.at(path = "/", "$name;format="norm,word"$.yml") - case GET(p"/docs" ? q"url=\$url") => - assetsController.at(path = "/public/lib/swagger-ui", file = "index.html") - case GET(p"/docs/index.html" ? q"url=\$specs") => - assetsController.at(path = "/public/lib/swagger-ui", file = "index.html") - case GET(p"/docs") | GET(p"/docs/index.html") => - defaultController.redirect("/docs/index.html?url=/specs.yml") - case GET(p"/docs/\$file*") => - assetsController.at(path = "/public/lib/swagger-ui", file) - case GET(p"/") => - defaultController.redirect("/docs") - } + override def routes: Routes = + exposeSwaggerUIAtPath( + assetsController, "/", "$name;format="norm"$.yml", "/docs" + ) + .orElse( + swaggerUiRoutes(assetsController, "/", "$name;format="norm"$.yml")(executor) + ) + .orElse { + // Base Routes + case GET(p"/health") => healthCheckController.health + case GET(p"/version") => buildInfoController.info + } } diff --git "a/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/routers.scala" "b/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/routers.scala" new file mode 100644 index 0000000..ec6a4fd --- /dev/null +++ "b/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/routers.scala" @@ -0,0 +1,67 @@ +package $organisation_domain$.$organisation;format="norm,word"$.$name;format="norm,word"$.core.api + +import scala.concurrent.ExecutionContext + +import _root_.controllers.Assets +import play.api.mvc._ +import play.api.routing.Router.Routes +import play.api.routing.sird._ + +package object routers { + + /** + * A routing function allowing Play to serve the swagger UI. + * + * @param assets the assets controller + * @param swaggerPath the path of the directory at which the swagger file can be found + * @param swaggerFile the name of the swagger file + * @return a routing partial-function that can be composed with other routes + * and fed to a Play application + */ + def swaggerUiRoutes(assets: Assets, swaggerPath: String, swaggerFile: String)( + implicit ec: ExecutionContext + ): Routes = { + case GET(p"/assets/\$file*") => + assets.at(path = "/public/", file) + case GET(p"/docs") => + new ActionBuilderImpl(BodyParsers.utils.empty).apply { + Results.Redirect( + url = "/assets/lib/swagger-ui/index.html", + queryString = Map("url" -> Seq(s"/\$swaggerFile")) + ) + } + case GET(p"/") => + new ActionBuilderImpl(BodyParsers.utils.empty).apply { + Results.Redirect( + url = "/assets/lib/swagger-ui/index.html", + queryString = Map("url" -> Seq(s"/\$swaggerFile")) + ) + } + } + + /** + * Generic function to expose specific swagger specs at specific url path + * @param assets the assets controller + * @param swaggerPath the path of the directory at which the swagger file can be found + * @param swaggerFile the name of the swagger file + * @param urlToServeSwagger url to server swagger ui + * @return + */ + def exposeSwaggerUIAtPath( + assets: Assets, + swaggerPath: String, + swaggerFile: String, + urlToServeSwagger: String + )(implicit ec: ExecutionContext): Routes = { + case GET(p"/\$url") if url == swaggerFile => + assets.at(swaggerPath, swaggerFile) + case GET(p"/\$url*") if url == urlToServeSwagger.dropWhile(_ == '/') => + new ActionBuilderImpl(BodyParsers.utils.empty).apply { + Results.Redirect( + url = "/assets/lib/swagger-ui/index.html", + queryString = Map("url" -> Seq(s"/\$swaggerFile")) + ) + } + } + +} diff --git "a/src/main/g8/play/src/test/resources/$name;format=\"norm,word\"$.yml" "b/src/main/g8/play/src/test/resources/$name;format=\"norm,word\"$.yml" deleted file mode 100644 index e69de29..0000000 diff --git "a/src/main/g8/play/src/test/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouterSpec.scala" "b/src/main/g8/play/src/test/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouterSpec.scala" index 7c9744d..8effa92 100644 --- "a/src/main/g8/play/src/test/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouterSpec.scala" +++ "b/src/main/g8/play/src/test/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouterSpec.scala" @@ -28,40 +28,22 @@ class CoreRouterSpec extends PlaySpec { val Some(healthCheck) = route(application, healthRequest) status(healthCheck) mustBe Status.OK } - "serve API Docs" in { - val specsRequest = FakeRequest(GET, "/specs.yml") + "serve API specs" in { + val specsRequest = FakeRequest(GET, "/$name;format="norm"$.yml") val Some(specs) = route(application, specsRequest) - status(specs) mustBe Status.OK - - val docsRequest = FakeRequest(GET, "/docs?url=/specs.yml") - val Some(docs) = route(application, docsRequest) - status(docs) mustBe Status.OK - - val indexRequest = FakeRequest(GET, "/docs/index.html?url=/specs.yml") - val Some(index) = route(application, indexRequest) - status(index) mustBe Status.OK - - val swaggerUIRequest = FakeRequest(GET, "/docs/swagger-ui-bundle.js") - val Some(swaggerUI) = route(application, swaggerUIRequest) - status(swaggerUI) mustBe Status.OK + status(specs) mustBe OK } - "redirect request to API Docs when url parameter is missing" in { + "redirect request to API docs when url parameter is missing" in { val redirectDocsRequest = FakeRequest(GET, "/docs") val Some(redirectDocs) = route(application, redirectDocsRequest) - status(redirectDocs) mustBe Status.SEE_OTHER + status(redirectDocs) mustBe SEE_OTHER - val redirectIndexRequest = FakeRequest(GET, "/docs/index.html") - val Some(redirectIndex) = route(application, redirectIndexRequest) - status(redirectIndex) mustBe Status.SEE_OTHER } - "redirect request to API Docs when bass route is called" in { + "redirect request to API docs when base route is called" in { val redirectDocsRequest = FakeRequest(GET, "/") val Some(redirectDocs) = route(application, redirectDocsRequest) - status(redirectDocs) mustBe Status.SEE_OTHER + status(redirectDocs) mustBe SEE_OTHER - val redirectIndexRequest = FakeRequest(GET, "/docs/index.html") - val Some(redirectIndex) = route(application, redirectIndexRequest) - status(redirectIndex) mustBe Status.SEE_OTHER } "respond with 404 (not found) for unknown resources" in { val request = FakeRequest(GET, "/unknown/resource") diff --git a/src/main/g8/project/ProjectDockerBuildPlugin.scala b/src/main/g8/project/ProjectDockerBuildPlugin.scala index 7f9ae99..1e24ea9 100644 --- a/src/main/g8/project/ProjectDockerBuildPlugin.scala +++ b/src/main/g8/project/ProjectDockerBuildPlugin.scala @@ -1,3 +1,4 @@ +import com.typesafe.sbt.packager.Keys.dockerRepository import com.typesafe.sbt.packager.archetypes.scripts.AshScriptPlugin import net.cakesolutions._ import sbt._ @@ -23,4 +24,9 @@ object ProjectDockerBuildPlugin extends AutoPlugin { file("docker/docker-compose-testing.yml") ) ) + + /** @see [[sbt.AutoPlugin]] */ + override val projectSettings = Seq( + dockerRepository := Some("$organisation;format="norm"$") + ) } diff --git a/src/main/g8/project/ProjectPlugin.scala b/src/main/g8/project/ProjectPlugin.scala index e7b9c2e..54a25f8 100644 --- a/src/main/g8/project/ProjectPlugin.scala +++ b/src/main/g8/project/ProjectPlugin.scala @@ -20,9 +20,9 @@ object ProjectPlugin extends AutoPlugin { /** @see [[sbt.AutoPlugin]] */ override val buildSettings = Seq( - name := "$name;format="norm,word"$", + name := "$name;format="norm"$", organization := "$organisation_domain$.$organisation;format="norm,word"$", - buildInfoPackage := "$organisation_domain$.$organisation;format="norm,word"$.$name;format="norm,word"$.build", + buildInfoPackage := s"\${organization.value}.$name;format="norm,word"$.build", buildInfoKeys := Seq[BuildInfoKey]( name, version, From 3c6e85d13b5e14211072d65fa45abbb1a7cb5750 Mon Sep 17 00:00:00 2001 From: Damien Bailly Date: Thu, 1 Feb 2018 11:05:30 +0000 Subject: [PATCH 2/3] Add option to disable startup logs --- src/main/g8/build.sbt | 4 +++- src/main/g8/play/src/main/resources/application.conf | 1 + src/main/g8/play/src/main/resources/env.conf | 2 ++ src/main/g8/play/src/main/resources/logging.conf | 5 +++++ .../core/StartUpLogging.scala" | 11 +++++++---- .../core/StartUpLoggingSpec.scala" | 1 + 6 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 src/main/g8/play/src/main/resources/logging.conf diff --git a/src/main/g8/build.sbt b/src/main/g8/build.sbt index 44a355a..8bfdb6e 100644 --- a/src/main/g8/build.sbt +++ b/src/main/g8/build.sbt @@ -28,7 +28,9 @@ lazy val play = (project in file("play")) webjars, // Play WebServer client library ws % "it,test" - ) + ), + envVars in Test += "STARTUPLOGGING_ENABLED" -> "false", + envVars in IntegrationTest += "STARTUPLOGGING_ENABLED" -> "false" ) .dependsOn(testCommon % "it,test") diff --git a/src/main/g8/play/src/main/resources/application.conf b/src/main/g8/play/src/main/resources/application.conf index 861b9a7..3555a73 100644 --- a/src/main/g8/play/src/main/resources/application.conf +++ b/src/main/g8/play/src/main/resources/application.conf @@ -2,3 +2,4 @@ include "env" include "akka" include "play" include "services" +include "logging" diff --git a/src/main/g8/play/src/main/resources/env.conf b/src/main/g8/play/src/main/resources/env.conf index f29ce03..4f1a94d 100644 --- a/src/main/g8/play/src/main/resources/env.conf +++ b/src/main/g8/play/src/main/resources/env.conf @@ -38,5 +38,7 @@ env { USE_JAVA_SERIALISATION = \${?USE_JAVA_SERIALISATION} # The host address which will be added to allowed hosts which will be used both in integration tests and production ALLOWED_HOST = \${?ALLOWED_HOST} + # Log JVM props, configuration on application startup + STARTUPLOGGING_ENABLED = \${?STARTUPLOGGING_ENABLED} } } diff --git a/src/main/g8/play/src/main/resources/logging.conf b/src/main/g8/play/src/main/resources/logging.conf new file mode 100644 index 0000000..c3883a4 --- /dev/null +++ b/src/main/g8/play/src/main/resources/logging.conf @@ -0,0 +1,5 @@ +startuplogging { + # Log JVM props, configuration on application startup + enabled = true + enabled = \${?STARTUPLOGGING_ENABLED} +} diff --git "a/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/StartUpLogging.scala" "b/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/StartUpLogging.scala" index da6dee5..58ece7a 100644 --- "a/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/StartUpLogging.scala" +++ "b/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/StartUpLogging.scala" @@ -20,10 +20,13 @@ class StartUpLogging @Inject()( * Logs environment, JVM, properties and configuration data. */ def logAllTheThings(): Unit = { - logEnvironmentData() - logJVMData() - logPropertyData() - logConfigurationData(config) + val isEnabled = config.get[Boolean]("startuplogging.enabled") + if (isEnabled) { + logEnvironmentData() + logJVMData() + logPropertyData() + logConfigurationData(config) + } } private def logEnvironmentData(): Unit = { diff --git "a/src/main/g8/play/src/test/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/StartUpLoggingSpec.scala" "b/src/main/g8/play/src/test/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/StartUpLoggingSpec.scala" index d4f8c1e..790ba70 100644 --- "a/src/main/g8/play/src/test/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/StartUpLoggingSpec.scala" +++ "b/src/main/g8/play/src/test/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/StartUpLoggingSpec.scala" @@ -35,6 +35,7 @@ class StartUpLoggingSpec extends PlaySpec { private val application = GuiceApplicationBuilder() + .configure("startuplogging.enabled" -> true) .overrides( bind[LoggerLike] .qualifiedWith("startUpLogging") From 00b38bd80009af54ed3016cfefbf93529c1aa7c0 Mon Sep 17 00:00:00 2001 From: Damien Bailly Date: Thu, 1 Feb 2018 13:51:46 +0000 Subject: [PATCH 3/3] Linting --- ...rmat=\"norm,Camel\"$IntegrationTest.scala" | 2 +- .../core/api/routers/CoreRouter.scala" | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) rename "src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,word,Camel\"$IntegrationTest.scala" => "src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,Camel\"$IntegrationTest.scala" (99%) diff --git "a/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,word,Camel\"$IntegrationTest.scala" "b/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,Camel\"$IntegrationTest.scala" similarity index 99% rename from "src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,word,Camel\"$IntegrationTest.scala" rename to "src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,Camel\"$IntegrationTest.scala" index 7a5360f..9ef6fe4 100644 --- "a/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,word,Camel\"$IntegrationTest.scala" +++ "b/src/main/g8/play/src/it/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/$name;format=\"norm,Camel\"$IntegrationTest.scala" @@ -67,7 +67,7 @@ class $name;format="norm,Camel"$IntegrationTest @Inject() extends RestApiIntegra res .header("Location") .get shouldEqual "/assets/lib/swagger-ui/index.html?url=%2F$name;format="norm"$.yml" - } + } } } } diff --git "a/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouter.scala" "b/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouter.scala" index b86a7d9..1d5cce9 100644 --- "a/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouter.scala" +++ "b/src/main/g8/play/src/main/scala/$organisation_domain$/$organisation;format=\"norm,word\"$/$name;format=\"norm,word\"$/core/api/routers/CoreRouter.scala" @@ -22,15 +22,17 @@ class CoreRouter @Inject()( override def routes: Routes = exposeSwaggerUIAtPath( - assetsController, "/", "$name;format="norm"$.yml", "/docs" - ) - .orElse( - swaggerUiRoutes(assetsController, "/", "$name;format="norm"$.yml")(executor) - ) - .orElse { - // Base Routes - case GET(p"/health") => healthCheckController.health - case GET(p"/version") => buildInfoController.info - } + assetsController, + "/", + "$name;format="norm"$.yml", + "/docs" + ).orElse( + swaggerUiRoutes(assetsController, "/", "$name;format="norm"$.yml")(executor) + ) + .orElse { + // Base Routes + case GET(p"/health") => healthCheckController.health + case GET(p"/version") => buildInfoController.info + } }