Skip to content

Commit

Permalink
AOSS-1418 BL Setting the structure for wiring dependent services in t…
Browse files Browse the repository at this point in the history
…he microservice
  • Loading branch information
Ben Letton committed Jul 7, 2016
1 parent 1bfa888 commit dc55c61
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
/*
* Copyright 2016 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.agentclientauthorisation.controllers

import uk.gov.hmrc.play.microservice.controller.BaseController
import uk.gov.hmrc.play.http.logging.MdcLoggingExecutionContext._
import play.api.mvc._
import uk.gov.hmrc.play.microservice.controller.BaseController

import scala.concurrent.Future

object MicroserviceHelloWorld extends MicroserviceHelloWorld

trait MicroserviceHelloWorld extends BaseController {
class MicroserviceHelloWorld extends BaseController {

def hello() = Action.async { implicit request =>
Future.successful(Ok("Hello world"))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2016 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.agentclientauthorisation

import com.typesafe.config.Config
Expand Down Expand Up @@ -34,7 +50,7 @@ object MicroserviceAuthFilter extends AuthorisationFilter {
override def controllerNeedsAuth(controllerName: String): Boolean = ControllerConfiguration.paramsForController(controllerName).needsAuth
}

object MicroserviceGlobal extends DefaultMicroserviceGlobal with RunMode {
trait MicroserviceGlobal extends DefaultMicroserviceGlobal with RunMode with ServiceRegistry with ControllerRegistry {
override val auditConnector = MicroserviceAuditConnector

override def microserviceMetricsConfig(implicit app: Application): Option[Configuration] = app.configuration.getConfig(s"microservice.metrics")
Expand All @@ -44,4 +60,10 @@ object MicroserviceGlobal extends DefaultMicroserviceGlobal with RunMode {
override val microserviceAuditFilter = MicroserviceAuditFilter

override val authFilter = Some(MicroserviceAuthFilter)

override def getControllerInstance[A](controllerClass: Class[A]): A = {
getController(controllerClass)
}
}

object MicroserviceGlobal extends MicroserviceGlobal
34 changes: 34 additions & 0 deletions app/uk/gov/hmrc/agentclientauthorisation/microserviceWiring.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
/*
* Copyright 2016 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.agentclientauthorisation

import play.api.mvc.Controller
import uk.gov.hmrc.agentclientauthorisation.controllers.MicroserviceHelloWorld
import uk.gov.hmrc.play.audit.http.config.LoadAuditingConfig
import uk.gov.hmrc.play.audit.http.connector.AuditConnector
import uk.gov.hmrc.play.auth.microservice.connectors.AuthConnector
Expand All @@ -18,3 +36,19 @@ object MicroserviceAuditConnector extends AuditConnector with RunMode {
object MicroserviceAuthConnector extends AuthConnector with ServicesConfig {
override val authBaseUrl = baseUrl("auth")
}

trait ServiceRegistry extends ServicesConfig {

// Instantiate services here

}

trait ControllerRegistry {
registry: ServiceRegistry =>

private lazy val controllers = Map[Class[_], Controller](
classOf[MicroserviceHelloWorld] -> new MicroserviceHelloWorld()
)

def getController[A](controllerClass: Class[A]) : A = controllers(controllerClass).asInstanceOf[A]
}
15 changes: 13 additions & 2 deletions conf/application.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Copyright 2016 HM Revenue & Customs
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This is the main configuration file for the application.
# ~~~~~
Expand Down Expand Up @@ -138,5 +151,3 @@ microservice {

}
}


6 changes: 5 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "1.0.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-git-versioning" % "467a8b417f9d90ab863f3172f1bebe1d7c49706b")
addSbtPlugin("uk.gov.hmrc" % "sbt-git-versioning" % "0.8.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "0.11.0")

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.10")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5")

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")

0 comments on commit dc55c61

Please sign in to comment.