Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBQu committed Dec 16, 2024
1 parent 5a48789 commit 6d103ce
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 3 deletions.
1 change: 1 addition & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func NewDefraCommand() *cobra.Command {
MakeKeyringGenerateCommand(),
MakeKeyringImportCommand(),
MakeKeyringExportCommand(),
MakeKeyringListCommand(),
)

identity := MakeIdentityCommand()
Expand Down
44 changes: 44 additions & 0 deletions cli/keyring_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cli

import (
"github.com/spf13/cobra"
)

// MakeKeyringListCommand creates a new command to list all keys in the keyring.
func MakeKeyringListCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "list",
Short: "List all keys in the keyring",
Long: `List all keys in the keyring.
The DEFRA_KEYRING_SECRET environment variable must be set to unlock the keyring.
This can also be done with a .env file in the working directory or at a path
defined with the --secret-file flag.
Example:
defradb keyring list`,
Args: cobra.NoArgs, // No arguments expected
RunE: func(cmd *cobra.Command, args []string) error {
keyring, err := openKeyring(cmd)
if err != nil {
return err
}

keyNames, err := keyring.List()
if err != nil {
return err
}

if len(keyNames) == 0 {
cmd.Println("No keys found in the keyring.")
return nil
}

cmd.Println("Keys in the keyring:")
for _, keyName := range keyNames {
cmd.Println("- " + keyName)
}
return nil
},
}
return cmd
}
8 changes: 5 additions & 3 deletions internal/planner/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package planner

import (
"fmt"

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/request"
"github.com/sourcenetwork/defradb/internal/core"
Expand Down Expand Up @@ -59,9 +61,6 @@ type groupExecInfo struct {
}

// Creates a new group node.

// The function is recursive and will construct the node-chain for any child (`_group`) collections.
// `groupSelect` is optional and will typically be nil if the child `_group` is not requested.
func (p *Planner) GroupBy(n *mapper.GroupBy, parsed *mapper.Select, childSelects []*mapper.Select) (*groupNode, error) {
if n == nil {
return nil, nil
Expand All @@ -83,6 +82,9 @@ func (p *Planner) GroupBy(n *mapper.GroupBy, parsed *mapper.Select, childSelects
// group by fields have to be propagated downwards to ensure correct sub-grouping, otherwise child
// groups will only group on the fields they explicitly reference
childSelect.GroupBy.Fields = append(childSelect.GroupBy.Fields, n.Fields...)
for _, field := range childSelect.GroupBy.Fields {
fmt.Println("field", field)

Check failure on line 86 in internal/planner/group.go

View workflow job for this annotation

GitHub Actions / Lint GoLang job

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
}
}
dataSources = append(dataSources, newDataSource(childSelect.Index))
}
Expand Down
24 changes: 24 additions & 0 deletions keyring/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,27 @@ func (f *fileKeyring) Delete(user string) error {
}
return err
}

// List is a method that lists all keys in the file-based keyring directory.
func (f *fileKeyring) List() ([]string, error) {
return listKeys(f.dir)
}

// listKeys is a helper function to list all keys in the given keyring directory.
func listKeys(keyringDir string) ([]string, error) {
// Read all the files in the keyring directory
files, err := os.ReadDir(keyringDir)
if err != nil {
return nil, err // Return an error if the directory cannot be read
}

// Extract file names
var keyNames []string
for _, file := range files {
if !file.IsDir() { // Only include files, not subdirectories
keyNames = append(keyNames, file.Name())
}
}

return keyNames, nil
}
2 changes: 2 additions & 0 deletions keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ type Keyring interface {
//
// If a key with that name does not exist `ErrNotFound` is returned.
Delete(name string) error
// List returns a list of all keys in the keyring, used by the CLI 'keyring list' command
List() ([]string, error)
}
6 changes: 6 additions & 0 deletions keyring/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ func (s *systemKeyring) Get(name string) ([]byte, error) {
func (s *systemKeyring) Delete(user string) error {
return keyring.Delete(s.service, user)
}

func (s *systemKeyring) List() ([]string, error) {
// List does not need to be returned here
// This function is a stub
return nil, nil
}

0 comments on commit 6d103ce

Please sign in to comment.