-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Wallet Management Error Handling #1248
Merged
+218
−176
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this one represents the catch-all "unexpected error" case, right? From the caller's perspective, there is no way to recover from this type of failure, so I would remove it and throw a defect in the service implementation instead.