-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: partially implement jdbc issuer metadata repo
- Loading branch information
Showing
6 changed files
with
97 additions
and
8 deletions.
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
14 changes: 14 additions & 0 deletions
14
pollux/sql-doobie/src/main/resources/sql/pollux/V20__add_issuer_metadata.sql
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,14 @@ | ||
CREATE TABLE public.issuer_metadata ( | ||
id UUID PRIMARY KEY, | ||
authorization_server VARCHAR(1000) NOT NULL, | ||
created_at TIMESTAMP WITH TIME ZONE NOT NULL, | ||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL, | ||
wallet_id UUID NOT NULL | ||
); | ||
|
||
ALTER TABLE public.issuer_metadata | ||
ENABLE ROW LEVEL SECURITY; | ||
|
||
CREATE POLICY issuer_metadata_wallet_isolation | ||
ON public.issuer_metadata | ||
USING (wallet_id = current_setting('app.current_wallet_id')::UUID); |
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
73 changes: 73 additions & 0 deletions
73
...a/org/hyperledger/identus/pollux/sql/repository/JdbcOIDC4VCIssuerMetadataRepository.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,73 @@ | ||
package org.hyperledger.identus.pollux.sql.repository | ||
|
||
import doobie.* | ||
import doobie.implicits.* | ||
import doobie.postgres.implicits.* | ||
import doobie.util.transactor.Transactor | ||
import org.hyperledger.identus.pollux.core.model.oidc4vc.CredentialConfiguration | ||
import org.hyperledger.identus.pollux.core.model.oidc4vc.CredentialIssuer | ||
import org.hyperledger.identus.pollux.core.repository.OIDC4VCIssuerMetadataRepository | ||
import org.hyperledger.identus.shared.db.ContextAwareTask | ||
import org.hyperledger.identus.shared.db.Implicits.{*, given} | ||
import org.hyperledger.identus.shared.models.WalletAccessContext | ||
import org.hyperledger.identus.shared.models.WalletId | ||
import zio.* | ||
|
||
import java.net.URL | ||
import java.util.UUID | ||
|
||
// TODO: implement all members | ||
class JdbcOIDC4VCIssuerMetadataRepository(xa: Transactor[ContextAwareTask]) extends OIDC4VCIssuerMetadataRepository { | ||
|
||
override def findAllCredentialConfigurations(issuerId: UUID): UIO[Seq[CredentialConfiguration]] = ??? | ||
|
||
override def findWalletIssuers: URIO[WalletAccessContext, Seq[CredentialIssuer]] = ??? | ||
|
||
override def createIssuer(issuer: CredentialIssuer): URIO[WalletAccessContext, Unit] = { | ||
val cxnIO = (walletId: WalletId) => sql""" | ||
|INSERT INTO public.issuer_metadata ( | ||
| id, | ||
| authorization_server, | ||
| created_at, | ||
| updated_at, | ||
| wallet_id | ||
|) VALUES ( | ||
| ${issuer.id}, | ||
| ${issuer.authorizationServer}, | ||
| ${issuer.createdAt}, | ||
| ${issuer.updatedAt}, | ||
| ${walletId} | ||
|) | ||
""".stripMargin.update | ||
|
||
for { | ||
walletId <- ZIO.serviceWith[WalletAccessContext](_.walletId) | ||
_ <- cxnIO(walletId).run.transactWallet(xa).ensureOneAffectedRowOrDie | ||
} yield () | ||
} | ||
|
||
override def deleteCredentialConfiguration( | ||
issuerId: UUID, | ||
configurationId: String | ||
): URIO[WalletAccessContext, Unit] = ??? | ||
|
||
override def findIssuer(issuerId: UUID): UIO[Option[CredentialIssuer]] = ??? | ||
|
||
override def updateIssuer( | ||
issuerId: UUID, | ||
authorizationServer: Option[URL] | ||
): URIO[WalletAccessContext, CredentialIssuer] = ??? | ||
|
||
override def createCredentialConfiguration( | ||
issuerId: UUID, | ||
config: CredentialConfiguration | ||
): URIO[WalletAccessContext, Unit] = ??? | ||
|
||
override def deleteIssuer(issuerId: UUID): URIO[WalletAccessContext, Unit] = ??? | ||
|
||
} | ||
|
||
object JdbcOIDC4VCIssuerMetadataRepository { | ||
val layer: URLayer[Transactor[ContextAwareTask], OIDC4VCIssuerMetadataRepository] = | ||
ZLayer.fromFunction(new JdbcOIDC4VCIssuerMetadataRepository(_)) | ||
} |
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