Skip to content

Commit

Permalink
Move function
Browse files Browse the repository at this point in the history
  • Loading branch information
islamaliev committed Jul 8, 2024
1 parent eaa8992 commit ac72996
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
15 changes: 15 additions & 0 deletions cli/collection_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
"github.com/spf13/cobra"

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/internal/db"
"github.com/sourcenetwork/defradb/internal/encryption"
)

func MakeCollectionCreateCommand() *cobra.Command {
Expand Down Expand Up @@ -112,3 +114,16 @@ Example: create from stdin:
cmd.Flags().StringVarP(&file, "file", "f", "", "File containing document(s)")
return cmd
}

// setContextDocEncryption sets doc encryption for the current command context.
func setContextDocEncryption(cmd *cobra.Command, shouldEncrypt bool, encryptFields []string, txn datastore.Txn) {
if !shouldEncrypt && len(encryptFields) == 0 {
return
}
ctx := cmd.Context()
if txn != nil {
ctx = encryption.ContextWithStore(ctx, txn)
}
ctx = encryption.SetContextConfigFromParams(ctx, shouldEncrypt, encryptFields)
cmd.SetContext(ctx)
}
15 changes: 0 additions & 15 deletions cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ import (

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

Expand Down Expand Up @@ -162,19 +160,6 @@ func setContextIdentity(cmd *cobra.Command, privateKeyHex string) error {
return nil
}

// setContextDocEncryption sets doc encryption for the current command context.
func setContextDocEncryption(cmd *cobra.Command, shouldEncrypt bool, encryptFields []string, txn datastore.Txn) {
if !shouldEncrypt && len(encryptFields) == 0 {
return
}
ctx := cmd.Context()
if txn != nil {
ctx = encryption.ContextWithStore(ctx, txn)
}
ctx = encryption.SetContextConfigFromParams(ctx, shouldEncrypt, encryptFields)
cmd.SetContext(ctx)
}

// setContextRootDir sets the rootdir for the current command context.
func setContextRootDir(cmd *cobra.Command) error {
rootdir, err := cmd.Root().PersistentFlags().GetString("rootdir")
Expand Down

0 comments on commit ac72996

Please sign in to comment.