2023-10-31 08:55:42 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
2023-12-21 12:55:09 +00:00
|
|
|
"encoding/hex"
|
2023-10-31 08:55:42 +00:00
|
|
|
|
|
|
|
"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"
|
2024-01-25 17:25:23 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util"
|
2023-10-31 08:55:42 +00:00
|
|
|
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"
|
2023-11-16 07:58:55 +00:00
|
|
|
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
2023-10-31 08:55:42 +00:00
|
|
|
"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)
|
2023-12-21 12:55:09 +00:00
|
|
|
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)
|
|
|
|
}
|
2023-10-31 08:55:42 +00:00
|
|
|
|
|
|
|
req := &control.GetChainLocalOverrideRequest{
|
|
|
|
Body: &control.GetChainLocalOverrideRequest_Body{
|
2023-12-05 09:11:28 +00:00
|
|
|
Target: &control.ChainTarget{
|
2023-12-13 12:25:47 +00:00
|
|
|
Name: cidStr,
|
2023-12-05 09:11:28 +00:00
|
|
|
Type: control.ChainTarget_CONTAINER,
|
|
|
|
},
|
2023-12-21 12:05:45 +00:00
|
|
|
ChainId: []byte(chainID),
|
2023-10-31 08:55:42 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
2023-11-16 07:58:55 +00:00
|
|
|
var chain apechain.Chain
|
2023-10-31 08:55:42 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "decode error: %w", chain.DecodeBytes(resp.GetBody().GetChain()))
|
2024-01-25 17:25:23 +00:00
|
|
|
util.PrintHumanReadableAPEChain(cmd, &chain)
|
2023-10-31 08:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initControGetRuleCmd() {
|
|
|
|
initControlFlags(getRuleCmd)
|
|
|
|
|
|
|
|
ff := getRuleCmd.Flags()
|
|
|
|
ff.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
|
|
|
ff.String(chainIDFlag, "", "Chain id")
|
2023-12-21 12:55:09 +00:00
|
|
|
ff.Bool(chainIDHexFlag, false, "Flag to parse chain ID as hex")
|
2023-10-31 08:55:42 +00:00
|
|
|
}
|