-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from hmrc/BDOG-238
Bdog 238
- Loading branch information
Showing
24 changed files
with
1,240 additions
and
89 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
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
91 changes: 91 additions & 0 deletions
91
app/uk/gov/hmrc/cataloguefrontend/shuttering/ShutterConnector.scala
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,91 @@ | ||
/* | ||
* Copyright 2019 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.cataloguefrontend.shuttering | ||
|
||
import javax.inject.{Inject, Singleton} | ||
import play.api.Logger | ||
import play.api.libs.json.Reads | ||
import uk.gov.hmrc.http.HeaderCarrier | ||
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig | ||
import uk.gov.hmrc.play.bootstrap.http.HttpClient | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
@Singleton | ||
class ShutterConnector @Inject()( | ||
http : HttpClient | ||
, serviceConfig: ServicesConfig | ||
)(implicit val ec: ExecutionContext){ | ||
|
||
private val urlStates: String = s"${serviceConfig.baseUrl("shutter-api")}/shutter-api/states" | ||
private val urlEvents: String = s"${serviceConfig.baseUrl("shutter-api")}/shutter-api/events" | ||
|
||
private implicit val ssr = ShutterState.reads | ||
private implicit val ser = ShutterEvent.reads | ||
|
||
/** | ||
* GET | ||
* /shutter-api/states | ||
* Retrieves the current shutter states for all applications in all environments | ||
*/ | ||
def shutterStates()(implicit hc: HeaderCarrier): Future[Seq[ShutterState]] = | ||
http.GET[Seq[ShutterState]](url = urlStates) | ||
|
||
/** | ||
* GET | ||
* /shutter-api/events | ||
* Retrieves the current shutter events for all applications for given environment | ||
*/ | ||
def latestShutterEvents(env: Environment)(implicit hc: HeaderCarrier): Future[Seq[ShutterStateChangeEvent]] = | ||
http.GET[Seq[ShutterEvent]](url = s"$urlEvents?type=${EventType.ShutterStateChange.asString}&namedFilter=latestByServiceName&data.environment=${env.asString}") | ||
.map(_.flatMap(_.toShutterStateChangeEvent)) | ||
|
||
/** | ||
* GET | ||
* /shutter-api/states/{appName} | ||
* Retrieves the current shutter states for the given application in all environments | ||
*/ | ||
def shutterStateByApp(appName: String)(implicit hc: HeaderCarrier): Future[Option[ShutterState]] = | ||
http.GET[Option[ShutterState]](s"$urlStates/$appName") | ||
|
||
|
||
/** | ||
* GET | ||
* /shutter-api/states/{appName}/{environment} | ||
* Retrieves the current shutter state for the given application in the given environment | ||
*/ | ||
def shutterStatusByAppAndEnv(appName: String, env: Environment)(implicit hc: HeaderCarrier): Future[Option[ShutterStatus]] = { | ||
implicit val ssf = ShutterStatus.format | ||
http.GET[Option[ShutterStatus]](s"$urlStates/$appName/${env.asString}") | ||
} | ||
|
||
|
||
/** | ||
* PUT | ||
* /shutter-api/states/{appName}/{environment} | ||
* Shutters/un-shutters the application in the given environment | ||
*/ | ||
def updateShutterStatus(appName: String, env: Environment, status: ShutterStatus)(implicit hc: HeaderCarrier): Future[Unit] = { | ||
implicit val isf = ShutterStatus.format | ||
|
||
implicit val ur = new uk.gov.hmrc.http.HttpReads[Unit] { | ||
def read(method: String, url: String, response: uk.gov.hmrc.http.HttpResponse): Unit = () | ||
} | ||
|
||
http.PUT[ShutterStatus, Unit](s"$urlStates/$appName/${env.asString}", status) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/uk/gov/hmrc/cataloguefrontend/shuttering/ShutterController.scala
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,51 @@ | ||
/* | ||
* Copyright 2019 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.cataloguefrontend.shuttering | ||
|
||
import javax.inject.{Inject, Singleton} | ||
import play.api.Logger | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
import uk.gov.hmrc.cataloguefrontend.actions.VerifySignInStatus | ||
import uk.gov.hmrc.play.bootstrap.controller.FrontendController | ||
import views.html.shuttering._ | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
import scala.util.control.NonFatal | ||
|
||
@Singleton | ||
class ShutterController @Inject()( | ||
mcc : MessagesControllerComponents | ||
, verifySignInStatus: VerifySignInStatus | ||
, shutterStatePage : ShutterStatePage | ||
, shutterService : ShutterService | ||
)(implicit val ec: ExecutionContext) | ||
extends FrontendController(mcc) { | ||
|
||
def allStates(envParam: String): Action[AnyContent] = | ||
verifySignInStatus.async { implicit request => | ||
val env = Environment.parse(envParam).getOrElse(Environment.Production) | ||
for { | ||
currentState <- shutterService.findCurrentState(env) | ||
.recover { | ||
case NonFatal(ex) => | ||
Logger.error(s"Could not retrieve currentState: ${ex.getMessage}", ex) | ||
Seq.empty | ||
} | ||
page = shutterStatePage(currentState, env, request.isSignedIn) | ||
} yield Ok(page) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/uk/gov/hmrc/cataloguefrontend/shuttering/ShutterService.scala
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,43 @@ | ||
/* | ||
* Copyright 2019 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.cataloguefrontend.shuttering | ||
|
||
import java.time.LocalDateTime | ||
|
||
import javax.inject.{Inject, Singleton} | ||
import uk.gov.hmrc.http.HeaderCarrier | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
@Singleton | ||
class ShutterService @Inject()(shutterConnector: ShutterConnector)(implicit val ec: ExecutionContext) { | ||
|
||
def getShutterStates(implicit hc: HeaderCarrier): Future[Seq[ShutterState]] = | ||
shutterConnector.shutterStates | ||
|
||
def updateShutterStatus(serviceName: String, env: Environment, status: ShutterStatus)(implicit hc: HeaderCarrier): Future[Unit] = | ||
shutterConnector.updateShutterStatus(serviceName, env, status) | ||
|
||
def findCurrentState(env: Environment)(implicit hc: HeaderCarrier): Future[Seq[ShutterStateChangeEvent]] = | ||
for { | ||
events <- shutterConnector.latestShutterEvents(env) | ||
sorted = events.sortWith { | ||
case (l, r) => l.status == ShutterStatus.Shuttered || | ||
l.serviceName < r.serviceName | ||
} | ||
} yield sorted | ||
} |
Oops, something went wrong.