0a1530afa0
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package control
|
|
|
|
import (
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
const (
|
|
restoreFilepathFlag = "path"
|
|
restoreIgnoreErrorsFlag = "no-errors"
|
|
)
|
|
|
|
var restoreShardCmd = &cobra.Command{
|
|
Use: "restore",
|
|
Short: "Restore objects from shard",
|
|
Long: "Restore objects from shard to a file",
|
|
Run: restoreShard,
|
|
}
|
|
|
|
func restoreShard(cmd *cobra.Command, _ []string) {
|
|
pk := key.Get(cmd)
|
|
|
|
body := new(control.RestoreShardRequest_Body)
|
|
body.SetShardID(getShardID(cmd))
|
|
|
|
p, _ := cmd.Flags().GetString(restoreFilepathFlag)
|
|
body.SetFilepath(p)
|
|
|
|
ignore, _ := cmd.Flags().GetBool(restoreIgnoreErrorsFlag)
|
|
body.SetIgnoreErrors(ignore)
|
|
|
|
req := new(control.RestoreShardRequest)
|
|
req.SetBody(body)
|
|
|
|
signRequest(cmd, pk, req)
|
|
|
|
cli := getClient(cmd, pk)
|
|
|
|
var resp *control.RestoreShardResponse
|
|
var err error
|
|
err = cli.ExecRaw(func(client *client.Client) error {
|
|
resp, err = control.RestoreShard(client, req)
|
|
return err
|
|
})
|
|
common.ExitOnErr(cmd, "rpc error: %w", err)
|
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
|
|
|
cmd.Println("Shard has been restored successfully.")
|
|
}
|
|
|
|
func initControlRestoreShardCmd() {
|
|
initControlFlags(restoreShardCmd)
|
|
|
|
flags := restoreShardCmd.Flags()
|
|
flags.String(shardIDFlag, "", "Shard ID in base58 encoding")
|
|
flags.String(restoreFilepathFlag, "", "File to read objects from")
|
|
flags.Bool(restoreIgnoreErrorsFlag, false, "Skip invalid/unreadable objects")
|
|
|
|
_ = restoreShardCmd.MarkFlagRequired(shardIDFlag)
|
|
_ = restoreShardCmd.MarkFlagRequired(restoreFilepathFlag)
|
|
_ = restoreShardCmd.MarkFlagRequired(controlRPC)
|
|
}
|