2024-02-01 13:11:17 +00:00
|
|
|
package frostfsid
|
2024-01-12 10:54:00 +00:00
|
|
|
|
|
|
|
import (
|
2024-01-15 08:48:44 +00:00
|
|
|
"errors"
|
2024-01-12 10:54:00 +00:00
|
|
|
"fmt"
|
2024-07-03 09:03:53 +00:00
|
|
|
"math/big"
|
2024-01-12 10:54:00 +00:00
|
|
|
"sort"
|
|
|
|
|
|
|
|
frostfsidclient "git.frostfs.info/TrueCloudLab/frostfs-contract/frostfsid/client"
|
2024-07-03 09:03:53 +00:00
|
|
|
frostfsidrpclient "git.frostfs.info/TrueCloudLab/frostfs-contract/rpcclient/frostfsid"
|
2024-02-02 12:04:48 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
2024-02-02 12:26:57 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
2024-02-02 12:36:14 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
2024-01-12 10:54:00 +00:00
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2024-07-03 09:03:53 +00:00
|
|
|
"github.com/google/uuid"
|
2024-01-15 08:48:44 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2024-01-12 10:54:00 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2024-07-03 09:03:53 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
2024-01-12 10:54:00 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
2024-01-15 08:48:44 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2024-01-12 10:54:00 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
2024-07-03 09:03:53 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2024-01-12 10:54:00 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2024-07-03 09:03:53 +00:00
|
|
|
const iteratorBatchSize = 1
|
|
|
|
|
2024-01-12 10:54:00 +00:00
|
|
|
const (
|
2024-01-12 15:03:18 +00:00
|
|
|
namespaceFlag = "namespace"
|
|
|
|
subjectNameFlag = "subject-name"
|
|
|
|
subjectKeyFlag = "subject-key"
|
|
|
|
subjectAddressFlag = "subject-address"
|
|
|
|
includeNamesFlag = "include-names"
|
|
|
|
groupNameFlag = "group-name"
|
|
|
|
groupIDFlag = "group-id"
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-02-01 13:11:17 +00:00
|
|
|
rootNamespacePlaceholder = "<root>"
|
|
|
|
)
|
2024-01-17 08:35:09 +00:00
|
|
|
|
2024-01-12 10:54:00 +00:00
|
|
|
var (
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd = &cobra.Command{
|
2024-01-12 10:54:00 +00:00
|
|
|
Use: "frostfsid",
|
|
|
|
Short: "Section for frostfsid interactions commands",
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidCreateNamespaceCmd = &cobra.Command{
|
|
|
|
Use: "create-namespace",
|
|
|
|
Short: "Create new namespace in frostfsid contract",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 10:54:00 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidCreateNamespace,
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidListNamespacesCmd = &cobra.Command{
|
|
|
|
Use: "list-namespaces",
|
|
|
|
Short: "List all namespaces in frostfsid",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 10:54:00 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidListNamespaces,
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidCreateSubjectCmd = &cobra.Command{
|
|
|
|
Use: "create-subject",
|
|
|
|
Short: "Create subject in frostfsid contract",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 10:54:00 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidCreateSubject,
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidDeleteSubjectCmd = &cobra.Command{
|
|
|
|
Use: "delete-subject",
|
|
|
|
Short: "Delete subject from frostfsid contract",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 10:54:00 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidDeleteSubject,
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidListSubjectsCmd = &cobra.Command{
|
|
|
|
Use: "list-subjects",
|
|
|
|
Short: "List subjects in namespace",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 10:54:00 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidListSubjects,
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidCreateGroupCmd = &cobra.Command{
|
|
|
|
Use: "create-group",
|
|
|
|
Short: "Create group in frostfsid contract",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 10:54:00 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidCreateGroup,
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidDeleteGroupCmd = &cobra.Command{
|
|
|
|
Use: "delete-group",
|
|
|
|
Short: "Delete group from frostfsid contract",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 10:54:00 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidDeleteGroup,
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidListGroupsCmd = &cobra.Command{
|
|
|
|
Use: "list-groups",
|
|
|
|
Short: "List groups in namespace",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 10:54:00 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidListGroups,
|
|
|
|
}
|
2024-01-12 15:03:18 +00:00
|
|
|
|
|
|
|
frostfsidAddSubjectToGroupCmd = &cobra.Command{
|
|
|
|
Use: "add-subject-to-group",
|
|
|
|
Short: "Add subject to group",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 15:03:18 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidAddSubjectToGroup,
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidRemoveSubjectFromGroupCmd = &cobra.Command{
|
|
|
|
Use: "remove-subject-from-group",
|
|
|
|
Short: "Remove subject from group",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.AlphabetWalletsFlag, cmd.Flags().Lookup(commonflags.AlphabetWalletsFlag))
|
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 15:03:18 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidRemoveSubjectFromGroup,
|
|
|
|
}
|
|
|
|
|
|
|
|
frostfsidListGroupSubjectsCmd = &cobra.Command{
|
|
|
|
Use: "list-group-subjects",
|
|
|
|
Short: "List subjects in group",
|
|
|
|
PreRun: func(cmd *cobra.Command, _ []string) {
|
2024-02-02 12:04:48 +00:00
|
|
|
_ = viper.BindPFlag(commonflags.EndpointFlag, cmd.Flags().Lookup(commonflags.EndpointFlag))
|
2024-01-12 15:03:18 +00:00
|
|
|
},
|
|
|
|
Run: frostfsidListGroupSubjects,
|
|
|
|
}
|
2024-01-12 10:54:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func initFrostfsIDCreateNamespaceCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidCreateNamespaceCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidCreateNamespaceCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
frostfsidCreateNamespaceCmd.Flags().String(namespaceFlag, "", "Namespace name to create")
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidCreateNamespaceCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
2024-03-05 13:01:49 +00:00
|
|
|
_ = frostfsidCreateNamespaceCmd.MarkFlagRequired(namespaceFlag)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initFrostfsIDListNamespacesCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidListNamespacesCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidListNamespacesCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initFrostfsIDCreateSubjectCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidCreateSubjectCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidCreateSubjectCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
frostfsidCreateSubjectCmd.Flags().String(namespaceFlag, "", "Namespace where create subject")
|
|
|
|
frostfsidCreateSubjectCmd.Flags().String(subjectNameFlag, "", "Subject name, must be unique in namespace")
|
|
|
|
frostfsidCreateSubjectCmd.Flags().String(subjectKeyFlag, "", "Subject hex-encoded public key")
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidCreateSubjectCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initFrostfsIDDeleteSubjectCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidDeleteSubjectCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidDeleteSubjectCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
frostfsidDeleteSubjectCmd.Flags().String(subjectAddressFlag, "", "Subject address")
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidDeleteSubjectCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initFrostfsIDListSubjectsCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidListSubjectsCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidListSubjectsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
frostfsidListSubjectsCmd.Flags().String(namespaceFlag, "", "Namespace to list subjects")
|
|
|
|
frostfsidListSubjectsCmd.Flags().Bool(includeNamesFlag, false, "Whether include subject name (require additional requests)")
|
|
|
|
}
|
|
|
|
|
|
|
|
func initFrostfsIDCreateGroupCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidCreateGroupCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidCreateGroupCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
frostfsidCreateGroupCmd.Flags().String(namespaceFlag, "", "Namespace where create group")
|
|
|
|
frostfsidCreateGroupCmd.Flags().String(groupNameFlag, "", "Group name, must be unique in namespace")
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidCreateGroupCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
2024-06-03 10:54:59 +00:00
|
|
|
_ = frostfsidCreateGroupCmd.MarkFlagRequired(groupNameFlag)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initFrostfsIDDeleteGroupCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidDeleteGroupCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidDeleteGroupCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
frostfsidDeleteGroupCmd.Flags().String(namespaceFlag, "", "Namespace to delete group")
|
|
|
|
frostfsidDeleteGroupCmd.Flags().Int64(groupIDFlag, 0, "Group id")
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidDeleteGroupCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initFrostfsIDListGroupsCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidListGroupsCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidListGroupsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 10:54:00 +00:00
|
|
|
frostfsidListGroupsCmd.Flags().String(namespaceFlag, "", "Namespace to list groups")
|
|
|
|
}
|
|
|
|
|
2024-01-12 15:03:18 +00:00
|
|
|
func initFrostfsIDAddSubjectToGroupCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidAddSubjectToGroupCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidAddSubjectToGroupCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 15:03:18 +00:00
|
|
|
frostfsidAddSubjectToGroupCmd.Flags().String(subjectAddressFlag, "", "Subject address")
|
|
|
|
frostfsidAddSubjectToGroupCmd.Flags().Int64(groupIDFlag, 0, "Group id")
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidAddSubjectToGroupCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
2024-01-12 15:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initFrostfsIDRemoveSubjectFromGroupCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidRemoveSubjectFromGroupCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidRemoveSubjectFromGroupCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 15:03:18 +00:00
|
|
|
frostfsidRemoveSubjectFromGroupCmd.Flags().String(subjectAddressFlag, "", "Subject address")
|
|
|
|
frostfsidRemoveSubjectFromGroupCmd.Flags().Int64(groupIDFlag, 0, "Group id")
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidRemoveSubjectFromGroupCmd.Flags().String(commonflags.AlphabetWalletsFlag, "", commonflags.AlphabetWalletsFlagDesc)
|
2024-01-12 15:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initFrostfsIDListGroupSubjectsCmd() {
|
2024-02-01 13:11:17 +00:00
|
|
|
Cmd.AddCommand(frostfsidListGroupSubjectsCmd)
|
2024-02-02 12:04:48 +00:00
|
|
|
frostfsidListGroupSubjectsCmd.Flags().StringP(commonflags.EndpointFlag, commonflags.EndpointFlagShort, "", commonflags.EndpointFlagDesc)
|
2024-01-12 15:03:18 +00:00
|
|
|
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)")
|
|
|
|
}
|
|
|
|
|
2024-01-12 10:54:00 +00:00
|
|
|
func frostfsidCreateNamespace(cmd *cobra.Command, _ []string) {
|
2024-01-17 08:35:09 +00:00
|
|
|
ns := getFrostfsIDNamespace(cmd)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid, err := newFrostfsIDClient(cmd)
|
|
|
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
|
|
|
|
|
|
|
ffsid.addCall(ffsid.roCli.CreateNamespaceCall(ns))
|
|
|
|
|
|
|
|
err = ffsid.sendWait()
|
|
|
|
commonCmd.ExitOnErr(cmd, "create namespace error: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func frostfsidListNamespaces(cmd *cobra.Command, _ []string) {
|
2024-07-03 09:03:53 +00:00
|
|
|
inv, _, hash := initInvoker(cmd)
|
|
|
|
reader := frostfsidrpclient.NewReader(inv, hash)
|
|
|
|
sessionID, it, err := reader.ListNamespaces()
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't get namespace: %w", err)
|
|
|
|
items, err := readIterator(inv, &it, iteratorBatchSize, sessionID)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't read iterator: %w", err)
|
|
|
|
|
|
|
|
namespaces, err := frostfsidclient.ParseNamespaces(items)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't parse namespace: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
sort.Slice(namespaces, func(i, j int) bool { return namespaces[i].Name < namespaces[j].Name })
|
|
|
|
|
|
|
|
for _, namespace := range namespaces {
|
2024-01-17 08:35:09 +00:00
|
|
|
if namespace.Name == "" {
|
|
|
|
namespace.Name = rootNamespacePlaceholder
|
|
|
|
}
|
|
|
|
cmd.Printf("%s\n", namespace.Name)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func frostfsidCreateSubject(cmd *cobra.Command, _ []string) {
|
2024-01-17 08:35:09 +00:00
|
|
|
ns := getFrostfsIDNamespace(cmd)
|
|
|
|
subjName := getFrostfsIDSubjectName(cmd)
|
2024-01-12 10:54:00 +00:00
|
|
|
subjKey := getFrostfsIDSubjectKey(cmd)
|
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid, err := newFrostfsIDClient(cmd)
|
|
|
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid.addCall(ffsid.roCli.CreateSubjectCall(ns, subjKey))
|
2024-01-12 10:54:00 +00:00
|
|
|
if subjName != "" {
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid.addCall(ffsid.roCli.SetSubjectNameCall(subjKey.GetScriptHash(), subjName))
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
err = ffsid.sendWait()
|
|
|
|
commonCmd.ExitOnErr(cmd, "create subject: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func frostfsidDeleteSubject(cmd *cobra.Command, _ []string) {
|
|
|
|
subjectAddress := getFrostfsIDSubjectAddress(cmd)
|
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid, err := newFrostfsIDClient(cmd)
|
|
|
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
|
|
|
|
|
|
|
ffsid.addCall(ffsid.roCli.DeleteSubjectCall(subjectAddress))
|
|
|
|
|
|
|
|
err = ffsid.sendWait()
|
2024-01-12 10:54:00 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "delete subject error: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func frostfsidListSubjects(cmd *cobra.Command, _ []string) {
|
|
|
|
includeNames, _ := cmd.Flags().GetBool(includeNamesFlag)
|
2024-07-03 09:03:53 +00:00
|
|
|
ns := getFrostfsIDNamespace(cmd)
|
|
|
|
inv, _, hash := initInvoker(cmd)
|
|
|
|
reader := frostfsidrpclient.NewReader(inv, hash)
|
|
|
|
sessionID, it, err := reader.ListNamespaceSubjects(ns)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't get namespace: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-07-03 09:03:53 +00:00
|
|
|
subAddresses, err := frostfsidclient.UnwrapArrayOfUint160(readIterator(inv, &it, iteratorBatchSize, sessionID))
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't unwrap: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
|
|
|
sort.Slice(subAddresses, func(i, j int) bool { return subAddresses[i].Less(subAddresses[j]) })
|
|
|
|
|
|
|
|
for _, addr := range subAddresses {
|
|
|
|
if !includeNames {
|
|
|
|
cmd.Println(address.Uint160ToString(addr))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-07-03 09:03:53 +00:00
|
|
|
sessionID, it, err := reader.ListSubjects()
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't get subject: %w", err)
|
|
|
|
|
|
|
|
items, err := readIterator(inv, &it, iteratorBatchSize, sessionID)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't read iterator: %w", err)
|
|
|
|
|
|
|
|
subj, err := frostfsidclient.ParseSubject(items)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't parse subject: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
|
|
|
cmd.Printf("%s (%s)\n", address.Uint160ToString(addr), subj.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func frostfsidCreateGroup(cmd *cobra.Command, _ []string) {
|
2024-01-17 08:35:09 +00:00
|
|
|
ns := getFrostfsIDNamespace(cmd)
|
|
|
|
groupName := getFrostfsIDGroupName(cmd)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid, err := newFrostfsIDClient(cmd)
|
2024-01-12 10:54:00 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid.addCall(ffsid.roCli.CreateGroupCall(ns, groupName))
|
|
|
|
|
|
|
|
groupID, err := ffsid.roCli.ParseGroupID(ffsid.sendWaitRes())
|
2024-01-12 10:54:00 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "create group: %w", err)
|
|
|
|
|
|
|
|
cmd.Printf("group '%s' created with id: %d\n", groupName, groupID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func frostfsidDeleteGroup(cmd *cobra.Command, _ []string) {
|
2024-01-17 08:35:09 +00:00
|
|
|
ns := getFrostfsIDNamespace(cmd)
|
|
|
|
groupID := getFrostfsIDGroupID(cmd)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid, err := newFrostfsIDClient(cmd)
|
2024-01-12 10:54:00 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid.addCall(ffsid.roCli.DeleteGroupCall(ns, groupID))
|
|
|
|
|
|
|
|
err = ffsid.sendWait()
|
2024-01-12 10:54:00 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "delete group error: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func frostfsidListGroups(cmd *cobra.Command, _ []string) {
|
2024-07-03 09:03:53 +00:00
|
|
|
inv, _, hash := initInvoker(cmd)
|
2024-01-17 08:35:09 +00:00
|
|
|
ns := getFrostfsIDNamespace(cmd)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-07-03 09:03:53 +00:00
|
|
|
reader := frostfsidrpclient.NewReader(inv, hash)
|
|
|
|
sessionID, it, err := reader.ListGroups(ns)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't get namespace: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-07-03 09:03:53 +00:00
|
|
|
items, err := readIterator(inv, &it, iteratorBatchSize, sessionID)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't list groups: %w", err)
|
|
|
|
groups, err := frostfsidclient.ParseGroups(items)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't parse groups: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
|
|
|
|
sort.Slice(groups, func(i, j int) bool { return groups[i].Name < groups[j].Name })
|
|
|
|
|
|
|
|
for _, group := range groups {
|
2024-01-17 08:35:09 +00:00
|
|
|
cmd.Printf("%s (%d)\n", group.Name, group.ID)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-12 15:03:18 +00:00
|
|
|
func frostfsidAddSubjectToGroup(cmd *cobra.Command, _ []string) {
|
|
|
|
subjectAddress := getFrostfsIDSubjectAddress(cmd)
|
2024-01-17 08:35:09 +00:00
|
|
|
groupID := getFrostfsIDGroupID(cmd)
|
2024-01-12 15:03:18 +00:00
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid, err := newFrostfsIDClient(cmd)
|
|
|
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
|
|
|
|
|
|
|
ffsid.addCall(ffsid.roCli.AddSubjectToGroupCall(subjectAddress, groupID))
|
|
|
|
|
|
|
|
err = ffsid.sendWait()
|
|
|
|
commonCmd.ExitOnErr(cmd, "add subject to group error: %w", err)
|
2024-01-12 15:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func frostfsidRemoveSubjectFromGroup(cmd *cobra.Command, _ []string) {
|
|
|
|
subjectAddress := getFrostfsIDSubjectAddress(cmd)
|
2024-01-17 08:35:09 +00:00
|
|
|
groupID := getFrostfsIDGroupID(cmd)
|
2024-01-12 15:03:18 +00:00
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
ffsid, err := newFrostfsIDClient(cmd)
|
|
|
|
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
|
|
|
|
|
|
|
|
ffsid.addCall(ffsid.roCli.RemoveSubjectFromGroupCall(subjectAddress, groupID))
|
|
|
|
|
|
|
|
err = ffsid.sendWait()
|
|
|
|
commonCmd.ExitOnErr(cmd, "remove subject from group error: %w", err)
|
2024-01-12 15:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func frostfsidListGroupSubjects(cmd *cobra.Command, _ []string) {
|
2024-01-17 08:35:09 +00:00
|
|
|
ns := getFrostfsIDNamespace(cmd)
|
|
|
|
groupID := getFrostfsIDGroupID(cmd)
|
2024-01-12 15:03:18 +00:00
|
|
|
includeNames, _ := cmd.Flags().GetBool(includeNamesFlag)
|
2024-07-03 09:03:53 +00:00
|
|
|
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)
|
2024-01-12 15:03:18 +00:00
|
|
|
|
2024-07-03 09:03:53 +00:00
|
|
|
reader := frostfsidrpclient.NewReader(inv, hash)
|
|
|
|
sessionID, it, err := reader.ListGroupSubjects(ns, big.NewInt(groupID))
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't list groups: %w", err)
|
|
|
|
|
|
|
|
items, err := readIterator(inv, &it, iteratorBatchSize, sessionID)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't read iterator: %w", err)
|
2024-01-12 15:03:18 +00:00
|
|
|
|
2024-07-03 09:03:53 +00:00
|
|
|
subjects, err := frostfsidclient.UnwrapArrayOfUint160(items, err)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't unwrap: %w", err)
|
2024-01-12 15:03:18 +00:00
|
|
|
|
|
|
|
sort.Slice(subjects, func(i, j int) bool { return subjects[i].Less(subjects[j]) })
|
|
|
|
|
|
|
|
for _, subjAddr := range subjects {
|
|
|
|
if !includeNames {
|
|
|
|
cmd.Println(address.Uint160ToString(subjAddr))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-07-03 09:03:53 +00:00
|
|
|
items, err := reader.GetSubject(subjAddr)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't get subject: %w", err)
|
|
|
|
subj, err := frostfsidclient.ParseSubject(items)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't parse subject: %w", err)
|
2024-01-12 15:03:18 +00:00
|
|
|
cmd.Printf("%s (%s)\n", address.Uint160ToString(subjAddr), subj.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
type frostfsidClient struct {
|
|
|
|
bw *io.BufBinWriter
|
|
|
|
contractHash util.Uint160
|
|
|
|
roCli *frostfsidclient.Client // client can be used only for waiting tx, parsing and forming method params
|
2024-02-02 12:36:14 +00:00
|
|
|
wCtx *helper.InitializeContext
|
2024-01-15 08:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newFrostfsIDClient(cmd *cobra.Command) (*frostfsidClient, error) {
|
2024-02-02 12:36:14 +00:00
|
|
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
2024-01-12 10:54:00 +00:00
|
|
|
if err != nil {
|
2024-07-01 15:58:37 +00:00
|
|
|
return nil, fmt.Errorf("can't initialize context: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
2024-06-28 13:35:18 +00:00
|
|
|
cs, err := helper.GetContractByID(r, 1)
|
2024-01-12 10:54:00 +00:00
|
|
|
if err != nil {
|
2024-01-15 08:48:44 +00:00
|
|
|
return nil, fmt.Errorf("can't get NNS contract info: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
ffsidHash, err := helper.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, helper.DomainOf(constants.FrostfsIDContract))
|
2024-01-12 10:54:00 +00:00
|
|
|
if err != nil {
|
2024-01-15 08:48:44 +00:00
|
|
|
return nil, fmt.Errorf("can't get proxy contract hash: %w", err)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
return &frostfsidClient{
|
|
|
|
bw: io.NewBufBinWriter(),
|
|
|
|
contractHash: ffsidHash,
|
|
|
|
roCli: frostfsidclient.NewSimple(wCtx.CommitteeAct, ffsidHash),
|
|
|
|
wCtx: wCtx,
|
|
|
|
}, nil
|
|
|
|
}
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
func (f *frostfsidClient) addCall(method string, args []any) {
|
|
|
|
emit.AppCall(f.bw.BinWriter, f.contractHash, method, callflag.All, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *frostfsidClient) sendWait() error {
|
2024-02-01 11:30:59 +00:00
|
|
|
if err := f.wCtx.SendConsensusTx(f.bw.Bytes()); err != nil {
|
2024-01-12 10:54:00 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-01-15 08:48:44 +00:00
|
|
|
f.bw.Reset()
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-02-01 11:30:59 +00:00
|
|
|
return f.wCtx.AwaitTx()
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
func (f *frostfsidClient) sendWaitRes() (*state.AppExecResult, error) {
|
2024-02-01 11:30:59 +00:00
|
|
|
if err := f.wCtx.SendConsensusTx(f.bw.Bytes()); err != nil {
|
2024-01-15 08:48:44 +00:00
|
|
|
return nil, err
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
2024-01-15 08:48:44 +00:00
|
|
|
f.bw.Reset()
|
2024-01-12 10:54:00 +00:00
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
if len(f.wCtx.SentTxs) == 0 {
|
|
|
|
return nil, errors.New("no transactions to wait")
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
|
|
|
|
2024-01-15 08:48:44 +00:00
|
|
|
f.wCtx.Command.Println("Waiting for transactions to persist...")
|
2024-01-31 14:26:26 +00:00
|
|
|
return f.roCli.Wait(f.wCtx.SentTxs[0].Hash, f.wCtx.SentTxs[0].Vub, nil)
|
2024-01-12 10:54:00 +00:00
|
|
|
}
|
2024-07-03 09:03:53 +00:00
|
|
|
|
|
|
|
func readIterator(inv *invoker.Invoker, iter *result.Iterator, batchSize int, sessionID uuid.UUID) ([]stackitem.Item, error) {
|
|
|
|
var shouldStop bool
|
|
|
|
res := make([]stackitem.Item, 0)
|
|
|
|
for !shouldStop {
|
|
|
|
items, err := inv.TraverseIterator(sessionID, iter, batchSize)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res = append(res, items...)
|
|
|
|
shouldStop = len(items) < batchSize
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func initInvoker(cmd *cobra.Command) (*invoker.Invoker, *state.Contract, util.Uint160) {
|
2024-11-22 07:53:09 +00:00
|
|
|
c, err := helper.NewRemoteClient(viper.GetViper())
|
2024-07-03 09:03:53 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "can't create N3 client: %w", err)
|
|
|
|
|
|
|
|
inv := invoker.New(c, nil)
|
|
|
|
r := management.NewReader(inv)
|
|
|
|
|
|
|
|
cs, err := r.GetContractByID(1)
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err)
|
|
|
|
|
|
|
|
nmHash, err := helper.NNSResolveHash(inv, cs.Hash, helper.DomainOf(constants.FrostfsIDContract))
|
|
|
|
commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err)
|
|
|
|
|
|
|
|
return inv, cs, nmHash
|
|
|
|
}
|