Airat Arifullin
daff77b273
* Refactor local override managing subcommands * Use `cmd/internal/common/ape` parser commands within local override subcommands * Use flag names from `cmd/internal/common/ape` Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package control
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"strconv"
|
|
"text/tabwriter"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
|
apeCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/ape"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
|
|
"github.com/spf13/cobra"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
var listTargetsCmd = &cobra.Command{
|
|
Use: "list-targets",
|
|
Short: "List local targets",
|
|
Long: "List local APE overrides of the node",
|
|
Run: listTargets,
|
|
}
|
|
|
|
func listTargets(cmd *cobra.Command, _ []string) {
|
|
pk := key.Get(cmd)
|
|
|
|
chainName := apeCmd.ParseChainName(cmd)
|
|
|
|
req := &control.ListTargetsLocalOverridesRequest{
|
|
Body: &control.ListTargetsLocalOverridesRequest_Body{
|
|
ChainName: string(chainName),
|
|
},
|
|
}
|
|
|
|
signRequest(cmd, pk, req)
|
|
|
|
cli := getClient(cmd, pk)
|
|
|
|
var resp *control.ListTargetsLocalOverridesResponse
|
|
var err error
|
|
err = cli.ExecRaw(func(client *client.Client) error {
|
|
resp, err = control.ListTargetsLocalOverrides(client, req)
|
|
return err
|
|
})
|
|
if err != nil && status.Code(err) == codes.NotFound {
|
|
cmd.Println("Local overrides are not defined for any target.")
|
|
return
|
|
}
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
|
|
|
targets := resp.GetBody().GetTargets()
|
|
if len(targets) == 0 {
|
|
cmd.Println("Local overrides are not defined for any target.")
|
|
return
|
|
}
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
tw := tabwriter.NewWriter(buf, 0, 2, 2, ' ', 0)
|
|
_, _ = tw.Write([]byte("#\tName\tType\n"))
|
|
for i, t := range targets {
|
|
_, _ = tw.Write([]byte(fmt.Sprintf("%s\t%s\t%s\n", strconv.Itoa(i), t.GetName(), t.GetType())))
|
|
}
|
|
_ = tw.Flush()
|
|
cmd.Print(buf.String())
|
|
}
|
|
|
|
func initControlListTargetsCmd() {
|
|
initControlFlags(listTargetsCmd)
|
|
|
|
ff := listTargetsCmd.Flags()
|
|
ff.String(apeCmd.ChainNameFlag, "", apeCmd.ChainNameFlagDesc)
|
|
|
|
_ = cobra.MarkFlagRequired(ff, apeCmd.ChainNameFlag)
|
|
}
|