-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Wallet Management Error Handling (#1248)
Signed-off-by: Bassam Riman <[email protected]> Signed-off-by: Shota Jolbordi <[email protected]>
- Loading branch information
1 parent
bbc9629
commit a80ffab
Showing
23 changed files
with
218 additions
and
176 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
38 changes: 0 additions & 38 deletions
38
.../src/main/scala/org/hyperledger/identus/iam/authorization/core/PermissionManagement.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 |
---|---|---|
@@ -1,39 +1 @@ | ||
package org.hyperledger.identus.iam.authorization.core | ||
|
||
import org.hyperledger.identus.agent.walletapi.model.BaseEntity | ||
import org.hyperledger.identus.shared.models.{WalletAdministrationContext, WalletId} | ||
import zio.* | ||
|
||
import java.util.UUID | ||
|
||
object PermissionManagement { | ||
trait Service[E <: BaseEntity] { | ||
def grantWalletToUser(walletId: WalletId, entity: E): ZIO[WalletAdministrationContext, Error, Unit] | ||
def revokeWalletFromUser(walletId: WalletId, entity: E): ZIO[WalletAdministrationContext, Error, Unit] | ||
def listWalletPermissions(entity: E): ZIO[WalletAdministrationContext, Error, Seq[WalletId]] | ||
} | ||
|
||
sealed trait Error(val message: String) | ||
|
||
object Error { | ||
case class UserNotFoundById(userId: UUID, cause: Option[Throwable] = None) | ||
extends Error(s"User $userId is not found" + cause.map(t => s" Cause: ${t.getMessage}")) | ||
case class WalletNotFoundByUserId(userId: UUID) extends Error(s"Wallet for user $userId is not found") | ||
|
||
case class WalletNotFoundById(walletId: WalletId) extends Error(s"Wallet not found by ${walletId.toUUID}") | ||
|
||
case class WalletResourceNotFoundById(walletId: WalletId) | ||
extends Error(s"Wallet resource not found by ${walletId.toUUID}") | ||
|
||
case class PermissionNotFoundById(userId: UUID, walletId: WalletId, walletResourceId: String) | ||
extends Error( | ||
s"Permission not found by userId: $userId, walletId: ${walletId.toUUID}, walletResourceId: $walletResourceId" | ||
) | ||
|
||
case class PermissionNotAvailable(userId: UUID, cause: String) extends Error(cause) | ||
|
||
case class UnexpectedError(cause: Throwable) extends Error(cause.getMessage) | ||
|
||
case class ServiceError(cause: String) extends Error(cause) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...in/scala/org/hyperledger/identus/iam/authorization/core/PermissionManagementService.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,19 @@ | ||
package org.hyperledger.identus.iam.authorization.core | ||
|
||
import org.hyperledger.identus.agent.walletapi.model.BaseEntity | ||
import org.hyperledger.identus.shared.models.{WalletAdministrationContext, WalletId} | ||
import zio.* | ||
|
||
trait PermissionManagementService[E <: BaseEntity] { | ||
def grantWalletToUser( | ||
walletId: WalletId, | ||
entity: E | ||
): ZIO[WalletAdministrationContext, PermissionManagementServiceError, Unit] | ||
def revokeWalletFromUser( | ||
walletId: WalletId, | ||
entity: E | ||
): ZIO[WalletAdministrationContext, PermissionManagementServiceError, Unit] | ||
def listWalletPermissions( | ||
entity: E | ||
): ZIO[WalletAdministrationContext, PermissionManagementServiceError, Seq[WalletId]] | ||
} |
50 changes: 50 additions & 0 deletions
50
...ala/org/hyperledger/identus/iam/authorization/core/PermissionManagementServiceError.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,50 @@ | ||
package org.hyperledger.identus.iam.authorization.core | ||
|
||
import org.hyperledger.identus.shared.models.{Failure, StatusCode, WalletId} | ||
|
||
import java.util.UUID | ||
|
||
sealed trait PermissionManagementServiceError( | ||
val statusCode: StatusCode, | ||
val userFacingMessage: String | ||
) extends Failure { | ||
override val namespace: String = "PermissionManagementServiceError" | ||
} | ||
|
||
object PermissionManagementServiceError { | ||
|
||
case class UserNotFoundById(userId: UUID, cause: Option[Throwable] = None) | ||
extends PermissionManagementServiceError( | ||
StatusCode.BadRequest, | ||
s"User $userId is not found" + cause.map(t => s" Cause: ${t.getMessage}") | ||
) | ||
|
||
case class WalletNotFoundByUserId(userId: UUID) | ||
extends PermissionManagementServiceError( | ||
StatusCode.BadRequest, | ||
s"Wallet for user $userId is not found" | ||
) | ||
|
||
case class WalletNotFoundById(walletId: WalletId) | ||
extends PermissionManagementServiceError( | ||
StatusCode.BadRequest, | ||
s"Wallet not found by ${walletId.toUUID}" | ||
) | ||
|
||
case class WalletResourceNotFoundById(walletId: WalletId) | ||
extends PermissionManagementServiceError( | ||
StatusCode.BadRequest, | ||
s"Wallet resource not found by ${walletId.toUUID}" | ||
) | ||
|
||
case class PermissionNotFoundById(userId: UUID, walletId: WalletId, walletResourceId: String) | ||
extends PermissionManagementServiceError( | ||
StatusCode.BadRequest, | ||
s"Permission not found by userId: $userId, walletId: ${walletId.toUUID}, walletResourceId: $walletResourceId" | ||
) | ||
|
||
case class PermissionNotAvailable(userId: UUID, cause: String) | ||
extends PermissionManagementServiceError(StatusCode.BadRequest, cause) | ||
|
||
case class ServiceError(cause: String) extends PermissionManagementServiceError(StatusCode.InternalServerError, cause) | ||
} |
Oops, something went wrong.