forked from TrueCloudLab/frostfs-node
aarifullin
39060382a1
* Introduce Target type and pass it to all gRPC methods for APE chain managing instead CID. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package control
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
"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"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
|
nativeschema "git.frostfs.info/TrueCloudLab/policy-engine/schema/native"
|
|
"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)
|
|
|
|
var cnr cid.ID
|
|
cidStr, _ := cmd.Flags().GetString(commonflags.CIDFlag)
|
|
commonCmd.ExitOnErr(cmd, "can't decode container ID: %w", cnr.DecodeString(cidStr))
|
|
|
|
rawCID := make([]byte, sha256.Size)
|
|
cnr.Encode(rawCID)
|
|
|
|
chainID, _ := cmd.Flags().GetString(chainIDFlag)
|
|
|
|
name := fmt.Sprintf(nativeschema.ResourceFormatRootContainerObjects, cidStr)
|
|
|
|
req := &control.GetChainLocalOverrideRequest{
|
|
Body: &control.GetChainLocalOverrideRequest_Body{
|
|
Target: &control.ChainTarget{
|
|
Name: name,
|
|
Type: control.ChainTarget_CONTAINER,
|
|
},
|
|
ChainId: 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()))
|
|
|
|
// TODO (aarifullin): make pretty-formatted output for chains.
|
|
cmd.Println("Parsed chain:\n" + prettyJSONFormat(cmd, chain.Bytes()))
|
|
}
|
|
|
|
func initControGetRuleCmd() {
|
|
initControlFlags(getRuleCmd)
|
|
|
|
ff := getRuleCmd.Flags()
|
|
ff.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
|
ff.String(chainIDFlag, "", "Chain id")
|
|
}
|