Airat Arifullin
4a64b07703
* Fix add-rule, list-rules, remove-rule, get-rule commands: do not convert container ID to native-schema resource format and pass it to control API. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package control
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
|
|
"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"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var listRulesCmd = &cobra.Command{
|
|
Use: "list-rules",
|
|
Short: "List local overrides",
|
|
Long: "List local APE overrides of the node",
|
|
Run: listRules,
|
|
}
|
|
|
|
func listRules(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)
|
|
|
|
req := &control.ListChainLocalOverridesRequest{
|
|
Body: &control.ListChainLocalOverridesRequest_Body{
|
|
Target: &control.ChainTarget{
|
|
Name: cidStr,
|
|
Type: control.ChainTarget_CONTAINER,
|
|
},
|
|
},
|
|
}
|
|
|
|
signRequest(cmd, pk, req)
|
|
|
|
cli := getClient(cmd, pk)
|
|
|
|
var resp *control.ListChainLocalOverridesResponse
|
|
var err error
|
|
err = cli.ExecRaw(func(client *client.Client) error {
|
|
resp, err = control.ListChainLocalOverrides(client, req)
|
|
return err
|
|
})
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
|
|
|
chains := resp.GetBody().GetChains()
|
|
if len(chains) == 0 {
|
|
cmd.Println("Local overrides are not defined for the container.")
|
|
return
|
|
}
|
|
|
|
for _, c := range chains {
|
|
// TODO (aarifullin): make pretty-formatted output for chains.
|
|
var chain apechain.Chain
|
|
commonCmd.ExitOnErr(cmd, "decode error: %w", chain.DecodeBytes(c))
|
|
cmd.Println("Parsed chain:\n" + prettyJSONFormat(cmd, chain.Bytes()))
|
|
}
|
|
}
|
|
|
|
func initControlListRulesCmd() {
|
|
initControlFlags(listRulesCmd)
|
|
|
|
ff := listRulesCmd.Flags()
|
|
ff.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
|
}
|