Skip to content

Commit

Permalink
PIN-5017 BKE - Authorization management - Added id parameter for clie…
Browse files Browse the repository at this point in the history
…nt creation
  • Loading branch information
nttdata-rtorsoli committed Jun 25, 2024
1 parent f5250fd commit 13806ff
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,9 @@ components:
description: Models the seed for a client to be persisted
type: object
properties:
clientId:
type: string
format: uuid
consumerId:
type: string
format: uuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import it.pagopa.interop.authorizationmanagement.model.persistence.ClientAdapter
import it.pagopa.interop.authorizationmanagement.model.persistence._
import it.pagopa.interop.authorizationmanagement.model.persistence.impl.Validation
import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog}
import it.pagopa.interop.commons.utils.service.UUIDSupplier
import it.pagopa.interop.commons.utils.TypeConversions._
import cats.syntax.all._

Expand All @@ -29,8 +28,7 @@ import scala.util.{Failure, Success, Try}
final case class ClientApiServiceImpl(
system: ActorSystem[_],
sharding: ClusterSharding,
entity: Entity[Command, ShardingEnvelope[Command]],
uuidSupplier: UUIDSupplier
entity: Entity[Command, ShardingEnvelope[Command]]
)(implicit ec: ExecutionContext)
extends ClientApiService
with Validation {
Expand All @@ -49,11 +47,9 @@ final case class ClientApiServiceImpl(
val operationLabel: String = s"Creating client for Consumer ${clientSeed.consumerId}"
logger.info(operationLabel)

val clientId = uuidSupplier.get()

val persistentClient = PersistentClient.toPersistentClient(clientId, clientSeed)
val persistentClient = PersistentClient.toPersistentClient(clientSeed)
val result: Future[Client] =
commander(clientId.toString)
commander(persistentClient.id.toString)
.askWithStatus(ref => AddClient(persistentClient, ref))
.map(_.toApi)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package object impl extends SprayJsonSupport with DefaultJsonProtocol {
implicit val purposeDetailsUpdateFormat: RootJsonFormat[ClientPurposeDetailsUpdate] =
jsonFormat2(ClientPurposeDetailsUpdate)

implicit val clientSeedFormat: RootJsonFormat[ClientSeed] = jsonFormat6(ClientSeed)
implicit val clientSeedFormat: RootJsonFormat[ClientSeed] = jsonFormat7(ClientSeed)
implicit val clientFormat: RootJsonFormat[Client] = jsonFormat8(Client)
implicit val relationshipSeedFormat: RootJsonFormat[UserSeed] = jsonFormat1(UserSeed)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import it.pagopa.interop.authorizationmanagement.model._
import it.pagopa.interop.authorizationmanagement.model.client._
import it.pagopa.interop.commons.utils.service.UUIDSupplier

import java.util.UUID

object ClientAdapters {

implicit class PersistentClientWrapper(private val p: PersistentClient) extends AnyVal {
Expand All @@ -23,9 +21,9 @@ object ClientAdapters {
}

implicit class PersistentClientObjectWrapper(private val p: PersistentClient.type) extends AnyVal {
def toPersistentClient(clientId: UUID, seed: ClientSeed): PersistentClient =
def toPersistentClient(seed: ClientSeed): PersistentClient =
client.PersistentClient(
id = clientId,
id = seed.clientId.getOrElse(UUIDSupplier.get()),
consumerId = seed.consumerId,
name = seed.name,
purposes = Seq.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ trait Dependencies {
ec: ExecutionContext,
actorSystem: ActorSystem[_]
) = new ClientApi(
ClientApiServiceImpl(actorSystem, sharding, keyPersistentEntity, uuidSupplier),
ClientApiServiceImpl(actorSystem, sharding, keyPersistentEntity),
ClientApiMarshallerImpl,
jwtReader.OAuth2JWTValidatorAsContexts
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@ trait SpecHelper
wrappingDirective
)

val clientApi = new ClientApi(
ClientApiServiceImpl(system, sharding, persistentEntity, mockUUIDSupplier),
clientApiMarshaller,
wrappingDirective
)
val clientApi =
new ClientApi(ClientApiServiceImpl(system, sharding, persistentEntity), clientApiMarshaller, wrappingDirective)

val purposeApi = new PurposeApi(
PurposeApiServiceImpl(system, sharding, persistentEntity, mockUUIDSupplier),
Expand Down Expand Up @@ -124,14 +121,13 @@ trait SpecHelper
}

def createClient(id: UUID, consumerUUID: UUID, userIds: Seq[UUID] = Seq.empty): Client = {
(() => mockUUIDSupplier.get()).expects().returning(id).once()

val name = s"New Client ${id.toString}"
val description = s"New Client ${id.toString} description"
val users = if (userIds.isEmpty) "[]" else userIds.map(_.toString).mkString("[\"", "\",\"", "\"]")

val data =
s"""{
| "clientId": "${id.toString}",
| "consumerId": "${consumerUUID.toString}",
| "name": "$name",
| "kind": "CONSUMER",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ClientManagementSpec

"be created successfully" in {
val newClientUuid = UUID.randomUUID()
(() => mockUUIDSupplier.get()).expects().returning(newClientUuid).once()

val consumerUuid = UUID.randomUUID()
val name = "New Client 1"
Expand All @@ -57,6 +56,7 @@ class ClientManagementSpec

val data =
s"""{
| "clientId": "${newClientUuid.toString}",
| "consumerId": "${consumerUuid.toString}",
| "name": "$name",
| "kind": "CONSUMER",
Expand Down

0 comments on commit 13806ff

Please sign in to comment.