Skip to content

Commit

Permalink
PR(ACP): Remove ACPModule from client.Store
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Mar 14, 2024
1 parent c83c90b commit 0c63d72
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 58 deletions.
5 changes: 0 additions & 5 deletions client/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/lens-vm/lens/host-go/config/model"
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/events"
)
Expand Down Expand Up @@ -223,10 +222,6 @@ type Store interface {
request string,
) *RequestResult

// ACPModule returns the underlying acp module (optional). Incase the access control
// is turned off, then the returned acp module will have no value (will be empty).
ACPModule(context.Context) (immutable.Option[acp.ACPModule], error)

// AddPolicy attempts to add policy if the acp module exists, otherwise returns an error.
AddPolicy(context.Context, string, string) (AddPolicyResult, error)
}
Expand Down
1 change: 1 addition & 0 deletions db/collection_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ func (c *collection) makeSelectionPlan(
planner := planner.New(
ctx,
identity,
c.db.acp,
c.db.WithTxn(txn),
txn,
)
Expand Down
8 changes: 7 additions & 1 deletion db/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ func (db *db) execRequest(
return res
}

planner := planner.New(ctx, identity, db.WithTxn(txn), txn)
planner := planner.New(
ctx,
identity,
db.acp,
db.WithTxn(txn),
txn,
)

results, err := planner.RunRequest(ctx, parsedRequest)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion db/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ func (db *db) handleEvent(
evt events.Update,
r *request.ObjectSubscription,
) {
p := planner.New(ctx, identity, db.WithTxn(txn), txn)
p := planner.New(
ctx,
identity,
db.acp,
db.WithTxn(txn),
txn,
)

s := r.ToSelect(evt.DocID, evt.Cid.String())

Expand Down
33 changes: 4 additions & 29 deletions db/txn_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
)
Expand Down Expand Up @@ -403,20 +402,6 @@ func (db *explicitTxnDB) LensRegistry() client.LensRegistry {
return db.lensRegistry
}

func (db *implicitTxnDB) ACPModule(ctx context.Context) (immutable.Option[acp.ACPModule], error) {
txn, err := db.NewTxn(ctx, true)
if err != nil {
return acp.NoACPModule, err
}
defer txn.Discard(ctx)

return db.acp, txn.Commit(ctx)
}

func (db *explicitTxnDB) ACPModule(ctx context.Context) (immutable.Option[acp.ACPModule], error) {
return db.acp, nil
}

func (db *implicitTxnDB) AddPolicy(
ctx context.Context,
creator string,
Expand All @@ -428,16 +413,11 @@ func (db *implicitTxnDB) AddPolicy(
}
defer txn.Discard(ctx)

acpModule, err := db.ACPModule(ctx)
if err != nil {
return client.AddPolicyResult{}, err
}

if !acpModule.HasValue() {
if !db.acp.HasValue() {
return client.AddPolicyResult{}, client.ErrPolicyAddFailureACPModuleNotFound
}

policyID, err := acpModule.Value().AddPolicy(
policyID, err := db.acp.Value().AddPolicy(
ctx,
creator,
policy,
Expand All @@ -455,16 +435,11 @@ func (db *explicitTxnDB) AddPolicy(
creator string,
policy string,
) (client.AddPolicyResult, error) {
acpModule, err := db.ACPModule(ctx)
if err != nil {
return client.AddPolicyResult{}, err
}

if !acpModule.HasValue() {
if !db.acp.HasValue() {
return client.AddPolicyResult{}, client.ErrPolicyAddFailureACPModuleNotFound
}

policyID, err := acpModule.Value().AddPolicy(
policyID, err := db.acp.Value().AddPolicy(
ctx,
creator,
policy,
Expand Down
5 changes: 0 additions & 5 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/events"
Expand Down Expand Up @@ -434,10 +433,6 @@ func (c *Client) Peerstore() datastore.DSBatching {
panic("client side database")
}

func (c *Client) ACPModule(ctx context.Context) (immutable.Option[acp.ACPModule], error) {
panic("client side database")
}

func (c *Client) Events() events.Events {
panic("client side database")
}
Expand Down
4 changes: 4 additions & 0 deletions planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/request"
"github.com/sourcenetwork/defradb/connor"
Expand Down Expand Up @@ -86,6 +87,7 @@ type PlanContext struct {
type Planner struct {
txn datastore.Txn
identity immutable.Option[string]
acp immutable.Option[acp.ACPModule]
db client.Store

ctx context.Context
Expand All @@ -94,12 +96,14 @@ type Planner struct {
func New(
ctx context.Context,
identity immutable.Option[string],
acp immutable.Option[acp.ACPModule],
db client.Store,
txn datastore.Txn,
) *Planner {
return &Planner{
txn: txn,
identity: identity,
acp: acp,
db: db,
ctx: ctx,
}
Expand Down
7 changes: 1 addition & 6 deletions planner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,12 @@ func (n *scanNode) Kind() string {
}

func (n *scanNode) Init() error {
acpModule, err := n.p.db.ACPModule(n.p.ctx)
if err != nil {
return err
}

// init the fetcher
if err := n.fetcher.Init(
n.p.ctx,
n.p.identity,
n.p.txn,
acpModule,
n.p.acp,
n.col,
n.fields,
n.filter,
Expand Down
9 changes: 8 additions & 1 deletion tests/bench/query/planner/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"fmt"
"testing"

"github.com/sourcenetwork/defradb/acp"
acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/core"
"github.com/sourcenetwork/defradb/datastore"
Expand Down Expand Up @@ -79,7 +80,13 @@ func runMakePlanBench(

b.ResetTimer()
for i := 0; i < b.N; i++ {
planner := planner.New(ctx, acpIdentity.NoIdentity, db.WithTxn(txn), txn)
planner := planner.New(
ctx,
acpIdentity.NoIdentity,
acp.NoACPModule,
db.WithTxn(txn),
txn,
)
plan, err := planner.MakePlan(q)
if err != nil {
return errors.Wrap("failed to make plan", err)
Expand Down
5 changes: 0 additions & 5 deletions tests/clients/cli/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/cli"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
Expand Down Expand Up @@ -503,10 +502,6 @@ func (w *Wrapper) Peerstore() datastore.DSBatching {
return w.node.Peerstore()
}

func (w *Wrapper) ACPModule(ctx context.Context) (immutable.Option[acp.ACPModule], error) {
return w.node.ACPModule(ctx)
}

func (w *Wrapper) AddPolicy(
ctx context.Context,
creator string,
Expand Down
5 changes: 0 additions & 5 deletions tests/clients/http/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/events"
Expand Down Expand Up @@ -203,10 +202,6 @@ func (w *Wrapper) Peerstore() datastore.DSBatching {
return w.node.Peerstore()
}

func (w *Wrapper) ACPModule(ctx context.Context) (immutable.Option[acp.ACPModule], error) {
return w.node.ACPModule(ctx)
}

func (w *Wrapper) AddPolicy(
ctx context.Context,
creator string,
Expand Down

0 comments on commit 0c63d72

Please sign in to comment.