Skip to content

Commit

Permalink
feat: added remove key reference endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperBatata committed Nov 21, 2024
1 parent 31c53e9 commit 8c6e0be
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class AWSKey(
config = config
)

val awsKmsUrl = "kms.${config.region}.amazonaws.com"
val awsKmsUrl = "kms.${config.auth.region}.amazonaws.com"

logger.debug { "Calling AWS KMS ($awsKmsUrl) - TrentService.ScheduleKeyDeletion" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,35 @@ class SSIKit2WalletService(
}
)


override suspend fun removeKey(alias: String): Boolean = runCatching {
val key = KeysService.get(walletId, alias)
key?.let {
val resolvedKey = KeyManager.resolveSerializedKey(it.document)
KeysService.delete(walletId, alias)
eventUseCase.log(
action = EventType.Key.Delete,
originator = "wallet",
tenant = tenant,
accountId = accountId,
walletId = walletId,
data = eventUseCase.keyEventData(
id = alias,
algorithm = resolvedKey.keyType.name,
kmsType = EventDataNotAvailable
)
)
} ?: throw IllegalArgumentException("Key not found for alias: $alias")

}.fold(
onSuccess = { true },
onFailure = {
logger.error(it) { "Failed to delete key: ${it.message}" }
throw IllegalArgumentException("Failed to delete key: ${it.message}")
}
)


override fun getHistory(limit: Int, offset: Long): List<WalletOperationHistory> =
WalletOperationHistories.selectAll()
.where { WalletOperationHistories.wallet eq walletId.toJavaUuid() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ abstract class WalletService(val tenant: String, val accountId: Uuid, val wallet
abstract suspend fun getKeyMeta(alias: String): JsonObject
abstract suspend fun importKey(jwkOrPem: String): String
abstract suspend fun deleteKey(alias: String): Boolean
abstract suspend fun removeKey(alias: String): Boolean

// History
abstract fun getHistory(limit: Int = 10, offset: Long = 0): List<WalletOperationHistory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ fun Application.keys() = walletRoute {
}

delete({
summary = "Delete a specific key"
summary = "Delete a specific key (hard delete)"
response {
HttpStatusCode.Accepted to { description = "Key deleted" }
HttpStatusCode.BadRequest to { description = "Key could not be deleted" }
Expand All @@ -232,6 +232,22 @@ fun Application.keys() = walletRoute {
val success = getWalletService().deleteKey(keyId)
context.respond(if (success) HttpStatusCode.Accepted else HttpStatusCode.BadRequest)
}

delete("remove", {
summary = "Remove a specific key (soft delete)"
response {
HttpStatusCode.Accepted to { description = "Key removed" }
HttpStatusCode.BadRequest to { description = "Failed to remove the key" }
}
}) {
val keyId = context.parameters["keyId"] ?: return@delete context.respond(
HttpStatusCode.BadRequest,
"Key ID is missing"
)

val success = getWalletService().removeKey(keyId)
context.respond(if (success) HttpStatusCode.Accepted else HttpStatusCode.BadRequest)
}
}
}
}

0 comments on commit 8c6e0be

Please sign in to comment.