2024-01-26 14:15:28 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"crypto/sha256"
|
|
|
|
"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"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
|
2024-01-26 14:15:28 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"github.com/spf13/cobra"
|
2024-06-26 11:44:41 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2024-01-26 14:15:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
chainNameFlag = "chain-name"
|
|
|
|
chainNameFlagUsage = "Chain name(ingress|s3)"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
var cnr cid.ID
|
|
|
|
chainName, _ := cmd.Flags().GetString(chainNameFlag)
|
|
|
|
|
|
|
|
rawCID := make([]byte, sha256.Size)
|
|
|
|
cnr.Encode(rawCID)
|
|
|
|
|
|
|
|
req := &control.ListTargetsLocalOverridesRequest{
|
|
|
|
Body: &control.ListTargetsLocalOverridesRequest_Body{
|
|
|
|
ChainName: 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
|
|
|
|
})
|
2024-06-26 11:44:41 +00:00
|
|
|
if err != nil && status.Code(err) == codes.NotFound {
|
|
|
|
cmd.Println("Local overrides are not defined for any target.")
|
|
|
|
return
|
|
|
|
}
|
2024-01-26 14:15:28 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
|
|
|
|
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
|
|
|
|
|
|
|
targets := resp.GetBody().GetTargets()
|
|
|
|
if len(targets) == 0 {
|
2024-02-29 11:22:10 +00:00
|
|
|
cmd.Println("Local overrides are not defined for any target.")
|
2024-01-26 14:15:28 +00:00
|
|
|
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(chainNameFlag, "", chainNameFlagUsage)
|
|
|
|
|
|
|
|
_ = cobra.MarkFlagRequired(ff, chainNameFlag)
|
|
|
|
}
|