Skip to content

Commit

Permalink
review feedback, change response time for aretimelimitedv2credssubmitted
Browse files Browse the repository at this point in the history
  • Loading branch information
husobee committed Feb 5, 2024
1 parent afad291 commit e53a580
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
6 changes: 3 additions & 3 deletions services/skus/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,16 @@ func (s *Service) doTLV2Exist(ctx context.Context, requestID uuid.UUID, item *mo
}

// Check TLV2 to see if we have credentials signed that match incoming blinded tokens.
alreadySubmitted, mismatch, err := s.Datastore.AreTimeLimitedV2CredsSubmitted(ctx, requestID, blindedCreds...)
credsSubmitted, err := s.Datastore.AreTimeLimitedV2CredsSubmitted(ctx, requestID, blindedCreds...)
if err != nil {
return fmt.Errorf("error validating credentials exist for order item: %w", err)
}

if alreadySubmitted {
if credsSubmitted.AlreadySubmitted {
// No need to create order credentials, since these are already submitted.
return errCredsAlreadySubmitted
}
if mismatch {
if credsSubmitted.Mismatch {
// conflict because those credentials were submitted with a different request id
return errCredsAlreadySubmittedMismatch
}
Expand Down
27 changes: 13 additions & 14 deletions services/skus/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type Datastore interface {
GetOrderCreds(orderID uuid.UUID, isSigned bool) ([]OrderCreds, error)
SendSigningRequest(ctx context.Context, signingRequestWriter SigningRequestWriter) error
InsertSignedOrderCredentialsTx(ctx context.Context, tx *sqlx.Tx, signedOrderResult *SigningOrderResult) error
AreTimeLimitedV2CredsSubmitted(ctx context.Context, requestID uuid.UUID, blindedCreds ...string) (bool, bool, error)
AreTimeLimitedV2CredsSubmitted(ctx context.Context, requestID uuid.UUID, blindedCreds ...string) (*AreTimeLimitedV2CredsSubmittedResult, error)
GetTimeLimitedV2OrderCredsByOrder(orderID uuid.UUID) (*TimeLimitedV2Creds, error)
GetTLV2Creds(ctx context.Context, dbi sqlx.QueryerContext, ordID, itemID, reqID uuid.UUID) (*TimeLimitedV2Creds, error)
DeleteTimeLimitedV2OrderCredsByOrderTx(ctx context.Context, tx *sqlx.Tx, orderID uuid.UUID) error
Expand Down Expand Up @@ -950,11 +950,18 @@ type TimeAwareSubIssuedCreds struct {
RequestID string `json:"-" db:"request_id"`
}

func (pg *Postgres) AreTimeLimitedV2CredsSubmitted(ctx context.Context, requestID uuid.UUID, blindedCreds ...string) (bool, bool, error) {
type AreTimeLimitedV2CredsSubmittedResult struct {
AlreadySubmitted bool `db:"already_submitted"`
Mismatch bool `db:"mismatch"`
}

func (pg *Postgres) AreTimeLimitedV2CredsSubmitted(ctx context.Context, requestID uuid.UUID, blindedCreds ...string) (*AreTimeLimitedV2CredsSubmittedResult, error) {
if len(blindedCreds) < 1 {
return false, false, errors.New("invalid parameter to tlv2 creds signed")
return nil, errors.New("invalid parameter to tlv2 creds signed")
}

var result = AreTimeLimitedV2CredsSubmittedResult{}

query := `
select exists(
select 1 from time_limited_v2_order_creds where blinded_creds->>0 = $1
Expand All @@ -963,20 +970,12 @@ func (pg *Postgres) AreTimeLimitedV2CredsSubmitted(ctx context.Context, requestI
select 1 from time_limited_v2_order_creds where blinded_creds->>0 = $1 and request_id != $2
) as mismatch
`

type data struct {
AlreadySubmitted bool `db:"already_submitted"`
Mismatch bool `db:"mismatch"`
}

var d = data{}

err := pg.RawDB().Get(&d, query, blindedCreds[0], requestID)
err := pg.RawDB().Get(&result, query, blindedCreds[0], requestID)
if err != nil {
return false, false, err
return nil, err
}

return d.AlreadySubmitted, d.Mismatch, nil
return &result, nil
}

// GetTimeLimitedV2OrderCredsByOrder returns all the non expired time limited v2 order credentials for a given order.
Expand Down
2 changes: 1 addition & 1 deletion services/skus/instrumented_datastore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions services/skus/mockdatastore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e53a580

Please sign in to comment.