All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 2m6s
Tests and linters / Run gofumpt (pull_request) Successful in 2m16s
DCO action / DCO (pull_request) Successful in 2m35s
Build / Build Components (1.23) (pull_request) Successful in 3m0s
Build / Build Components (1.22) (pull_request) Successful in 3m0s
Tests and linters / Tests (1.22) (pull_request) Successful in 3m1s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m24s
Tests and linters / Tests (1.23) (pull_request) Successful in 3m41s
Tests and linters / Staticcheck (pull_request) Successful in 3m39s
Tests and linters / Lint (pull_request) Successful in 4m15s
Tests and linters / Tests with -race (pull_request) Successful in 4m28s
Tests and linters / gopls check (pull_request) Successful in 4m29s
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package nns
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
|
client "git.frostfs.info/TrueCloudLab/frostfs-contract/rpcclient/nns"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
const (
|
|
verboseDesc = "Includes additional information about CNAME record."
|
|
)
|
|
|
|
func initTokensCmd() {
|
|
Cmd.AddCommand(tokensCmd)
|
|
tokensCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
|
tokensCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
|
tokensCmd.Flags().BoolP(commonflags.Verbose, commonflags.VerboseShorthand, false, verboseDesc)
|
|
}
|
|
|
|
func listTokens(cmd *cobra.Command, _ []string) {
|
|
c, _, _ := getRPCClient(cmd)
|
|
it, err := c.Tokens()
|
|
commonCmd.ExitOnErr(cmd, "unable to get tokens: %w", err)
|
|
for toks, err := it.Next(10); err == nil && len(toks) > 0; toks, err = it.Next(10) {
|
|
for _, token := range toks {
|
|
output := string(token)
|
|
if longFlag, err := cmd.Flags().GetBool(commonflags.Verbose); err == nil && longFlag {
|
|
if cname := getCnameRecord(c, token); cname != "" {
|
|
output += " ( CNAME: " + cname + " )"
|
|
}
|
|
}
|
|
cmd.Println(output)
|
|
}
|
|
}
|
|
}
|
|
|
|
func getCnameRecord(c *client.Contract, token []byte) string {
|
|
items, err := c.GetRecords(string(token), big.NewInt(int64(nns.CNAME)))
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
for _, item := range items {
|
|
record, err := item.TryBytes()
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
return string(record)
|
|
}
|
|
|
|
return ""
|
|
}
|