frostfs-node/cmd/frostfs-cli/modules/ape_manager/list_chain.go
Airat Arifullin 8a465b74ad
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 50s
DCO action / DCO (pull_request) Successful in 1m6s
Vulncheck / Vulncheck (pull_request) Successful in 2m12s
Tests and linters / Staticcheck (pull_request) Successful in 2m41s
Build / Build Components (pull_request) Successful in 2m48s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m49s
Tests and linters / gopls check (pull_request) Successful in 3m21s
Tests and linters / Lint (pull_request) Successful in 3m46s
Tests and linters / Tests (pull_request) Successful in 3m58s
Tests and linters / Tests with -race (pull_request) Successful in 4m16s
[#1501] cli: Refactor APE-related commands
* Move common rule parsing logic to a common package that
  also can be imported out of `frostfs-node`;
* Move common flags and commands to `cmd/internal/common/ape` package to
  avoid duplication. Since `frostfs-adm` and `frostfs-cli` subcommands
  are able to use commands, thee same flag names and their descriptions.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-11-15 15:59:37 +03:00

49 lines
1.6 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"
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
apecmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/ape"
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))
apecmd.PrintHumanReadableAPEChain(cmd, &chain)
}
}
func initListCmd() {
commonflags.Init(listCmd)
ff := listCmd.Flags()
ff.String(apecmd.TargetNameFlag, "", apecmd.TargetNameFlagDesc)
ff.String(apecmd.TargetTypeFlag, "", apecmd.TargetTypeFlagDesc)
_ = listCmd.MarkFlagRequired(apecmd.TargetTypeFlag)
}