forked from TrueCloudLab/frostfs-node
Airat Arifullin
9b13a18aac
* Update version within go.mod; * Fix deprecated frostfs-api-go/v2 package and use frostfs-sdk-go/api instead. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
71 lines
2 KiB
Go
71 lines
2 KiB
Go
package control
|
|
|
|
import (
|
|
"encoding/hex"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util"
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
|
|
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var getRuleCmd = &cobra.Command{
|
|
Use: "get-rule",
|
|
Short: "Get local override",
|
|
Long: "Get local APE override of the node",
|
|
Run: getRule,
|
|
}
|
|
|
|
func getRule(cmd *cobra.Command, _ []string) {
|
|
pk := key.Get(cmd)
|
|
|
|
target := parseTarget(cmd)
|
|
|
|
chainID, _ := cmd.Flags().GetString(chainIDFlag)
|
|
hexEncoded, _ := cmd.Flags().GetBool(chainIDHexFlag)
|
|
|
|
if hexEncoded {
|
|
chainIDBytes, err := hex.DecodeString(chainID)
|
|
commonCmd.ExitOnErr(cmd, "can't decode chain ID as hex: %w", err)
|
|
chainID = string(chainIDBytes)
|
|
}
|
|
|
|
req := &control.GetChainLocalOverrideRequest{
|
|
Body: &control.GetChainLocalOverrideRequest_Body{
|
|
Target: target,
|
|
ChainId: []byte(chainID),
|
|
},
|
|
}
|
|
|
|
signRequest(cmd, pk, req)
|
|
|
|
cli := getClient(cmd, pk)
|
|
|
|
var resp *control.GetChainLocalOverrideResponse
|
|
var err error
|
|
err = cli.ExecRaw(func(client *client.Client) error {
|
|
resp, err = control.GetChainLocalOverride(client, req)
|
|
return err
|
|
})
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
|
|
|
var chain apechain.Chain
|
|
commonCmd.ExitOnErr(cmd, "decode error: %w", chain.DecodeBytes(resp.GetBody().GetChain()))
|
|
util.PrintHumanReadableAPEChain(cmd, &chain)
|
|
}
|
|
|
|
func initControGetRuleCmd() {
|
|
initControlFlags(getRuleCmd)
|
|
|
|
ff := getRuleCmd.Flags()
|
|
ff.String(targetNameFlag, "", targetNameDesc)
|
|
ff.String(targetTypeFlag, "", targetTypeDesc)
|
|
_ = getRuleCmd.MarkFlagRequired(targetTypeFlag)
|
|
ff.String(chainIDFlag, "", "Chain id")
|
|
ff.Bool(chainIDHexFlag, false, "Flag to parse chain ID as hex")
|
|
}
|