Skip to content

Commit

Permalink
fix: update issuer auth server model parity (#1154)
Browse files Browse the repository at this point in the history
Signed-off-by: Pat Losoponkul <[email protected]>
  • Loading branch information
patlo-iog authored Jun 7, 2024
1 parent 1c6fd95 commit 096b746
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,17 @@ case class CredentialIssuerControllerImpl(
): ZIO[WalletAccessContext, ErrorResponse, CredentialIssuer] =
for {
maybeAuthServerUrl <- ZIO
.succeed(request.authorizationServer)
.succeed(request.authorizationServer.flatMap(_.url))
.flatMap {
case Some(url) => parseURL(url).asSome
case None => ZIO.none
}
issuer <- issuerMetadataService.updateCredentialIssuer(issuerId, maybeAuthServerUrl)
issuer <- issuerMetadataService.updateCredentialIssuer(
issuerId,
maybeAuthServerUrl,
request.authorizationServer.flatMap(_.clientId),
request.authorizationServer.flatMap(_.clientSecret)
)
} yield issuer: CredentialIssuer

override def deleteCredentialIssuer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ object AuthorizationServer {
given decoder: JsonDecoder[AuthorizationServer] = DeriveJsonDecoder.gen
}

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

case class PatchCredentialIssuerRequest(authorizationServer: Option[String] = None)
case class PatchAuthorizationServer(url: Option[String], clientId: Option[String], clientSecret: Option[String])

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

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

object PatchCredentialIssuerRequest {
given schema: Schema[PatchCredentialIssuerRequest] = Schema.derived
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ trait OID4VCIIssuerMetadataRepository {
def findIssuerById(issuerId: UUID): UIO[Option[CredentialIssuer]]
def createIssuer(issuer: CredentialIssuer): URIO[WalletAccessContext, Unit]
def findWalletIssuers: URIO[WalletAccessContext, Seq[CredentialIssuer]]
def updateIssuer(issuerId: UUID, authorizationServer: Option[URL] = None): URIO[WalletAccessContext, Unit]
def updateIssuer(
issuerId: UUID,
authorizationServer: Option[URL] = None,
authorizationServerClientId: Option[String] = None,
authorizationServerClientSecret: Option[String] = None
): URIO[WalletAccessContext, Unit]
def deleteIssuer(issuerId: UUID): URIO[WalletAccessContext, Unit]
def createCredentialConfiguration(issuerId: UUID, config: CredentialConfiguration): URIO[WalletAccessContext, Unit]
def findCredentialConfigurationsByIssuer(issuerId: UUID): UIO[Seq[CredentialConfiguration]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ trait OID4VCIIssuerMetadataService {
def getCredentialIssuers: URIO[WalletAccessContext, Seq[CredentialIssuer]]
def updateCredentialIssuer(
issuerId: UUID,
authorizationServer: Option[URL] = None
authorizationServer: Option[URL] = None,
authorizationServerClientId: Option[String] = None,
authorizationServerClientSecret: Option[String] = None
): ZIO[WalletAccessContext, IssuerIdNotFound, CredentialIssuer]
def deleteCredentialIssuer(issuerId: UUID): ZIO[WalletAccessContext, IssuerIdNotFound, Unit]
def createCredentialConfiguration(
Expand Down Expand Up @@ -99,11 +101,18 @@ class OID4VCIIssuerMetadataServiceImpl(repository: OID4VCIIssuerMetadataReposito

override def updateCredentialIssuer(
issuerId: UUID,
authorizationServer: Option[URL]
authorizationServer: Option[URL],
authorizationServerClientId: Option[String],
authorizationServerClientSecret: Option[String]
): ZIO[WalletAccessContext, IssuerIdNotFound, CredentialIssuer] =
for {
_ <- repository
.updateIssuer(issuerId, authorizationServer = authorizationServer)
.updateIssuer(
issuerId = issuerId,
authorizationServer = authorizationServer,
authorizationServerClientId = authorizationServerClientId,
authorizationServerClientSecret = authorizationServerClientSecret
)
.catchSomeDefect { case _: UnexpectedAffectedRow =>
ZIO.fail(IssuerIdNotFound(issuerId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,17 @@ object OID4VCIIssuerMetadataRepositorySpecSuite {
authServer2 = URI.create("http://example-2.com").toURL()
issuer = makeCredentialIssuer(authorizationServer = authServer1)
_ <- repo.createIssuer(issuer)
_ <- repo.updateIssuer(issuer.id, authorizationServer = Some(authServer2))
_ <- repo.updateIssuer(
issuerId = issuer.id,
authorizationServer = Some(authServer2),
authorizationServerClientId = Some("client-2"),
authorizationServerClientSecret = Some("secret-2")
)
updatedIssuer <- repo.findIssuerById(issuer.id).some
} yield assert(updatedIssuer.id)(equalTo(issuer.id)) &&
assert(updatedIssuer.authorizationServer)(equalTo(authServer2)) &&
assert(updatedIssuer.authorizationServerClientId)(equalTo("client-2")) &&
assert(updatedIssuer.authorizationServerClientSecret)(equalTo("secret-2")) &&
assert(updatedIssuer.updatedAt)(not(equalTo(issuer.createdAt)))
},
test("update credential issuer with empty patch successfully") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ class JdbcOID4VCIIssuerMetadataRepository(xa: Transactor[ContextAwareTask], xb:

override def updateIssuer(
issuerId: UUID,
authorizationServer: Option[URL]
authorizationServer: Option[URL],
authorizationServerClientId: Option[String],
authorizationServerClientSecret: Option[String]
): URIO[WalletAccessContext, Unit] = {
val setFr = (now: Instant) =>
Fragments.set(
fr"updated_at = $now",
(Seq(authorizationServer.map(url => fr"authorization_server = $url")).flatten): _*
(Seq(
authorizationServer.map(url => fr"authorization_server = $url"),
authorizationServerClientId.map(i => fr"authorization_server_client_id = $i"),
authorizationServerClientSecret.map(i => fr"authorization_server_client_secret = $i")
).flatten)*
)
val cxnIO = (setFr: Fragment) => sql"""
|UPDATE public.issuer_metadata
Expand Down

0 comments on commit 096b746

Please sign in to comment.