Skip to content

Commit

Permalink
feat: add missing CRUD endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
patlo-iog committed May 7, 2024
1 parent f26c615 commit 8151a1a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.util.UUID

object CredentialIssuerEndpoints {

private val tagName = "OIDC Credential Issuer"
private val tagName = "OIDC4VC"
private val tagDescription =
s"""
|The __${tagName}__ is a service that issues credentials to users by implementing the [OIDC for Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) specification.
Expand All @@ -35,6 +35,10 @@ object CredentialIssuerEndpoints {
.description("An issuer identifier in the oidc4vc protocol")
.example(UUID.fromString("f47ac10b-58cc-4372-a567-0e02b2c3d479"))

private val credentialConfigurationIdSegment = path[String]("credentialConfigurationId")
.description("An identifier for the credential configuration")
.example("credentialConfigurationId")

private val baseEndpoint = endpoint
.tag(tagName)
.in(extractFromRequest[RequestContext](RequestContext.apply))
Expand Down Expand Up @@ -126,7 +130,7 @@ object CredentialIssuerEndpoints {
] = baseIssuerPrivateEndpoint.post
.in(jsonBody[CreateCredentialIssuerRequest])
.out(
statusCode(StatusCode.Created).description("Credential Issuer created successfully")
statusCode(StatusCode.Created).description("Credential issuer created successfully")
)
.out(jsonBody[CredentialIssuer])
.errorOut(EndpointOutputs.basicFailureAndNotFoundAndForbidden)
Expand All @@ -146,6 +150,23 @@ object CredentialIssuerEndpoints {
.name("getCredentialIssuers")
.summary("List all credential issuers")

val updateCredentialIssuerEndpoint: Endpoint[
(ApiKeyCredentials, JwtCredentials),
(RequestContext, UUID, PatchCredentialIssuerRequest),
ErrorResponse,
CredentialIssuer,
Any
] = baseIssuerPrivateEndpoint.patch
.in(issuerIdPathSegment)
.in(jsonBody[PatchCredentialIssuerRequest])
.out(
statusCode(StatusCode.Ok).description("Credential issuer updated successfully")
)
.out(jsonBody[CredentialIssuer])
.errorOut(EndpointOutputs.basicFailureAndNotFoundAndForbidden)
.name("updateCredentialIssuer")
.summary("Update the credential issuer")

val deleteCredentialIssuerEndpoint: Endpoint[
(ApiKeyCredentials, JwtCredentials),
(RequestContext, UUID),
Expand All @@ -157,7 +178,7 @@ object CredentialIssuerEndpoints {
.errorOut(EndpointOutputs.basicFailureAndNotFoundAndForbidden)
.out(statusCode(StatusCode.Ok).description("Credential issuer deleted successfully"))
.name("deleteCredentialIssuer")
.summary("Delete a credential issuer")
.summary("Delete the credential issuer")

val createCredentialConfigurationEndpoint: Endpoint[
(ApiKeyCredentials, JwtCredentials),
Expand All @@ -176,6 +197,22 @@ object CredentialIssuerEndpoints {
.name("createCredentialConfiguration")
.summary("Create a new credential configuration")

val deleteCredentialConfigurationEndpoint: Endpoint[
(ApiKeyCredentials, JwtCredentials),
(RequestContext, UUID, String),
ErrorResponse,
CredentialConfiguration,
Any
] = baseIssuerPrivateEndpoint.delete
.in(issuerIdPathSegment / "credential-configurations" / credentialConfigurationIdSegment)
.out(
statusCode(StatusCode.Created).description("Credential configuration created successfully")
)
.out(jsonBody[CredentialConfiguration])
.errorOut(EndpointOutputs.basicFailureAndNotFoundAndForbidden)
.name("createCredentialConfiguration")
.summary("Create a new credential configuration")

val issuerMetadataEndpoint: Endpoint[
Unit,
(RequestContext, UUID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ case class CredentialIssuerServerEndpoints(
}
}

val updateCredentialIssuerServerEndpoint: ZServerEndpoint[Any, Any] =
CredentialIssuerEndpoints.updateCredentialIssuerEndpoint
.zServerSecurityLogic(SecurityLogic.authorizeWalletAccessWith(_)(authenticator, authorizer))
.serverLogic { wac =>
{ case (rc, issuerId, request) =>
// credentialIssuerController
// .updateCredentialIssuer(rc, issuerId, request)
// .provideSomeLayer(ZLayer.succeed(wac))
// .logTrace(rc)
ZIO.dieMessage("Not implemented") // TODO: implement
}
}

val deleteCredentialIssuerServerEndpoint: ZServerEndpoint[Any, Any] =
CredentialIssuerEndpoints.deleteCredentialIssuerEndpoint
.zServerSecurityLogic(SecurityLogic.authorizeWalletAccessWith(_)(authenticator, authorizer))
Expand All @@ -105,6 +118,19 @@ case class CredentialIssuerServerEndpoints(
}
}

val deleteCredentialConfigurationServerEndpoint: ZServerEndpoint[Any, Any] =
CredentialIssuerEndpoints.deleteCredentialConfigurationEndpoint
.zServerSecurityLogic(SecurityLogic.authorizeWalletAccessWith(_)(authenticator, authorizer))
.serverLogic { wac =>
{ case (rc, issuerId, credentialId) =>
// credentialIssuerController
// .deleteCredentialConfiguration(rc, issuerId, credentialId)
// .provideSomeLayer(ZLayer.succeed(wac))
// .logTrace(rc)
ZIO.dieMessage("Not implemented") // TODO: implement
}
}

val issuerMetadataServerEndpoint: ZServerEndpoint[Any, Any] = CredentialIssuerEndpoints.issuerMetadataEndpoint
.zServerLogic {
{ case (rc, didRef) => credentialIssuerController.getIssuerMetadata(rc, didRef).logTrace(rc) }
Expand All @@ -116,8 +142,10 @@ case class CredentialIssuerServerEndpoints(
nonceServerEndpoint,
createCredentialIssuerServerEndpoint,
getCredentialIssuersServerEndpoint,
updateCredentialIssuerServerEndpoint,
deleteCredentialIssuerServerEndpoint,
createCredentialConfigurationServerEndpoint,
deleteCredentialConfigurationServerEndpoint,
issuerMetadataServerEndpoint
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object CredentialConfiguration {
credential_definition = CredentialDefinition(
`@context` = Some(Seq("https://www.w3.org/2018/credentials/v1")),
`type` = Seq("VerifiableCredential"),
credentialSubject = Some(Map.empty) // TODO: implement conversion from JsonSchhema
credentialSubject = None
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ object CreateCredentialIssuerRequest {

case class CredentialIssuer(id: UUID, authorizationServer: String)

case class PatchCredentialIssuerRequest(authorizationServer: Option[String] = None)

object PatchCredentialIssuerRequest {
given schema: Schema[PatchCredentialIssuerRequest] = Schema.derived
given encoder: JsonEncoder[PatchCredentialIssuerRequest] = DeriveJsonEncoder.gen
given decoder: JsonDecoder[PatchCredentialIssuerRequest] = DeriveJsonDecoder.gen
}

object CredentialIssuer {
given schema: Schema[CredentialIssuer] = Schema.derived
given encoder: JsonEncoder[CredentialIssuer] = DeriveJsonEncoder.gen
Expand Down

0 comments on commit 8151a1a

Please sign in to comment.