From 218bd72f9abbab228f72896b4fb8cbedf944a709 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 1 Feb 2024 16:11:17 +0300 Subject: [PATCH] [#932] adm: Move command `frostfsid` to package `frostfsid` Signed-off-by: Anton Nikiforov --- .../morph/{ => frostfsid}/frostfsid.go | 31 ++++++++++--------- .../morph/{ => frostfsid}/frostfsid_util.go | 4 +-- .../{ => frostfsid}/frostfsid_util_test.go | 8 ++--- .../internal/modules/morph/frostfsid/root.go | 15 +++++++++ .../modules/morph/initialize_deploy.go | 5 ++- .../internal/modules/morph/root.go | 14 ++------- 6 files changed, 41 insertions(+), 36 deletions(-) rename cmd/frostfs-adm/internal/modules/morph/{ => frostfsid}/frostfsid.go (96%) rename cmd/frostfs-adm/internal/modules/morph/{ => frostfsid}/frostfsid_util.go (96%) rename cmd/frostfs-adm/internal/modules/morph/{ => frostfsid}/frostfsid_util_test.go (96%) create mode 100644 cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go diff --git a/cmd/frostfs-adm/internal/modules/morph/frostfsid.go b/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid.go similarity index 96% rename from cmd/frostfs-adm/internal/modules/morph/frostfsid.go rename to cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid.go index 3e39c3019..76bbc7148 100644 --- a/cmd/frostfs-adm/internal/modules/morph/frostfsid.go +++ b/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid.go @@ -1,4 +1,4 @@ -package morph +package frostfsid import ( "errors" @@ -27,12 +27,13 @@ const ( includeNamesFlag = "include-names" groupNameFlag = "group-name" groupIDFlag = "group-id" + + frostfsIDAdminConfigKey = "frostfsid.admin" + rootNamespacePlaceholder = "" ) -const rootNamespacePlaceholder = "" - var ( - frostfsidCmd = &cobra.Command{ + Cmd = &cobra.Command{ Use: "frostfsid", Short: "Section for frostfsid interactions commands", } @@ -149,20 +150,20 @@ var ( ) func initFrostfsIDCreateNamespaceCmd() { - frostfsidCmd.AddCommand(frostfsidCreateNamespaceCmd) + Cmd.AddCommand(frostfsidCreateNamespaceCmd) frostfsidCreateNamespaceCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidCreateNamespaceCmd.Flags().String(namespaceFlag, "", "Namespace name to create") frostfsidCreateNamespaceCmd.Flags().String(morphUtil.AlphabetWalletsFlag, "", morphUtil.AlphabetWalletsFlagDesc) } func initFrostfsIDListNamespacesCmd() { - frostfsidCmd.AddCommand(frostfsidListNamespacesCmd) + Cmd.AddCommand(frostfsidListNamespacesCmd) frostfsidListNamespacesCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidListNamespacesCmd.Flags().String(morphUtil.AlphabetWalletsFlag, "", morphUtil.AlphabetWalletsFlagDesc) } func initFrostfsIDCreateSubjectCmd() { - frostfsidCmd.AddCommand(frostfsidCreateSubjectCmd) + Cmd.AddCommand(frostfsidCreateSubjectCmd) frostfsidCreateSubjectCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidCreateSubjectCmd.Flags().String(namespaceFlag, "", "Namespace where create subject") frostfsidCreateSubjectCmd.Flags().String(subjectNameFlag, "", "Subject name, must be unique in namespace") @@ -171,14 +172,14 @@ func initFrostfsIDCreateSubjectCmd() { } func initFrostfsIDDeleteSubjectCmd() { - frostfsidCmd.AddCommand(frostfsidDeleteSubjectCmd) + Cmd.AddCommand(frostfsidDeleteSubjectCmd) frostfsidDeleteSubjectCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidDeleteSubjectCmd.Flags().String(subjectAddressFlag, "", "Subject address") frostfsidDeleteSubjectCmd.Flags().String(morphUtil.AlphabetWalletsFlag, "", morphUtil.AlphabetWalletsFlagDesc) } func initFrostfsIDListSubjectsCmd() { - frostfsidCmd.AddCommand(frostfsidListSubjectsCmd) + Cmd.AddCommand(frostfsidListSubjectsCmd) frostfsidListSubjectsCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidListSubjectsCmd.Flags().String(namespaceFlag, "", "Namespace to list subjects") frostfsidListSubjectsCmd.Flags().Bool(includeNamesFlag, false, "Whether include subject name (require additional requests)") @@ -186,7 +187,7 @@ func initFrostfsIDListSubjectsCmd() { } func initFrostfsIDCreateGroupCmd() { - frostfsidCmd.AddCommand(frostfsidCreateGroupCmd) + Cmd.AddCommand(frostfsidCreateGroupCmd) frostfsidCreateGroupCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidCreateGroupCmd.Flags().String(namespaceFlag, "", "Namespace where create group") frostfsidCreateGroupCmd.Flags().String(groupNameFlag, "", "Group name, must be unique in namespace") @@ -194,7 +195,7 @@ func initFrostfsIDCreateGroupCmd() { } func initFrostfsIDDeleteGroupCmd() { - frostfsidCmd.AddCommand(frostfsidDeleteGroupCmd) + Cmd.AddCommand(frostfsidDeleteGroupCmd) frostfsidDeleteGroupCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidDeleteGroupCmd.Flags().String(namespaceFlag, "", "Namespace to delete group") frostfsidDeleteGroupCmd.Flags().Int64(groupIDFlag, 0, "Group id") @@ -202,14 +203,14 @@ func initFrostfsIDDeleteGroupCmd() { } func initFrostfsIDListGroupsCmd() { - frostfsidCmd.AddCommand(frostfsidListGroupsCmd) + Cmd.AddCommand(frostfsidListGroupsCmd) frostfsidListGroupsCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidListGroupsCmd.Flags().String(namespaceFlag, "", "Namespace to list groups") frostfsidListGroupsCmd.Flags().String(morphUtil.AlphabetWalletsFlag, "", morphUtil.AlphabetWalletsFlagDesc) } func initFrostfsIDAddSubjectToGroupCmd() { - frostfsidCmd.AddCommand(frostfsidAddSubjectToGroupCmd) + Cmd.AddCommand(frostfsidAddSubjectToGroupCmd) frostfsidAddSubjectToGroupCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidAddSubjectToGroupCmd.Flags().String(subjectAddressFlag, "", "Subject address") frostfsidAddSubjectToGroupCmd.Flags().Int64(groupIDFlag, 0, "Group id") @@ -217,7 +218,7 @@ func initFrostfsIDAddSubjectToGroupCmd() { } func initFrostfsIDRemoveSubjectFromGroupCmd() { - frostfsidCmd.AddCommand(frostfsidRemoveSubjectFromGroupCmd) + Cmd.AddCommand(frostfsidRemoveSubjectFromGroupCmd) frostfsidRemoveSubjectFromGroupCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidRemoveSubjectFromGroupCmd.Flags().String(subjectAddressFlag, "", "Subject address") frostfsidRemoveSubjectFromGroupCmd.Flags().Int64(groupIDFlag, 0, "Group id") @@ -225,7 +226,7 @@ func initFrostfsIDRemoveSubjectFromGroupCmd() { } func initFrostfsIDListGroupSubjectsCmd() { - frostfsidCmd.AddCommand(frostfsidListGroupSubjectsCmd) + Cmd.AddCommand(frostfsidListGroupSubjectsCmd) frostfsidListGroupSubjectsCmd.Flags().StringP(morphUtil.EndpointFlag, morphUtil.EndpointFlagShort, "", morphUtil.EndpointFlagDesc) frostfsidListGroupSubjectsCmd.Flags().String(namespaceFlag, "", "Namespace name") frostfsidListGroupSubjectsCmd.Flags().Int64(groupIDFlag, 0, "Group id") diff --git a/cmd/frostfs-adm/internal/modules/morph/frostfsid_util.go b/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid_util.go similarity index 96% rename from cmd/frostfs-adm/internal/modules/morph/frostfsid_util.go rename to cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid_util.go index 6b6bdffa9..99c04f57d 100644 --- a/cmd/frostfs-adm/internal/modules/morph/frostfsid_util.go +++ b/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid_util.go @@ -1,4 +1,4 @@ -package morph +package frostfsid import ( "errors" @@ -13,7 +13,7 @@ import ( "github.com/spf13/viper" ) -func getFrostfsIDAdmin(v *viper.Viper) (util.Uint160, bool, error) { +func GetFrostfsIDAdmin(v *viper.Viper) (util.Uint160, bool, error) { admin := v.GetString(frostfsIDAdminConfigKey) if admin == "" { return util.Uint160{}, false, nil diff --git a/cmd/frostfs-adm/internal/modules/morph/frostfsid_util_test.go b/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid_util_test.go similarity index 96% rename from cmd/frostfs-adm/internal/modules/morph/frostfsid_util_test.go rename to cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid_util_test.go index 79a0845f9..119e10d15 100644 --- a/cmd/frostfs-adm/internal/modules/morph/frostfsid_util_test.go +++ b/cmd/frostfs-adm/internal/modules/morph/frostfsid/frostfsid_util_test.go @@ -1,4 +1,4 @@ -package morph +package frostfsid import ( "encoding/hex" @@ -30,7 +30,7 @@ func TestFrostfsIDConfig(t *testing.T) { v := viper.New() v.Set("frostfsid.admin", fmts[i]) - actual, found, err := getFrostfsIDAdmin(v) + actual, found, err := GetFrostfsIDAdmin(v) require.NoError(t, err) require.True(t, found) require.Equal(t, pks[i].GetScriptHash(), actual) @@ -40,14 +40,14 @@ func TestFrostfsIDConfig(t *testing.T) { v := viper.New() v.Set("frostfsid.admin", "abc") - _, found, err := getFrostfsIDAdmin(v) + _, found, err := GetFrostfsIDAdmin(v) require.Error(t, err) require.True(t, found) }) t.Run("missing key", func(t *testing.T) { v := viper.New() - _, found, err := getFrostfsIDAdmin(v) + _, found, err := GetFrostfsIDAdmin(v) require.NoError(t, err) require.False(t, found) }) diff --git a/cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go b/cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go new file mode 100644 index 000000000..850474794 --- /dev/null +++ b/cmd/frostfs-adm/internal/modules/morph/frostfsid/root.go @@ -0,0 +1,15 @@ +package frostfsid + +func init() { + initFrostfsIDCreateNamespaceCmd() + initFrostfsIDListNamespacesCmd() + initFrostfsIDCreateSubjectCmd() + initFrostfsIDDeleteSubjectCmd() + initFrostfsIDListSubjectsCmd() + initFrostfsIDCreateGroupCmd() + initFrostfsIDDeleteGroupCmd() + initFrostfsIDListGroupsCmd() + initFrostfsIDAddSubjectToGroupCmd() + initFrostfsIDRemoveSubjectFromGroupCmd() + initFrostfsIDListGroupSubjectsCmd() +} diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go b/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go index 322033abc..5cd7b3ba0 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go @@ -8,6 +8,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-contract/common" "git.frostfs.info/TrueCloudLab/frostfs-contract/nns" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/frostfsid" morphUtil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap" @@ -27,8 +28,6 @@ import ( "github.com/spf13/viper" ) -const frostfsIDAdminConfigKey = "frostfsid.admin" - var netmapConfigKeys = []string{ netmap.EpochDurationConfig, netmap.MaxObjectSizeConfig, @@ -361,7 +360,7 @@ func getContractDeployData(c *morphUtil.InitializeContext, ctrName string, keysP h, found, err = getFrostfsIDAdminFromContract(c.ReadOnlyInvoker) } if method != updateMethodName || err == nil && !found { - h, found, err = getFrostfsIDAdmin(viper.GetViper()) + h, found, err = frostfsid.GetFrostfsIDAdmin(viper.GetViper()) } if err != nil { return nil, err diff --git a/cmd/frostfs-adm/internal/modules/morph/root.go b/cmd/frostfs-adm/internal/modules/morph/root.go index b53a64486..0d6f48d98 100644 --- a/cmd/frostfs-adm/internal/modules/morph/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/root.go @@ -2,6 +2,7 @@ package morph import ( "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/ape" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/frostfsid" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/policy" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" "github.com/spf13/cobra" @@ -262,18 +263,7 @@ func init() { initProxyAddAccount() initProxyRemoveAccount() - RootCmd.AddCommand(frostfsidCmd) - initFrostfsIDCreateNamespaceCmd() - initFrostfsIDListNamespacesCmd() - initFrostfsIDCreateSubjectCmd() - initFrostfsIDDeleteSubjectCmd() - initFrostfsIDListSubjectsCmd() - initFrostfsIDCreateGroupCmd() - initFrostfsIDDeleteGroupCmd() - initFrostfsIDListGroupsCmd() - initFrostfsIDAddSubjectToGroupCmd() - initFrostfsIDRemoveSubjectFromGroupCmd() - initFrostfsIDListGroupSubjectsCmd() + RootCmd.AddCommand(frostfsid.Cmd) } func initProxyAddAccount() {