forked from TrueCloudLab/frostfs-node
[#1678] adm: Fix frostfs-adm morph list-subjects & list-group-subjects
`include-names` for `list-subjects` returns error `invalid response subject struct` because `ListSubjects` returns only subject addresses (see frostfs-contract). Replace `include-names` with `extended` as now all subject info printed. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
07a660fbc4
commit
fde2649e60
1 changed files with 39 additions and 13 deletions
|
@ -34,7 +34,7 @@ const (
|
|||
subjectNameFlag = "subject-name"
|
||||
subjectKeyFlag = "subject-key"
|
||||
subjectAddressFlag = "subject-address"
|
||||
includeNamesFlag = "include-names"
|
||||
extendedFlag = "extended"
|
||||
groupNameFlag = "group-name"
|
||||
groupIDFlag = "group-id"
|
||||
|
||||
|
@ -209,7 +209,7 @@ func initFrostfsIDListSubjectsCmd() {
|
|||
Cmd.AddCommand(frostfsidListSubjectsCmd)
|
||||
frostfsidListSubjectsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||
frostfsidListSubjectsCmd.Flags().String(namespaceFlag, "", "Namespace to list subjects")
|
||||
frostfsidListSubjectsCmd.Flags().Bool(includeNamesFlag, false, "Whether include subject name (require additional requests)")
|
||||
frostfsidListSubjectsCmd.Flags().Bool(extendedFlag, false, "Whether include subject info (require additional requests)")
|
||||
}
|
||||
|
||||
func initFrostfsIDCreateGroupCmd() {
|
||||
|
@ -256,7 +256,7 @@ func initFrostfsIDListGroupSubjectsCmd() {
|
|||
frostfsidListGroupSubjectsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
||||
frostfsidListGroupSubjectsCmd.Flags().String(namespaceFlag, "", "Namespace name")
|
||||
frostfsidListGroupSubjectsCmd.Flags().Int64(groupIDFlag, 0, "Group id")
|
||||
frostfsidListGroupSubjectsCmd.Flags().Bool(includeNamesFlag, false, "Whether include subject name (require additional requests)")
|
||||
frostfsidListGroupSubjectsCmd.Flags().Bool(extendedFlag, false, "Whether include subject info (require additional requests)")
|
||||
}
|
||||
|
||||
func initFrostfsIDSetKVCmd() {
|
||||
|
@ -336,7 +336,7 @@ func frostfsidDeleteSubject(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
|
||||
func frostfsidListSubjects(cmd *cobra.Command, _ []string) {
|
||||
includeNames, _ := cmd.Flags().GetBool(includeNamesFlag)
|
||||
extended, _ := cmd.Flags().GetBool(extendedFlag)
|
||||
ns := getFrostfsIDNamespace(cmd)
|
||||
inv, _, hash := initInvoker(cmd)
|
||||
reader := frostfsidrpclient.NewReader(inv, hash)
|
||||
|
@ -349,21 +349,19 @@ func frostfsidListSubjects(cmd *cobra.Command, _ []string) {
|
|||
sort.Slice(subAddresses, func(i, j int) bool { return subAddresses[i].Less(subAddresses[j]) })
|
||||
|
||||
for _, addr := range subAddresses {
|
||||
if !includeNames {
|
||||
if !extended {
|
||||
cmd.Println(address.Uint160ToString(addr))
|
||||
continue
|
||||
}
|
||||
|
||||
sessionID, it, err := reader.ListSubjects()
|
||||
items, err := reader.GetSubject(addr)
|
||||
commonCmd.ExitOnErr(cmd, "can't get subject: %w", err)
|
||||
|
||||
items, err := readIterator(inv, &it, sessionID)
|
||||
commonCmd.ExitOnErr(cmd, "can't read iterator: %w", err)
|
||||
|
||||
subj, err := frostfsidclient.ParseSubject(items)
|
||||
commonCmd.ExitOnErr(cmd, "can't parse subject: %w", err)
|
||||
|
||||
cmd.Printf("%s (%s)\n", address.Uint160ToString(addr), subj.Name)
|
||||
printSubjectInfo(cmd, addr, subj)
|
||||
cmd.Println()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -483,7 +481,7 @@ func frostfsidDeleteKV(cmd *cobra.Command, _ []string) {
|
|||
func frostfsidListGroupSubjects(cmd *cobra.Command, _ []string) {
|
||||
ns := getFrostfsIDNamespace(cmd)
|
||||
groupID := getFrostfsIDGroupID(cmd)
|
||||
includeNames, _ := cmd.Flags().GetBool(includeNamesFlag)
|
||||
extended, _ := cmd.Flags().GetBool(extendedFlag)
|
||||
inv, cs, hash := initInvoker(cmd)
|
||||
_, err := helper.NNSResolveHash(inv, cs.Hash, helper.DomainOf(constants.FrostfsIDContract))
|
||||
commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err)
|
||||
|
@ -501,7 +499,7 @@ func frostfsidListGroupSubjects(cmd *cobra.Command, _ []string) {
|
|||
sort.Slice(subjects, func(i, j int) bool { return subjects[i].Less(subjects[j]) })
|
||||
|
||||
for _, subjAddr := range subjects {
|
||||
if !includeNames {
|
||||
if !extended {
|
||||
cmd.Println(address.Uint160ToString(subjAddr))
|
||||
continue
|
||||
}
|
||||
|
@ -510,7 +508,8 @@ func frostfsidListGroupSubjects(cmd *cobra.Command, _ []string) {
|
|||
commonCmd.ExitOnErr(cmd, "can't get subject: %w", err)
|
||||
subj, err := frostfsidclient.ParseSubject(items)
|
||||
commonCmd.ExitOnErr(cmd, "can't parse subject: %w", err)
|
||||
cmd.Printf("%s (%s)\n", address.Uint160ToString(subjAddr), subj.Name)
|
||||
printSubjectInfo(cmd, subjAddr, subj)
|
||||
cmd.Println()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -600,3 +599,30 @@ func initInvoker(cmd *cobra.Command) (*invoker.Invoker, *state.Contract, util.Ui
|
|||
|
||||
return inv, cs, nmHash
|
||||
}
|
||||
|
||||
func printSubjectInfo(cmd *cobra.Command, addr util.Uint160, subj *frostfsidclient.Subject) {
|
||||
cmd.Printf("Address: %s\n", address.Uint160ToString(addr))
|
||||
pk := "<nil>"
|
||||
if subj.PrimaryKey != nil {
|
||||
pk = subj.PrimaryKey.String()
|
||||
}
|
||||
cmd.Printf("Primary key: %s\n", pk)
|
||||
cmd.Printf("Name: %s\n", subj.Name)
|
||||
cmd.Printf("Namespace: %s\n", subj.Namespace)
|
||||
if len(subj.AdditionalKeys) > 0 {
|
||||
cmd.Printf("Additional keys:\n")
|
||||
for _, key := range subj.AdditionalKeys {
|
||||
k := "<nil>"
|
||||
if key != nil {
|
||||
k = key.String()
|
||||
}
|
||||
cmd.Printf("- %s\n", k)
|
||||
}
|
||||
}
|
||||
if len(subj.KV) > 0 {
|
||||
cmd.Printf("KV:\n")
|
||||
for k, v := range subj.KV {
|
||||
cmd.Printf("- %s: %s\n", k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue