-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rarimo/feature/claims-revocation
Claims revocation
- Loading branch information
Showing
16 changed files
with
385 additions
and
61 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
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 |
---|---|---|
|
@@ -8,6 +8,9 @@ allOf: | |
type: object | ||
required: | ||
- claim_id | ||
- issuer_did | ||
properties: | ||
claim_id: | ||
type: string | ||
issuer_did: | ||
type: string |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- +migrate Up | ||
alter table proofs add column claim_id uuid; | ||
|
||
create table claims( | ||
id uuid primary key, | ||
user_did text not null, | ||
issuer_did text not null, | ||
document text not null unique | ||
); | ||
|
||
-- +migrate Down | ||
alter table proofs drop column claim_id; | ||
drop table claims; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package data | ||
|
||
import "github.com/google/uuid" | ||
|
||
type ClaimQ interface { | ||
New() ClaimQ | ||
Insert(value Claim) error | ||
FilterBy(column string, value any) ClaimQ | ||
Get() (*Claim, error) | ||
DeleteByID(id uuid.UUID) error | ||
ForUpdate() ClaimQ | ||
ResetFilter() ClaimQ | ||
} | ||
|
||
type Claim struct { | ||
ID uuid.UUID `db:"id" structs:"id"` | ||
UserDID string `db:"user_did" structs:"user_did"` | ||
IssuerDID string `db:"issuer_did" structs:"issuer_did"` | ||
Document string `db:"document" structs:"document"` | ||
} |
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,10 @@ | ||
package data | ||
|
||
type MasterQ interface { | ||
New() MasterQ | ||
|
||
Proof() ProofQ | ||
Claim() ClaimQ | ||
|
||
Transaction(fn func(db MasterQ) error) error | ||
} |
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,74 @@ | ||
package pg | ||
|
||
import ( | ||
"database/sql" | ||
sq "github.com/Masterminds/squirrel" | ||
"github.com/fatih/structs" | ||
"github.com/google/uuid" | ||
"github.com/rarimo/passport-identity-provider/internal/data" | ||
"gitlab.com/distributed_lab/kit/pgdb" | ||
) | ||
|
||
const claimsTableName = "claims" | ||
|
||
var ( | ||
claimsSelector = sq.Select("*").From(claimsTableName) | ||
claimsUpdate = sq.Update(claimsTableName) | ||
) | ||
|
||
func NewClaimsQ(db *pgdb.DB) data.ClaimQ { | ||
return &claimsQ{ | ||
db: db, | ||
sql: claimsSelector, | ||
upd: claimsUpdate, | ||
} | ||
} | ||
|
||
type claimsQ struct { | ||
db *pgdb.DB | ||
sql sq.SelectBuilder | ||
upd sq.UpdateBuilder | ||
} | ||
|
||
func (q *claimsQ) New() data.ClaimQ { | ||
return NewClaimsQ(q.db.Clone()) | ||
} | ||
|
||
func (q *claimsQ) Insert(value data.Claim) error { | ||
clauses := structs.Map(value) | ||
stmt := sq.Insert(claimsTableName).SetMap(clauses) | ||
err := q.db.Exec(stmt) | ||
return err | ||
} | ||
|
||
func (q *claimsQ) FilterBy(column string, value any) data.ClaimQ { | ||
q.sql = q.sql.Where(sq.Eq{column: value}) | ||
return q | ||
} | ||
|
||
func (q *claimsQ) Get() (*data.Claim, error) { | ||
var result data.Claim | ||
err := q.db.Get(&result, q.sql) | ||
if err == sql.ErrNoRows { | ||
return nil, nil | ||
} | ||
return &result, err | ||
} | ||
|
||
func (q *claimsQ) DeleteByID(id uuid.UUID) error { | ||
if err := q.db.Exec(sq.Delete(claimsTableName).Where(sq.Eq{"id": id})); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (q *claimsQ) ForUpdate() data.ClaimQ { | ||
q.sql = q.sql.Suffix("FOR UPDATE") | ||
return q | ||
} | ||
|
||
func (q *claimsQ) ResetFilter() data.ClaimQ { | ||
q.sql = sq.Select("*").From(claimsTableName) | ||
q.upd = sq.Update(claimsTableName) | ||
return q | ||
} |
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,34 @@ | ||
package pg | ||
|
||
import ( | ||
"github.com/rarimo/passport-identity-provider/internal/data" | ||
"gitlab.com/distributed_lab/kit/pgdb" | ||
) | ||
|
||
func NewMasterQ(db *pgdb.DB) data.MasterQ { | ||
return &masterQ{ | ||
db: db.Clone(), | ||
} | ||
} | ||
|
||
type masterQ struct { | ||
db *pgdb.DB | ||
} | ||
|
||
func (m *masterQ) New() data.MasterQ { | ||
return NewMasterQ(m.db) | ||
} | ||
|
||
func (m *masterQ) Transaction(fn func(q data.MasterQ) error) error { | ||
return m.db.Transaction(func() error { | ||
return fn(m) | ||
}) | ||
} | ||
|
||
func (m *masterQ) Proof() data.ProofQ { | ||
return NewProofsQ(m.db) | ||
} | ||
|
||
func (m *masterQ) Claim() data.ClaimQ { | ||
return NewClaimsQ(m.db) | ||
} |
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
Oops, something went wrong.