Skip to content
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: update issuer auth server model parity #1154

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading