[#1607] adm/ape: Extend kind flag to accept integer
All checks were successful
DCO action / DCO (pull_request) Successful in 47s
Vulncheck / Vulncheck (pull_request) Successful in 1m4s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m25s
Build / Build Components (pull_request) Successful in 1m32s
Tests and linters / Run gofumpt (pull_request) Successful in 1m35s
Tests and linters / Staticcheck (pull_request) Successful in 1m58s
Tests and linters / Lint (pull_request) Successful in 2m41s
Tests and linters / Tests (pull_request) Successful in 1m55s
Tests and linters / gopls check (pull_request) Successful in 3m57s
Tests and linters / Tests with -race (pull_request) Successful in 4m5s

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2025-02-04 14:57:02 +03:00
parent 38ece83eeb
commit a6f300ea17
3 changed files with 11 additions and 4 deletions

View file

@ -26,7 +26,7 @@ const (
func initListChainNamesCmd() { func initListChainNamesCmd() {
listChainNamesCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc) listChainNamesCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
listChainNamesCmd.Flags().String(kindFlag, "n", "Target kind (1-byte) to list (n(namespace)/c(container)/g(group)/u(user)/i(iam))") listChainNamesCmd.Flags().String(kindFlag, "n", "Target kind (1-byte) to list (n(namespace)/c(container)/g(group)/u(user)/i(iam)) or its integer representation")
listChainNamesCmd.Flags().String(nameFlag, "", "Target name to list") listChainNamesCmd.Flags().String(nameFlag, "", "Target name to list")
listChainNamesCmd.Flags().Bool(nameBase64Flag, false, "Use this flag if you provide name in base64 format") listChainNamesCmd.Flags().Bool(nameBase64Flag, false, "Use this flag if you provide name in base64 format")

View file

@ -28,7 +28,7 @@ const (
func initListChainsByPrefixCmd() { func initListChainsByPrefixCmd() {
listChainsByPrefixCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc) listChainsByPrefixCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
listChainsByPrefixCmd.Flags().String(kindFlag, "n", "Target kind (1-byte) to list (n(namespace)/c(container)/g(group)/u(user)/i(iam))") listChainsByPrefixCmd.Flags().String(kindFlag, "n", "Target kind (1-byte) to list (n(namespace)/c(container)/g(group)/u(user)/i(iam)) or its integer representation")
listChainsByPrefixCmd.Flags().String(nameFlag, "", "Target name to list") listChainsByPrefixCmd.Flags().String(nameFlag, "", "Target name to list")
listChainsByPrefixCmd.Flags().String(prefixFlag, "", "Prefix to list") listChainsByPrefixCmd.Flags().String(prefixFlag, "", "Prefix to list")
listChainsByPrefixCmd.Flags().Bool(prefixBase64Flag, false, "Use this flag if you provide prefix in base64 format") listChainsByPrefixCmd.Flags().Bool(prefixBase64Flag, false, "Use this flag if you provide prefix in base64 format")

View file

@ -4,6 +4,7 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"math/big" "math/big"
"strconv"
"git.frostfs.info/TrueCloudLab/frostfs-contract/commonclient" "git.frostfs.info/TrueCloudLab/frostfs-contract/commonclient"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
@ -22,7 +23,8 @@ var listTargetsCmd = &cobra.Command{
Short: "Invoke 'listTargets' method", Short: "Invoke 'listTargets' method",
Long: "Invoke 'listTargets' method in policy contract and print results to stdout", Long: "Invoke 'listTargets' method in policy contract and print results to stdout",
Example: `raw -r http://localhost:40332 list-targets Example: `raw -r http://localhost:40332 list-targets
raw -r http://localhost:40332 --policy-hash 81c1a41d09e08087a4b679418b12be5d3ab15742 list-targets --kind c`, raw -r http://localhost:40332 --policy-hash 81c1a41d09e08087a4b679418b12be5d3ab15742 list-targets --kind c
raw -r http://localhost:40332 --policy-hash 81c1a41d09e08087a4b679418b12be5d3ab15742 list-targets --kind 99`,
RunE: runListTargetsCmd, RunE: runListTargetsCmd,
} }
@ -38,7 +40,7 @@ const (
func initListTargetsCmd() { func initListTargetsCmd() {
listTargetsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc) listTargetsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
listTargetsCmd.Flags().String(kindFlag, "n", "Target kind (1-byte) to list (n(namespace)/c(container)/g(group)/u(user)/i(iam))") listTargetsCmd.Flags().String(kindFlag, "n", "Target kind (1-byte) to list (n(namespace)/c(container)/g(group)/u(user)/i(iam)) or its integer representation")
} }
func runListTargetsCmd(cmd *cobra.Command, _ []string) error { func runListTargetsCmd(cmd *cobra.Command, _ []string) error {
@ -63,6 +65,11 @@ func runListTargetsCmd(cmd *cobra.Command, _ []string) error {
} }
func parseTargetKind(typ string) (*big.Int, error) { func parseTargetKind(typ string) (*big.Int, error) {
val, err := strconv.ParseInt(typ, 10, 64)
if err == nil {
return big.NewInt(val), nil
}
if len(typ) != 1 { if len(typ) != 1 {
return nil, fmt.Errorf("invalid type: %s", typ) return nil, fmt.Errorf("invalid type: %s", typ)
} }