Skip to content

Commit

Permalink
PIN-4572 Add PRODUCER_ALLOWED_ORIGINS to createVerifiedAttribute and …
Browse files Browse the repository at this point in the history
…createDeclaredAttribute
  • Loading branch information
nttdata-rtorsoli committed Feb 20, 2024
1 parent 470f1db commit 804d6f5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import it.pagopa.interop.attributeregistryprocess.common.readmodel.ReadModelRegi
import it.pagopa.interop.attributeregistryprocess.error.ResponseHandlers._
import it.pagopa.interop.attributeregistryprocess.error.AttributeRegistryProcessErrors.{
OrganizationIsNotACertifier,
OriginIsNotCompliant
OriginIsNotAllowed
}
import it.pagopa.interop.attributeregistryprocess.model._
import it.pagopa.interop.attributeregistryprocess.service._
Expand All @@ -21,6 +21,7 @@ import it.pagopa.interop.commons.cqrs.service.ReadModelService
import it.pagopa.interop.commons.jwt._
import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog}
import it.pagopa.interop.commons.utils.AkkaUtils._
import it.pagopa.interop.commons.utils.PRODUCER_ALLOWED_ORIGINS
import it.pagopa.interop.commons.utils.OpenapiUtils.parseArrayParameters
import it.pagopa.interop.commons.utils.TypeConversions._
import it.pagopa.interop.commons.utils.service.{OffsetDateTimeSupplier, UUIDSupplier}
Expand Down Expand Up @@ -141,7 +142,7 @@ final case class AttributeRegistryApiServiceImpl(
private def checkIPAOrganization(contexts: Seq[(String, String)]): Future[Unit] = {
for {
origin <- getExternalIdOriginFuture(contexts)
_ <- if (origin == IPA) Future.unit else Future.failed(OriginIsNotCompliant(IPA))
_ <- if (PRODUCER_ALLOWED_ORIGINS.contains(origin)) Future.unit else Future.failed(OriginIsNotAllowed(origin))
} yield ()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ object AttributeRegistryProcessErrors {
final case class OrganizationIsNotACertifier(tenantId: UUID)
extends ComponentError("0003", s"Tenant ${tenantId.toString} is not a certifier")

final case class OriginIsNotCompliant(origin: String)
extends ComponentError("0004", s"Requester has not origin: $origin")
final case class OriginIsNotAllowed(origin: String)
extends ComponentError("0004", s"Requester origin: $origin is not allowed")
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ object ResponseHandlers extends AkkaResponses {
success: T => Route
)(result: Try[T])(implicit contexts: Seq[(String, String)], logger: LoggerTakingImplicit[ContextFieldsToLog]): Route =
result match {
case Success(s) => success(s)
case Failure(ex: OriginIsNotCompliant) => forbidden(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
case Success(s) => success(s)
case Failure(ex: OriginIsNotAllowed) => forbidden(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}

def createVerifiedAttributeResponse[T](logMessage: String)(
success: T => Route
)(result: Try[T])(implicit contexts: Seq[(String, String)], logger: LoggerTakingImplicit[ContextFieldsToLog]): Route =
result match {
case Success(s) => success(s)
case Failure(ex: OriginIsNotCompliant) => forbidden(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
case Success(s) => success(s)
case Failure(ex: OriginIsNotAllowed) => forbidden(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}

def getAttributeByIdResponse[T](logMessage: String)(
Expand Down

0 comments on commit 804d6f5

Please sign in to comment.