[#1889] Move netmap.go and exit.go from cli to cmd/internal/common

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-01-16 12:20:16 +03:00 committed by fyrchik
parent 5a9d6a09d8
commit 2b09564355
62 changed files with 269 additions and 247 deletions

View file

@ -2,8 +2,8 @@ package control
import (
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
"github.com/spf13/cobra"
)
@ -40,7 +40,7 @@ var dropObjectsCmd = &cobra.Command{
resp, err = control.DropObjects(client, req)
return err
})
common.ExitOnErr(cmd, "", err)
commonCmd.ExitOnErr(cmd, "", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

View file

@ -2,8 +2,8 @@ package control
import (
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
"github.com/spf13/cobra"
)
@ -32,7 +32,7 @@ func evacuateShard(cmd *cobra.Command, _ []string) {
resp, err = control.EvacuateShard(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
cmd.Printf("Objects moved: %d\n", resp.GetBody().GetCount())

View file

@ -2,8 +2,8 @@ package control
import (
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
"github.com/spf13/cobra"
)
@ -31,7 +31,7 @@ func flushCache(cmd *cobra.Command, _ []string) {
resp, err = control.FlushCache(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

View file

@ -4,8 +4,8 @@ import (
"crypto/ecdsa"
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
ircontrol "github.com/TrueCloudLab/frostfs-node/pkg/services/control/ir"
ircontrolsrv "github.com/TrueCloudLab/frostfs-node/pkg/services/control/ir/server"
@ -52,7 +52,7 @@ func healthCheck(cmd *cobra.Command, _ []string) {
resp, err = control.HealthCheck(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
@ -66,14 +66,14 @@ func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client)
req.SetBody(new(ircontrol.HealthCheckRequest_Body))
err := ircontrolsrv.SignMessage(key, req)
common.ExitOnErr(cmd, "could not sign request: %w", err)
commonCmd.ExitOnErr(cmd, "could not sign request: %w", err)
var resp *ircontrol.HealthCheckResponse
err = c.ExecRaw(func(client *rawclient.Client) error {
resp, err = ircontrol.HealthCheck(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

View file

@ -7,6 +7,7 @@ import (
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
"github.com/spf13/cobra"
)
@ -57,7 +58,7 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) {
switch st, _ := cmd.Flags().GetString(netmapStatusFlag); st {
default:
common.ExitOnErr(cmd, "", fmt.Errorf("unsupported status %s", st))
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("unsupported status %s", st))
case netmapStatusOnline:
body.SetStatus(control.NetmapStatus_ONLINE)
printIgnoreForce(control.NetmapStatus_ONLINE)
@ -86,7 +87,7 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) {
resp, err = control.SetNetmapStatus(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

View file

@ -2,8 +2,8 @@ package control
import (
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
"github.com/spf13/cobra"
)
@ -45,7 +45,7 @@ func dumpShard(cmd *cobra.Command, _ []string) {
resp, err = control.DumpShard(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

View file

@ -7,9 +7,9 @@ import (
"strings"
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
"github.com/mr-tron/base58"
"github.com/spf13/cobra"
@ -45,7 +45,7 @@ func listShards(cmd *cobra.Command, _ []string) {
resp, err = control.ListShards(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
@ -73,7 +73,7 @@ func prettyPrintShardsJSON(cmd *cobra.Command, ii []*control.ShardInfo) {
buf := bytes.NewBuffer(nil)
enc := json.NewEncoder(buf)
enc.SetIndent("", " ")
common.ExitOnErr(cmd, "cannot shard info to JSON: %w", enc.Encode(out))
commonCmd.ExitOnErr(cmd, "cannot shard info to JSON: %w", enc.Encode(out))
cmd.Print(buf.String()) // pretty printer emits newline, to no need for Println
}

View file

@ -2,8 +2,8 @@ package control
import (
"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
"github.com/spf13/cobra"
)
@ -45,7 +45,7 @@ func restoreShard(cmd *cobra.Command, _ []string) {
resp, err = control.RestoreShard(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

View file

@ -5,8 +5,8 @@ import (
"strings"
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
"github.com/mr-tron/base58"
"github.com/spf13/cobra"
@ -106,7 +106,7 @@ func setShardMode(cmd *cobra.Command, _ []string) {
mode, ok := lookUpShardModeFromString(strMode)
if !ok {
common.ExitOnErr(cmd, "", fmt.Errorf("unsupported mode %s", strMode))
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("unsupported mode %s", strMode))
}
req := new(control.SetShardModeRequest)
@ -130,7 +130,7 @@ func setShardMode(cmd *cobra.Command, _ []string) {
resp, err = control.SetShardMode(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
@ -140,7 +140,7 @@ func setShardMode(cmd *cobra.Command, _ []string) {
func getShardID(cmd *cobra.Command) []byte {
sid, _ := cmd.Flags().GetString(shardIDFlag)
raw, err := base58.Decode(sid)
common.ExitOnErr(cmd, "incorrect shard ID encoding: %w", err)
commonCmd.ExitOnErr(cmd, "incorrect shard ID encoding: %w", err)
return raw
}
@ -152,7 +152,7 @@ func getShardIDList(cmd *cobra.Command) [][]byte {
sidList, _ := cmd.Flags().GetStringSlice(shardIDFlag)
if len(sidList) == 0 {
common.ExitOnErr(cmd, "", fmt.Errorf("either --%s or --%s flag must be provided", shardIDFlag, shardAllFlag))
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("either --%s or --%s flag must be provided", shardIDFlag, shardAllFlag))
}
// We can sort the ID list and perform this check without additional allocations,
@ -161,7 +161,7 @@ func getShardIDList(cmd *cobra.Command) [][]byte {
seen := make(map[string]struct{})
for i := range sidList {
if _, ok := seen[sidList[i]]; ok {
common.ExitOnErr(cmd, "", fmt.Errorf("duplicated shard IDs: %s", sidList[i]))
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("duplicated shard IDs: %s", sidList[i]))
}
seen[sidList[i]] = struct{}{}
}
@ -169,7 +169,7 @@ func getShardIDList(cmd *cobra.Command) [][]byte {
res := make([][]byte, 0, len(sidList))
for i := range sidList {
raw, err := base58.Decode(sidList[i])
common.ExitOnErr(cmd, "incorrect shard ID encoding: %w", err)
commonCmd.ExitOnErr(cmd, "incorrect shard ID encoding: %w", err)
res = append(res, raw)
}

View file

@ -5,9 +5,9 @@ import (
"errors"
rawclient "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/TrueCloudLab/frostfs-node/pkg/services/control"
controlSvc "github.com/TrueCloudLab/frostfs-node/pkg/services/control/server"
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
@ -40,11 +40,11 @@ func synchronizeTree(cmd *cobra.Command, _ []string) {
var cnr cid.ID
cidStr, _ := cmd.Flags().GetString(commonflags.CIDFlag)
common.ExitOnErr(cmd, "can't decode container ID: %w", cnr.DecodeString(cidStr))
commonCmd.ExitOnErr(cmd, "can't decode container ID: %w", cnr.DecodeString(cidStr))
treeID, _ := cmd.Flags().GetString("tree-id")
if treeID == "" {
common.ExitOnErr(cmd, "", errors.New("tree ID must not be empty"))
commonCmd.ExitOnErr(cmd, "", errors.New("tree ID must not be empty"))
}
height, _ := cmd.Flags().GetUint64("height")
@ -61,7 +61,7 @@ func synchronizeTree(cmd *cobra.Command, _ []string) {
}
err := controlSvc.SignMessage(pk, req)
common.ExitOnErr(cmd, "could not sign request: %w", err)
commonCmd.ExitOnErr(cmd, "could not sign request: %w", err)
cli := getClient(cmd, pk)
@ -70,7 +70,7 @@ func synchronizeTree(cmd *cobra.Command, _ []string) {
resp, err = control.SynchronizeTree(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())

View file

@ -6,8 +6,8 @@ import (
"github.com/TrueCloudLab/frostfs-api-go/v2/refs"
internalclient "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
controlSvc "github.com/TrueCloudLab/frostfs-node/pkg/services/control/server"
"github.com/TrueCloudLab/frostfs-sdk-go/client"
frostfscrypto "github.com/TrueCloudLab/frostfs-sdk-go/crypto"
@ -24,7 +24,7 @@ func initControlFlags(cmd *cobra.Command) {
func signRequest(cmd *cobra.Command, pk *ecdsa.PrivateKey, req controlSvc.SignedMessage) {
err := controlSvc.SignMessage(pk, req)
common.ExitOnErr(cmd, "could not sign request: %w", err)
commonCmd.ExitOnErr(cmd, "could not sign request: %w", err)
}
func verifyResponse(cmd *cobra.Command,
@ -37,7 +37,7 @@ func verifyResponse(cmd *cobra.Command,
},
) {
if sigControl == nil {
common.ExitOnErr(cmd, "", errors.New("missing response signature"))
commonCmd.ExitOnErr(cmd, "", errors.New("missing response signature"))
}
// TODO(@cthulhu-rider): #1387 use Signature message from NeoFS API to avoid conversion
@ -47,10 +47,10 @@ func verifyResponse(cmd *cobra.Command,
sigV2.SetSign(sigControl.GetSign())
var sig frostfscrypto.Signature
common.ExitOnErr(cmd, "can't read signature: %w", sig.ReadFromV2(sigV2))
commonCmd.ExitOnErr(cmd, "can't read signature: %w", sig.ReadFromV2(sigV2))
if !sig.Verify(body.StableMarshal(nil)) {
common.ExitOnErr(cmd, "", errors.New("invalid response signature"))
commonCmd.ExitOnErr(cmd, "", errors.New("invalid response signature"))
}
}