Skip to content
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

feat: Inject ACP instance into the DB instance #2633

Merged
merged 4 commits into from
May 21, 2024
Merged
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion cli/server_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package cli
import (
"github.com/spf13/cobra"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/internal/db"
"github.com/sourcenetwork/defradb/node"
Expand All @@ -36,7 +37,7 @@ func MakeServerDumpCmd() *cobra.Command {
if err != nil {
return err
}
db, err := db.NewDB(cmd.Context(), rootstore)
db, err := db.NewDB(cmd.Context(), rootstore, acp.NoACP)
if err != nil {
return errors.Wrap("failed to initialize database", err)
}
Expand Down
11 changes: 6 additions & 5 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ func MakeStartCommand() *cobra.Command {
dbOpts := []db.Option{
db.WithUpdateEvents(),
db.WithMaxRetries(cfg.GetInt("datastore.MaxTxnRetries")),
// TODO-ACP: Infuture when we add support for the --no-acp flag when admin signatures are in,
// we can allow starting of db without acp. Currently that can only be done programmatically.
// https://github.com/sourcenetwork/defradb/issues/2271
db.WithACPInMemory(),
}

netOpts := []net.NodeOpt{
Expand All @@ -126,6 +122,10 @@ func MakeStartCommand() *cobra.Command {
node.WithInMemory(cfg.GetString("datastore.store") == configStoreMemory),
}

acpOpts := []node.ACPOpt{
node.WithACPType(node.LocalACPType),
}

var peers []peer.AddrInfo
if val := cfg.GetStringSlice("net.peers"); len(val) > 0 {
addrs, err := netutils.ParsePeers(val)
Expand All @@ -140,7 +140,7 @@ func MakeStartCommand() *cobra.Command {
// TODO-ACP: Infuture when we add support for the --no-acp flag when admin signatures are in,
// we can allow starting of db without acp. Currently that can only be done programmatically.
// https://github.com/sourcenetwork/defradb/issues/2271
dbOpts = append(dbOpts, db.WithACP(rootDir))
acpOpts = append(acpOpts, node.WithACPPath(rootDir))
shahzadlone marked this conversation as resolved.
Show resolved Hide resolved
}

if !cfg.GetBool("keyring.disabled") {
Expand Down Expand Up @@ -169,6 +169,7 @@ func MakeStartCommand() *cobra.Command {
node.WithNetOpts(netOpts...),
node.WithServerOpts(serverOpts...),
node.WithDisableP2P(cfg.GetBool("net.p2pDisabled")),
node.WithACPOpts(acpOpts...),
}

n, err := node.NewNode(cmd.Context(), opts...)
Expand Down
2 changes: 1 addition & 1 deletion cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"github.com/spf13/viper"
"golang.org/x/term"

acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/http"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
"github.com/sourcenetwork/defradb/internal/db"
"github.com/sourcenetwork/defradb/keyring"
)
Expand Down
3 changes: 2 additions & 1 deletion http/handler_ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore/memory"
"github.com/sourcenetwork/defradb/internal/db"
Expand Down Expand Up @@ -192,7 +193,7 @@ func TestCCIPPost_WithInvalidBody(t *testing.T) {
func setupDatabase(t *testing.T) client.DB {
ctx := context.Background()

cdb, err := db.NewDB(ctx, memory.NewDatastore(ctx), db.WithUpdateEvents())
cdb, err := db.NewDB(ctx, memory.NewDatastore(ctx), acp.NoACP, db.WithUpdateEvents())
require.NoError(t, err)

_, err = cdb.AddSchema(ctx, `type User {
Expand Down
2 changes: 1 addition & 1 deletion http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"github.com/go-chi/cors"
"golang.org/x/exp/slices"

acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
"github.com/sourcenetwork/defradb/internal/db"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/db/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"github.com/stretchr/testify/require"

acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
)

func TestBasicExport_WithNormalFormatting_NoError(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"github.com/lens-vm/lens/host-go/config/model"
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/request"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/events"
"github.com/sourcenetwork/defradb/internal/acp"
"github.com/sourcenetwork/defradb/internal/core"
coreblock "github.com/sourcenetwork/defradb/internal/core/block"
"github.com/sourcenetwork/defradb/internal/db/base"
Expand Down
2 changes: 1 addition & 1 deletion internal/db/collection_acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package db
import (
"context"

"github.com/sourcenetwork/defradb/internal/acp"
"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/internal/db/permission"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/db/collection_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

cidlink "github.com/ipld/go-ipld-prime/linking/cid"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/events"
"github.com/sourcenetwork/defradb/internal/acp"
"github.com/sourcenetwork/defradb/internal/core"
coreblock "github.com/sourcenetwork/defradb/internal/core/block"
"github.com/sourcenetwork/defradb/internal/merkle/clock"
Expand Down
15 changes: 0 additions & 15 deletions internal/db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
package db

import (
"context"

"github.com/lens-vm/lens/host-go/engine/module"
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/events"
"github.com/sourcenetwork/defradb/internal/acp"
)

const (
Expand All @@ -28,18 +25,6 @@ const (
// Option is a funtion that sets a config value on the db.
type Option func(*db)

// WithACP enables access control. If path is empty then acp runs in-memory.
func WithACP(path string) Option {
return func(db *db) {
var acpLocal acp.ACPLocal
acpLocal.Init(context.Background(), path)
db.acp = immutable.Some[acp.ACP](&acpLocal)
}
}

// WithACPInMemory enables access control in-memory.
func WithACPInMemory() Option { return WithACP("") }

// WithUpdateEvents enables the update events channel.
func WithUpdateEvents() Option {
return func(db *db) {
Expand Down
12 changes: 0 additions & 12 deletions internal/db/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestWithACP(t *testing.T) {
d := &db{}
WithACP("test")(d)
assert.True(t, d.acp.HasValue())
}

func TestWithACPInMemory(t *testing.T) {
d := &db{}
WithACPInMemory()(d)
assert.True(t, d.acp.HasValue())
}

func TestWithUpdateEvents(t *testing.T) {
d := &db{}
WithUpdateEvents()(d)
Expand Down
2 changes: 1 addition & 1 deletion internal/db/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

"github.com/sourcenetwork/immutable"

acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/datastore"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
)

// txnContextKey is the key type for transaction context values.
Expand Down
8 changes: 5 additions & 3 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"github.com/sourcenetwork/corelog"
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/events"
"github.com/sourcenetwork/defradb/internal/acp"
"github.com/sourcenetwork/defradb/internal/core"
"github.com/sourcenetwork/defradb/internal/lens"
"github.com/sourcenetwork/defradb/internal/request/graphql"
Expand Down Expand Up @@ -80,14 +80,16 @@ type db struct {
func NewDB(
ctx context.Context,
rootstore datastore.RootStore,
acp immutable.Option[acp.ACP],
options ...Option,
) (client.DB, error) {
return newDB(ctx, rootstore, options...)
return newDB(ctx, rootstore, acp, options...)
}

func newDB(
ctx context.Context,
rootstore datastore.RootStore,
acp immutable.Option[acp.ACP],
options ...Option,
) (*db, error) {
multistore := datastore.MultiStoreFrom(rootstore)
Expand All @@ -100,7 +102,7 @@ func newDB(
db := &db{
rootstore: rootstore,
multistore: multistore,
acp: acp.NoACP,
acp: acp,
parser: parser,
options: options,
}
Expand Down
5 changes: 3 additions & 2 deletions internal/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

badger "github.com/sourcenetwork/badger/v4"

"github.com/sourcenetwork/defradb/acp"
badgerds "github.com/sourcenetwork/defradb/datastore/badger/v4"
)

Expand All @@ -25,7 +26,7 @@ func newMemoryDB(ctx context.Context) (*db, error) {
if err != nil {
return nil, err
}
return newDB(ctx, rootstore)
return newDB(ctx, rootstore, acp.NoACP)
}

func TestNewDB(t *testing.T) {
Expand All @@ -37,7 +38,7 @@ func TestNewDB(t *testing.T) {
return
}

_, err = NewDB(ctx, rootstore)
_, err = NewDB(ctx, rootstore, acp.NoACP)
if err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/db/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/datastore/iterable"
"github.com/sourcenetwork/defradb/internal/acp"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
"github.com/sourcenetwork/defradb/internal/core"
"github.com/sourcenetwork/defradb/internal/db/base"
"github.com/sourcenetwork/defradb/internal/db/permission"
Expand Down
4 changes: 2 additions & 2 deletions internal/db/fetcher/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/internal/acp"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
"github.com/sourcenetwork/defradb/internal/core"
"github.com/sourcenetwork/defradb/internal/db/base"
"github.com/sourcenetwork/defradb/internal/planner/mapper"
Expand Down
4 changes: 2 additions & 2 deletions internal/db/fetcher/mocks/fetcher.go

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

4 changes: 2 additions & 2 deletions internal/db/fetcher/versioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/datastore/memory"
"github.com/sourcenetwork/defradb/internal/acp"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
"github.com/sourcenetwork/defradb/internal/core"
coreblock "github.com/sourcenetwork/defradb/internal/core/block"
"github.com/sourcenetwork/defradb/internal/db/base"
Expand Down
4 changes: 2 additions & 2 deletions internal/db/indexed_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/sourcenetwork/defradb/acp"
acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/datastore/mocks"
"github.com/sourcenetwork/defradb/internal/acp"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
"github.com/sourcenetwork/defradb/internal/core"
"github.com/sourcenetwork/defradb/internal/db/fetcher"
fetcherMocks "github.com/sourcenetwork/defradb/internal/db/fetcher/mocks"
Expand Down
4 changes: 2 additions & 2 deletions internal/db/permission/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/internal/acp"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
)

// CheckAccessOfDocOnCollectionWithACP handles the check, which tells us if access to the target
Expand Down
4 changes: 2 additions & 2 deletions internal/db/permission/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/internal/acp"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
)

// RegisterDocOnCollectionWithACP handles the registration of the document with acp.
Expand Down
4 changes: 2 additions & 2 deletions internal/lens/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/request"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/internal/acp"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
"github.com/sourcenetwork/defradb/internal/core"
"github.com/sourcenetwork/defradb/internal/db/fetcher"
"github.com/sourcenetwork/defradb/internal/planner/mapper"
Expand Down
4 changes: 2 additions & 2 deletions internal/planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp"
acpIdentity "github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/request"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/internal/acp"
acpIdentity "github.com/sourcenetwork/defradb/internal/acp/identity"
"github.com/sourcenetwork/defradb/internal/connor"
"github.com/sourcenetwork/defradb/internal/core"
"github.com/sourcenetwork/defradb/internal/planner/filter"
Expand Down
Loading
Loading