Skip to content

Add context to AuditInfoStore #915 #916

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions docs/db-driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type BindingStore interface {
}

type AuditInfoStore interface {
GetAuditInfo(id view.Identity) ([]byte, error)
PutAuditInfo(id view.Identity, info []byte) error
GetAuditInfo(ctx context.Context, id view.Identity) ([]byte, error)
PutAuditInfo(ctx context.Context, id view.Identity, info []byte) error
}
```

Expand Down
6 changes: 4 additions & 2 deletions platform/common/driver/kvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0
package driver

import (
"context"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
)

Expand All @@ -21,8 +23,8 @@ type SignerInfoStore interface {
}

type AuditInfoStore interface {
GetAuditInfo(id view.Identity) ([]byte, error)
PutAuditInfo(id view.Identity, info []byte) error
GetAuditInfo(ctx context.Context, id view.Identity) ([]byte, error)
PutAuditInfo(ctx context.Context, id view.Identity, info []byte) error
}

type BindingStore interface {
Expand Down
6 changes: 4 additions & 2 deletions platform/common/driver/sigservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0
package driver

import (
"context"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
)

Expand Down Expand Up @@ -62,10 +64,10 @@ type SigService interface {
// AuditRegistry models a repository of identities' audit information
type AuditRegistry interface {
// RegisterAuditInfo binds the passed audit info to the passed identity
RegisterAuditInfo(identity view.Identity, info []byte) error
RegisterAuditInfo(ctx context.Context, identity view.Identity, info []byte) error

// GetAuditInfo returns the audit info associated to the passed identity, nil if not found
GetAuditInfo(identity view.Identity) ([]byte, error)
GetAuditInfo(ctx context.Context, identity view.Identity) ([]byte, error)
}

type SigRegistry interface {
Expand Down
13 changes: 7 additions & 6 deletions platform/common/services/sig/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package sig

import (
"context"
"fmt"
"reflect"
"runtime/debug"
Expand Down Expand Up @@ -142,12 +143,12 @@ func (o *Service) RegisterVerifier(identity view.Identity, verifier driver.Verif
return nil
}

func (o *Service) RegisterAuditInfo(identity view.Identity, info []byte) error {
return o.auditInfoKVS.PutAuditInfo(identity, info)
func (o *Service) RegisterAuditInfo(ctx context.Context, identity view.Identity, info []byte) error {
return o.auditInfoKVS.PutAuditInfo(ctx, identity, info)
}

func (o *Service) GetAuditInfo(identity view.Identity) ([]byte, error) {
return o.auditInfoKVS.GetAuditInfo(identity)
func (o *Service) GetAuditInfo(ctx context.Context, identity view.Identity) ([]byte, error) {
return o.auditInfoKVS.GetAuditInfo(ctx, identity)
}

func (o *Service) IsMe(identity view.Identity) bool {
Expand Down Expand Up @@ -183,8 +184,8 @@ func (o *Service) AreMe(identities ...view.Identity) []string {
return result.ToSlice()
}

func (o *Service) Info(id view.Identity) string {
auditInfo, err := o.GetAuditInfo(id)
func (o *Service) Info(ctx context.Context, id view.Identity) string {
auditInfo, err := o.GetAuditInfo(ctx, id)
if err != nil {
logger.Debugf("failed getting audit info for [%s]", id)
return fmt.Sprintf("unable to identify identity : [%s][%s]", id.UniqueID(), string(id))
Expand Down
5 changes: 3 additions & 2 deletions platform/view/services/db/driver/sql/common/auditinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package common

import (
"context"
"database/sql"
"fmt"

Expand Down Expand Up @@ -36,7 +37,7 @@ type AuditInfoStore struct {
ci common.CondInterpreter
}

func (db *AuditInfoStore) GetAuditInfo(id view.Identity) ([]byte, error) {
func (db *AuditInfoStore) GetAuditInfo(ctx context.Context, id view.Identity) ([]byte, error) {
query, params := q.Select().FieldsByName("audit_info").
From(q.Table(db.table)).
Where(cond.Eq("id", id.UniqueID())).
Expand All @@ -46,7 +47,7 @@ func (db *AuditInfoStore) GetAuditInfo(id view.Identity) ([]byte, error) {
return QueryUnique[[]byte](db.readDB, query, params...)
}

func (db *AuditInfoStore) PutAuditInfo(id view.Identity, info []byte) error {
func (db *AuditInfoStore) PutAuditInfo(ctx context.Context, id view.Identity, info []byte) error {
query, params := q.InsertInto(db.table).
Fields("id", "audit_info").
Row(id.UniqueID(), info).
Expand Down
10 changes: 6 additions & 4 deletions platform/view/sig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0
package view

import (
"context"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/driver"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
)
Expand Down Expand Up @@ -70,13 +72,13 @@ type SigService struct {
}

// RegisterAuditInfo binds the passed audit info to the passed identity
func (s *SigService) RegisterAuditInfo(identity view.Identity, info []byte) error {
return s.auditRegistry.RegisterAuditInfo(identity, info)
func (s *SigService) RegisterAuditInfo(ctx context.Context, identity view.Identity, info []byte) error {
return s.auditRegistry.RegisterAuditInfo(ctx, identity, info)
}

// GetAuditInfo returns the audit info associated to the passed identity, nil if not found
func (s *SigService) GetAuditInfo(identity view.Identity) ([]byte, error) {
return s.auditRegistry.GetAuditInfo(identity)
func (s *SigService) GetAuditInfo(ctx context.Context, identity view.Identity) ([]byte, error) {
return s.auditRegistry.GetAuditInfo(ctx, identity)
}

// RegisterSigner binds the passed identity to the passed signer and verifier
Expand Down
Loading