forked from TrueCloudLab/frostfs-node
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package apemanager
|
|
|
|
import (
|
|
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
apeutil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util"
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
|
client_sdk "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
|
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var listCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: "List rule chains defined on target",
|
|
Run: list,
|
|
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
|
|
commonflags.Bind(cmd)
|
|
},
|
|
}
|
|
|
|
func list(cmd *cobra.Command, _ []string) {
|
|
target := parseTarget(cmd)
|
|
|
|
key := key.Get(cmd)
|
|
cli := internalclient.GetSDKClientByFlag(cmd, key, commonflags.RPC)
|
|
|
|
resp, err := cli.APEManagerListChains(cmd.Context(),
|
|
client_sdk.PrmAPEManagerListChains{
|
|
ChainTarget: target,
|
|
})
|
|
commonCmd.ExitOnErr(cmd, "list chains call error: %w", err)
|
|
|
|
for _, respChain := range resp.Chains {
|
|
var chain apechain.Chain
|
|
commonCmd.ExitOnErr(cmd, "decode error: %w", chain.DecodeBytes(respChain.Raw))
|
|
apeutil.PrintHumanReadableAPEChain(cmd, &chain)
|
|
}
|
|
}
|
|
|
|
func initListCmd() {
|
|
commonflags.Init(listCmd)
|
|
|
|
ff := listCmd.Flags()
|
|
ff.String(targetNameFlag, "", targetNameDesc)
|
|
ff.String(targetTypeFlag, "", targetTypeDesc)
|
|
_ = listCmd.MarkFlagRequired(targetTypeFlag)
|
|
}
|