Skip to content

Commit

Permalink
CLI get config + version commands + tests
Browse files Browse the repository at this point in the history
Signed-off-by: May Rosenbaum <mayro1595@gmail.com>
  • Loading branch information
MayRosenbaum committed Oct 2, 2023
1 parent 700f92b commit c39582a
Show file tree
Hide file tree
Showing 15 changed files with 1,047 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ goimports:
.PHONY: binary
binary:
$(GO) build -o $(BIN)/bdb github.com/hyperledger-labs/orion-server/cmd/bdb
$(GO) build -o $(BIN)/bcdbadmin github.com/hyperledger-labs/orion-sdk-go/cli

.PHONY: test
test-script:
Expand Down
49 changes: 49 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Config Orion via CLI

This command-line tool provides a simple way to config an orion database server.

## Building the tool
1. Run from `orion-sdk` root folder
2. Run `make binary` to create an executable file named bcdbadmin under `bin` directory.

## Commands

Here we list and describe the available commands.
We give a short explanation of their usage and describe the flags for each command.
We provide real-world examples demonstrating how to use the CLI tool for various tasks.


### Version Command
This command prints the version of the CLI tool.
1. Run from `orion-sdk` root folder.
2. Run `bin/bcdbadmin version`. This command has no flags.



### Config Command
This command enables to config an orion server or ask for the configuration of an orion server.

#### Get Config Command
1. Run from 'orion-sdk' root folder.
2. For Get Config Run `bin/bcdbadmin config get [args]`.

Replace `[args]` with flags.

###
##### Flags
| Flags | Description |
|-----------------------------|-------------------------------------------------------------------------------|
| `-c, --cli-config-path` | the absolute or relative path of CLI connection configuration file |
| `-p, --cluster-config-path` | the absolute or relative path to which the server configuration will be saved |

Both flags are necessary flags. If any flag is missing, the cli will raise an error.

###
##### Example:

Running
`bin/bcdbadmin config get -c "connection-session-config.yaml" -p "local/config"`
reads the connection and session details needed for connecting to a server from `connection-session-config.yaml` and
sends a config TX.
It creates a directory in `local/config` with the respective certificates, a yaml file, named shared_cluster_config.yml, that includes the cluster configuration
and a yaml file, named version.yml, that includes the version.
43 changes: 43 additions & 0 deletions cli/commands/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package commands

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

func adminCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "admin",
Short: "manage administrators",
Args: nil,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("not implemented yet")
},
}

cmd.AddCommand(&cobra.Command{
Use: "add",
Short: "Add an admin",
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("not implemented yet")
},
})

cmd.AddCommand(&cobra.Command{
Use: "remove",
Short: "Remove an admin",
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("not implemented yet")
},
})

cmd.AddCommand(&cobra.Command{
Use: "update",
Short: "Update an admin",
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("not implemented yet")
},
})

return cmd
}
28 changes: 28 additions & 0 deletions cli/commands/admin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package commands

import (
"io/ioutil"
"os"
"testing"

"github.com/hyperledger-labs/orion-sdk-go/examples/util"
"github.com/stretchr/testify/require"
)

func TestAdminCommand(t *testing.T) {
// 1. Create crypto material and start server
tempDir, err := ioutil.TempDir(os.TempDir(), "ExampleTest")
require.NoError(t, err)

testServer, _, _, err := util.SetupTestEnv(t, tempDir, uint32(6003))
require.NoError(t, err)
defer testServer.Stop()
util.StartTestServer(t, testServer)

// 2. Check cas command response
rootCmd := InitializeOrionCli()
rootCmd.SetArgs([]string{"admin"})
err = rootCmd.Execute()
require.Error(t, err)
require.Equal(t, err.Error(), "not implemented yet")
}
35 changes: 35 additions & 0 deletions cli/commands/cas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package commands

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

func casCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "CAs",
Short: "manage CA's",
Args: nil,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("not implemented yet")
},
}

cmd.AddCommand(&cobra.Command{
Use: "add",
Short: "Add CA",
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("not implemented yet")
},
})

cmd.AddCommand(&cobra.Command{
Use: "remove",
Short: "Remove CA",
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("not implemented yet")
},
})

return cmd
}
28 changes: 28 additions & 0 deletions cli/commands/cas_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package commands

import (
"io/ioutil"
"os"
"testing"

"github.com/hyperledger-labs/orion-sdk-go/examples/util"
"github.com/stretchr/testify/require"
)

func TestCasCommand(t *testing.T) {
// 1. Create crypto material and start server
tempDir, err := ioutil.TempDir(os.TempDir(), "ExampleTest")
require.NoError(t, err)

testServer, _, _, err := util.SetupTestEnv(t, tempDir, uint32(6003))
require.NoError(t, err)
defer testServer.Stop()
util.StartTestServer(t, testServer)

// 2. Check cas command response
rootCmd := InitializeOrionCli()
rootCmd.SetArgs([]string{"CAs"})
err = rootCmd.Execute()
require.Error(t, err)
require.Equal(t, err.Error(), "not implemented yet")
}
Loading

0 comments on commit c39582a

Please sign in to comment.