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

control: add network settings management via ir control #3059

Merged
merged 1 commit into from
Dec 28, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog for NeoFS Node
### Added
- Initial support for meta-on-chain for objects (#2877)
- First split-object part into the CLI output (#3064)
- `neofs-cli control notary` with `list`, `request` and `sign` commands (#3059)

### Fixed
- `neofs-cli object delete` command output (#3056)
Expand Down
20 changes: 20 additions & 0 deletions cmd/neofs-cli/modules/control/notary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package control

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

var notaryCmd = &cobra.Command{
Use: "notary",
Short: "Commands with notary request with alphabet key of inner ring node",
}

func initControlNotaryCmd() {
notaryCmd.AddCommand(listNotaryCmd)
notaryCmd.AddCommand(notaryRequestCmd)
notaryCmd.AddCommand(notarySignCmd)

initControlNotaryListCmd()
initControlNotaryRequestCmd()
initControlNotarySignCmd()

Check warning on line 19 in cmd/neofs-cli/modules/control/notary.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary.go#L12-L19

Added lines #L12 - L19 were not covered by tests
}
74 changes: 74 additions & 0 deletions cmd/neofs-cli/modules/control/notary_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package control

import (
"fmt"

"github.com/nspcc-dev/neo-go/pkg/util"
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
"github.com/spf13/cobra"
)

var listNotaryCmd = &cobra.Command{
Use: "list",
Short: "Get list of all notary requests in network",
Long: "Get list of all notary requests in network",
Args: cobra.NoArgs,
RunE: listNotary,
}

func initControlNotaryListCmd() {
initControlFlags(listNotaryCmd)

Check warning on line 24 in cmd/neofs-cli/modules/control/notary_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_list.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

func listNotary(cmd *cobra.Command, _ []string) error {
ctx, cancel := commonflags.GetCommandContext(cmd)
defer cancel()

pk, err := key.Get(cmd)
if err != nil {
return err
}

Check warning on line 34 in cmd/neofs-cli/modules/control/notary_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_list.go#L27-L34

Added lines #L27 - L34 were not covered by tests

cli, err := getClient(ctx)
if err != nil {
return err
}

Check warning on line 39 in cmd/neofs-cli/modules/control/notary_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_list.go#L36-L39

Added lines #L36 - L39 were not covered by tests

req := new(ircontrol.NotaryListRequest)

req.SetBody(new(ircontrol.NotaryListRequest_Body))

err = ircontrolsrv.SignMessage(pk, req)
if err != nil {
return fmt.Errorf("could not sign request: %w", err)
}

Check warning on line 48 in cmd/neofs-cli/modules/control/notary_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_list.go#L41-L48

Added lines #L41 - L48 were not covered by tests

var resp *ircontrol.NotaryListResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = ircontrol.NotaryList(client, req)
return err
})
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}

Check warning on line 57 in cmd/neofs-cli/modules/control/notary_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_list.go#L50-L57

Added lines #L50 - L57 were not covered by tests

err = verifyResponse(resp.GetSignature(), resp.GetBody())
if err != nil {
return err
}

Check warning on line 62 in cmd/neofs-cli/modules/control/notary_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_list.go#L59-L62

Added lines #L59 - L62 were not covered by tests

txs := resp.GetBody().GetTransactions()

for _, tx := range txs {
hash, err := util.Uint256DecodeBytesBE(tx.GetHash())
if err != nil {
return fmt.Errorf("failed to decode hash: %w", err)
}
cmd.Println(hash.String())

Check warning on line 71 in cmd/neofs-cli/modules/control/notary_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_list.go#L64-L71

Added lines #L64 - L71 were not covered by tests
}
return nil

Check warning on line 73 in cmd/neofs-cli/modules/control/notary_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_list.go#L73

Added line #L73 was not covered by tests
}
112 changes: 112 additions & 0 deletions cmd/neofs-cli/modules/control/notary_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package control

import (
"fmt"
"strings"

"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/util"
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
"github.com/spf13/cobra"
)

const notaryMethodFlag = "method"

var notaryRequestCmd = &cobra.Command{
Use: "request",
Short: "Create and send a notary request",
Long: "Create and send a notary request with one of the following methods:\n" +
"- newEpoch, transaction for creating of new NeoFS epoch event in FS chain, no args\n" +
"- setConfig, transaction to add/update global config value in the NeoFS network, 1 arg in the form key=val\n" +
"- removeNode, transaction to move nodes to the Offline state in the candidates list, 1 arg is the public key of the node",
RunE: notaryRequest,
}

func initControlNotaryRequestCmd() {
initControlFlags(notaryRequestCmd)

flags := notaryRequestCmd.Flags()
flags.String(notaryMethodFlag, "", "Requested method")

Check warning on line 33 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L29-L33

Added lines #L29 - L33 were not covered by tests
}

func notaryRequest(cmd *cobra.Command, args []string) error {
ctx, cancel := commonflags.GetCommandContext(cmd)
defer cancel()

pk, err := key.Get(cmd)
if err != nil {
return err
}

Check warning on line 43 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L36-L43

Added lines #L36 - L43 were not covered by tests

cli, err := getClient(ctx)
if err != nil {
return err
}

Check warning on line 48 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L45-L48

Added lines #L45 - L48 were not covered by tests

req := new(ircontrol.NotaryRequestRequest)
body := new(ircontrol.NotaryRequestRequest_Body)
req.SetBody(body)

method, _ := cmd.Flags().GetString(notaryMethodFlag)
body.SetMethod(method)

switch method {
case "newEpoch":
if len(args) > 0 {
cmd.Println("method 'newEpoch', but the args provided, they will be ignored")
}
case "setConfig":
if len(args) != 1 {
return fmt.Errorf("invalid number of args provided for 'setConfig', expected 1, got %d", len(args))
}

Check warning on line 65 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L50-L65

Added lines #L50 - L65 were not covered by tests

kv := strings.SplitN(args[0], "=", 2)
if len(kv) != 2 {
return fmt.Errorf("invalid parameter format: must be 'key=val', got: %s", args[0])
}

Check warning on line 70 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L67-L70

Added lines #L67 - L70 were not covered by tests

body.SetArgs([][]byte{[]byte(kv[0]), []byte(kv[1])})
case "removeNode":
if len(args) != 1 {
return fmt.Errorf("invalid number of args provided for 'removeNode', expected 1, got %d", len(args))
}
key, err := keys.NewPublicKeyFromString(args[0])
if err != nil {
return err
}

Check warning on line 80 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L72-L80

Added lines #L72 - L80 were not covered by tests

body.SetArgs([][]byte{key.Bytes()})

Check warning on line 82 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L82

Added line #L82 was not covered by tests
}

err = ircontrolsrv.SignMessage(pk, req)
if err != nil {
return fmt.Errorf("could not sign request: %w", err)
}

Check warning on line 88 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L85-L88

Added lines #L85 - L88 were not covered by tests

var resp *ircontrol.NotaryRequestResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = ircontrol.NotaryRequest(client, req)
return err
})
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}

Check warning on line 97 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L90-L97

Added lines #L90 - L97 were not covered by tests

err = verifyResponse(resp.GetSignature(), resp.GetBody())
if err != nil {
return err
}

Check warning on line 102 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L99-L102

Added lines #L99 - L102 were not covered by tests

hashB := resp.GetBody().GetHash()

hash, err := util.Uint256DecodeBytesBE(hashB)
if err != nil {
return fmt.Errorf("failed to decode hash %v: %w", hashB, err)
}
cmd.Printf("Transaction Hash: %s\n", hash.String())
return nil

Check warning on line 111 in cmd/neofs-cli/modules/control/notary_request.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_request.go#L104-L111

Added lines #L104 - L111 were not covered by tests
}
75 changes: 75 additions & 0 deletions cmd/neofs-cli/modules/control/notary_sign.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package control

import (
"fmt"

"github.com/nspcc-dev/neo-go/pkg/util"
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
"github.com/spf13/cobra"
)

var notarySignHashFlag string

var notarySignCmd = &cobra.Command{
Use: "sign",
Short: "Sign notary request by its hash",
Long: "Sign notary request by its hash",
Args: cobra.NoArgs,
RunE: notarySign,
}

func initControlNotarySignCmd() {
initControlFlags(notarySignCmd)

flags := notarySignCmd.Flags()
flags.StringVar(&notarySignHashFlag, "hash", "", "hash of the notary request")

Check warning on line 29 in cmd/neofs-cli/modules/control/notary_sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_sign.go#L25-L29

Added lines #L25 - L29 were not covered by tests
}

func notarySign(cmd *cobra.Command, _ []string) error {
ctx, cancel := commonflags.GetCommandContext(cmd)
defer cancel()

pk, err := key.Get(cmd)
if err != nil {
return err
}

Check warning on line 39 in cmd/neofs-cli/modules/control/notary_sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_sign.go#L32-L39

Added lines #L32 - L39 were not covered by tests

cli, err := getClient(ctx)
if err != nil {
return err
}

Check warning on line 44 in cmd/neofs-cli/modules/control/notary_sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_sign.go#L41-L44

Added lines #L41 - L44 were not covered by tests

req := new(ircontrol.NotarySignRequest)
body := new(ircontrol.NotarySignRequest_Body)
req.SetBody(body)
hash, err := util.Uint256DecodeStringBE(notarySignHashFlag)
if err != nil {
return fmt.Errorf("failed to decode hash: %w", err)
}
body.SetHash(hash.BytesBE())

err = ircontrolsrv.SignMessage(pk, req)
if err != nil {
return fmt.Errorf("could not sign request: %w", err)
}

Check warning on line 58 in cmd/neofs-cli/modules/control/notary_sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_sign.go#L46-L58

Added lines #L46 - L58 were not covered by tests

var resp *ircontrol.NotarySignResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = ircontrol.NotarySign(client, req)
return err
})
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}

Check warning on line 67 in cmd/neofs-cli/modules/control/notary_sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_sign.go#L60-L67

Added lines #L60 - L67 were not covered by tests

err = verifyResponse(resp.GetSignature(), resp.GetBody())
if err != nil {
return err
}

Check warning on line 72 in cmd/neofs-cli/modules/control/notary_sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_sign.go#L69-L72

Added lines #L69 - L72 were not covered by tests

return nil

Check warning on line 74 in cmd/neofs-cli/modules/control/notary_sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/notary_sign.go#L74

Added line #L74 was not covered by tests
}
2 changes: 2 additions & 0 deletions cmd/neofs-cli/modules/control/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
shardsCmd,
synchronizeTreeCmd,
objectCmd,
notaryCmd,

Check warning on line 37 in cmd/neofs-cli/modules/control/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/root.go#L37

Added line #L37 was not covered by tests
)

initControlHealthCheckCmd()
Expand All @@ -42,4 +43,5 @@
initControlShardsCmd()
initControlSynchronizeTreeCmd()
initControlObjectsCmd()
initControlNotaryCmd()

Check warning on line 46 in cmd/neofs-cli/modules/control/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/root.go#L46

Added line #L46 was not covered by tests
}
1 change: 1 addition & 0 deletions docs/cli-commands/neofs-cli_control.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Operations with storage node
* [neofs-cli](neofs-cli.md) - Command Line Tool to work with NeoFS
* [neofs-cli control drop-objects](neofs-cli_control_drop-objects.md) - Drop objects from the node's local storage
* [neofs-cli control healthcheck](neofs-cli_control_healthcheck.md) - Health check of the NeoFS node
* [neofs-cli control notary](neofs-cli_control_notary.md) - Commands with notary request with alphabet key of inner ring node
* [neofs-cli control object](neofs-cli_control_object.md) - Direct object operations with storage engine
* [neofs-cli control set-status](neofs-cli_control_set-status.md) - Set status of the storage node in NeoFS network map
* [neofs-cli control shards](neofs-cli_control_shards.md) - Operations with storage node's shards
Expand Down
24 changes: 24 additions & 0 deletions docs/cli-commands/neofs-cli_control_notary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## neofs-cli control notary

Commands with notary request with alphabet key of inner ring node

### Options

```
-h, --help help for notary
```

### Options inherited from parent commands

```
-c, --config string Config file (default is $HOME/.config/neofs-cli/config.yaml)
-v, --verbose Verbose output
```

### SEE ALSO

* [neofs-cli control](neofs-cli_control.md) - Operations with storage node
* [neofs-cli control notary list](neofs-cli_control_notary_list.md) - Get list of all notary requests in network
* [neofs-cli control notary request](neofs-cli_control_notary_request.md) - Create and send a notary request
* [neofs-cli control notary sign](neofs-cli_control_notary_sign.md) - Sign notary request by its hash

33 changes: 33 additions & 0 deletions docs/cli-commands/neofs-cli_control_notary_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## neofs-cli control notary list

Get list of all notary requests in network

### Synopsis

Get list of all notary requests in network

```
neofs-cli control notary list [flags]
```

### Options

```
--address string Address of wallet account
--endpoint string Remote node control address (as 'multiaddr' or '<host>:<port>')
-h, --help help for list
-t, --timeout duration Timeout for the operation (default 15s)
-w, --wallet string Path to the wallet
```

### Options inherited from parent commands

```
-c, --config string Config file (default is $HOME/.config/neofs-cli/config.yaml)
-v, --verbose Verbose output
```

### SEE ALSO

* [neofs-cli control notary](neofs-cli_control_notary.md) - Commands with notary request with alphabet key of inner ring node

Loading
Loading