-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Api-8024: added handling for UnsubscribeFromRetiredApi Command (#531)
* API-8020 - Align events use of ApplicationName * API-8024 - WIP * API-8024: WIP * API-8024: WIP2 * API-8024: fixed broken tests and bumped library * API-8024: fixed broken tests and bumped library * API-8024: added handling for UnsubscribeFromRetiredApi command * API-8024: added logging * API-8024: bump auto build plugin version --------- Co-authored-by: Andy Spaven <[email protected]>
- Loading branch information
1 parent
6915e83
commit 6f6d2a7
Showing
35 changed files
with
578 additions
and
128 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
67 changes: 67 additions & 0 deletions
67
app/uk/gov/hmrc/thirdpartyapplication/controllers/PublisherController.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,67 @@ | ||
/* | ||
* Copyright 2023 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.thirdpartyapplication.controllers | ||
|
||
import java.time.{Clock, Instant} | ||
import javax.inject.{Inject, Singleton} | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
import play.api.mvc._ | ||
import uk.gov.hmrc.http.HeaderCarrier | ||
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController | ||
|
||
import uk.gov.hmrc.apiplatform.modules.common.domain.models._ | ||
import uk.gov.hmrc.apiplatform.modules.common.services.ClockNow | ||
import uk.gov.hmrc.apiplatform.modules.commands.applications.domain.models.ApplicationCommands.UnsubscribeFromApi | ||
import uk.gov.hmrc.thirdpartyapplication.repository.{ApplicationRepository, SubscriptionRepository} | ||
import uk.gov.hmrc.thirdpartyapplication.services.ApplicationCommandDispatcher | ||
|
||
@Singleton | ||
class PublisherController @Inject() ( | ||
subscriptionRepository: SubscriptionRepository, | ||
applicationRepository: ApplicationRepository, | ||
applicationCommandDispatcher: ApplicationCommandDispatcher, | ||
cc: ControllerComponents, | ||
val clock: Clock | ||
)(implicit val ec: ExecutionContext | ||
) extends BackendController(cc) with JsonUtils with ClockNow { | ||
|
||
// What do we want to do if unsubscribing goes wrong?? | ||
|
||
def deleteSubscribers(context: ApiContext, version: ApiVersionNbr): Action[AnyContent] = Action.async { implicit request => | ||
// can check user-agent header to check originator and check secret key, Unauth response if failed. | ||
val ts: Instant = instant() | ||
val apiIdentifier = ApiIdentifier(context, version) | ||
val command = UnsubscribeFromApi(Actors.Process("Publisher"), apiIdentifier, ts) | ||
|
||
def deleteSubscriptionFor(applicationId: ApplicationId)(implicit hc: HeaderCarrier): Future[Unit] = { | ||
def logAndReturnUnit(msg: String) = { | ||
logger.info(s"deleteSubscribers $msg for app $applicationId for Api context: $context Api Version: $version") | ||
() | ||
} | ||
|
||
applicationCommandDispatcher.dispatch(applicationId, command, Set.empty) | ||
.fold(_ => logAndReturnUnit("command failed"), _ => logAndReturnUnit("command succeeded")) | ||
} | ||
|
||
(for { | ||
subscribers <- subscriptionRepository.getSubscribers(ApiIdentifier(context, version)) | ||
xs <- Future.sequence(subscribers.toList.map(id => deleteSubscriptionFor(id))) | ||
} yield xs) | ||
.map(_ => Ok) | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
app/uk/gov/hmrc/thirdpartyapplication/services/ApplicationCommandService.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,54 @@ | ||
/* | ||
* Copyright 2024 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.thirdpartyapplication.services | ||
|
||
import javax.inject.{Inject, Singleton} | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
import cats.data.{EitherT, NonEmptyList} | ||
|
||
import uk.gov.hmrc.http.HeaderCarrier | ||
|
||
import uk.gov.hmrc.apiplatform.modules.common.domain.models.{ApplicationId, LaxEmailAddress} | ||
import uk.gov.hmrc.apiplatform.modules.common.services.{ApplicationLogger, EitherTHelper} | ||
import uk.gov.hmrc.apiplatform.modules.commands.applications.domain.models.{ApplicationCommand, CommandFailures} | ||
import uk.gov.hmrc.thirdpartyapplication.services.commands.CommandHandler | ||
|
||
@Singleton | ||
class ApplicationCommandService @Inject() ( | ||
val applicationCommandDispatcher: ApplicationCommandDispatcher, | ||
val applicationCommandAuthenticator: ApplicationCommandAuthenticator | ||
)(implicit ec: ExecutionContext | ||
) extends ApplicationLogger { | ||
|
||
import CommandHandler._ | ||
|
||
val E = EitherTHelper.make[Failures] | ||
|
||
def authenticateAndDispatch(applicationId: ApplicationId, command: ApplicationCommand, collaboratorsToNotify: Set[LaxEmailAddress])(implicit hc: HeaderCarrier) | ||
: EitherT[Future, Failures, Success] = { | ||
(for { | ||
isAuthorised <- E.liftF(applicationCommandAuthenticator.authenticateCommand(command)) | ||
_ <- E.cond( | ||
isAuthorised, | ||
(), | ||
NonEmptyList.one(CommandFailures.InsufficientPrivileges("Not authenticated")) | ||
) | ||
dispatchResult <- applicationCommandDispatcher.dispatch(applicationId, command, collaboratorsToNotify) | ||
} yield dispatchResult) | ||
} | ||
} |
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
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
Oops, something went wrong.