From 63c34ea707b6aa3f0cc4ca7640a631bbac182009 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Fri, 2 Feb 2024 10:25:04 +0300 Subject: [PATCH] [#932] adm: Move command `init` to package `initialize` Signed-off-by: Anton Nikiforov --- .../morph/{ => initialize}/initialize.go | 2 +- .../{ => initialize}/initialize_deploy.go | 2 +- .../morph/{ => initialize}/initialize_nns.go | 2 +- .../{ => initialize}/initialize_register.go | 2 +- .../{ => initialize}/initialize_roles.go | 2 +- .../morph/{ => initialize}/initialize_test.go | 8 +-- .../{ => initialize}/initialize_transfer.go | 2 +- .../internal/modules/morph/initialize/root.go | 55 +++++++++++++++ .../internal/modules/morph/root.go | 67 ++----------------- 9 files changed, 72 insertions(+), 70 deletions(-) rename cmd/frostfs-adm/internal/modules/morph/{ => initialize}/initialize.go (98%) rename cmd/frostfs-adm/internal/modules/morph/{ => initialize}/initialize_deploy.go (99%) rename cmd/frostfs-adm/internal/modules/morph/{ => initialize}/initialize_nns.go (99%) rename cmd/frostfs-adm/internal/modules/morph/{ => initialize}/initialize_register.go (99%) rename cmd/frostfs-adm/internal/modules/morph/{ => initialize}/initialize_roles.go (98%) rename cmd/frostfs-adm/internal/modules/morph/{ => initialize}/initialize_test.go (96%) rename cmd/frostfs-adm/internal/modules/morph/{ => initialize}/initialize_transfer.go (99%) create mode 100644 cmd/frostfs-adm/internal/modules/morph/initialize/root.go diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize.go b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize.go similarity index 98% rename from cmd/frostfs-adm/internal/modules/morph/initialize.go rename to cmd/frostfs-adm/internal/modules/morph/initialize/initialize.go index 30f7248cd..d1b766019 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize.go @@ -1,4 +1,4 @@ -package morph +package initialize import ( "fmt" diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_deploy.go similarity index 99% rename from cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go rename to cmd/frostfs-adm/internal/modules/morph/initialize/initialize_deploy.go index 4d5487419..9374b9f7f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_deploy.go @@ -1,4 +1,4 @@ -package morph +package initialize import ( "fmt" diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_nns.go similarity index 99% rename from cmd/frostfs-adm/internal/modules/morph/initialize_nns.go rename to cmd/frostfs-adm/internal/modules/morph/initialize/initialize_nns.go index f943ac4a1..a9df7127f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_nns.go @@ -1,4 +1,4 @@ -package morph +package initialize import ( "encoding/hex" diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_register.go b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_register.go similarity index 99% rename from cmd/frostfs-adm/internal/modules/morph/initialize_register.go rename to cmd/frostfs-adm/internal/modules/morph/initialize/initialize_register.go index d6cbd2d56..cb33aa985 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_register.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_register.go @@ -1,4 +1,4 @@ -package morph +package initialize import ( "errors" diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_roles.go b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_roles.go similarity index 98% rename from cmd/frostfs-adm/internal/modules/morph/initialize_roles.go rename to cmd/frostfs-adm/internal/modules/morph/initialize/initialize_roles.go index 9e885d5f8..d7f17ccfb 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_roles.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_roles.go @@ -1,4 +1,4 @@ -package morph +package initialize import ( "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_test.go b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_test.go similarity index 96% rename from cmd/frostfs-adm/internal/modules/morph/initialize_test.go rename to cmd/frostfs-adm/internal/modules/morph/initialize/initialize_test.go index 3315b5d33..d6b180609 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_test.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_test.go @@ -1,4 +1,4 @@ -package morph +package initialize import ( "encoding/hex" @@ -63,16 +63,16 @@ func testInitialize(t *testing.T, committeeSize int) { v.Set(util.ProtoConfigPath, filepath.Join(testdataDir, protoFileName)) // Set to the path or remove the next statement to download from the network. - require.NoError(t, initCmd.Flags().Set(util.ContractsInitFlag, contractsPath)) + require.NoError(t, Cmd.Flags().Set(util.ContractsInitFlag, contractsPath)) dumpPath := filepath.Join(testdataDir, "out") - require.NoError(t, initCmd.Flags().Set(util.LocalDumpFlag, dumpPath)) + require.NoError(t, Cmd.Flags().Set(util.LocalDumpFlag, dumpPath)) v.Set(util.AlphabetWalletsFlag, testdataDir) v.Set(util.EpochDurationInitFlag, 1) v.Set(util.MaxObjectSizeInitFlag, 1024) setTestCredentials(v, committeeSize) - require.NoError(t, initializeSideChainCmd(initCmd, nil)) + require.NoError(t, initializeSideChainCmd(Cmd, nil)) t.Run("force-new-epoch", func(t *testing.T) { require.NoError(t, netmap.ForceNewEpoch.Flags().Set(util.LocalDumpFlag, dumpPath)) diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_transfer.go similarity index 99% rename from cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go rename to cmd/frostfs-adm/internal/modules/morph/initialize/initialize_transfer.go index ab4acefee..8e501953b 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_transfer.go @@ -1,4 +1,4 @@ -package morph +package initialize import ( "fmt" diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize/root.go b/cmd/frostfs-adm/internal/modules/morph/initialize/root.go new file mode 100644 index 000000000..7dd6d17ca --- /dev/null +++ b/cmd/frostfs-adm/internal/modules/morph/initialize/root.go @@ -0,0 +1,55 @@ +package initialize + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +const ( + maxObjectSizeCLIFlag = "max-object-size" + epochDurationCLIFlag = "epoch-duration" + containerFeeCLIFlag = "container-fee" + containerAliasFeeCLIFlag = "container-alias-fee" + candidateFeeCLIFlag = "candidate-fee" + homomorphicHashDisabledCLIFlag = "homomorphic-disabled" + withdrawFeeCLIFlag = "withdraw-fee" +) + +var Cmd = &cobra.Command{ + Use: "init", + Short: "Initialize side chain network with smart-contracts and network settings", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + _ = viper.BindPFlag(util.EpochDurationInitFlag, cmd.Flags().Lookup(epochDurationCLIFlag)) + _ = viper.BindPFlag(util.MaxObjectSizeInitFlag, cmd.Flags().Lookup(maxObjectSizeCLIFlag)) + _ = viper.BindPFlag(util.HomomorphicHashDisabledInitFlag, cmd.Flags().Lookup(homomorphicHashDisabledCLIFlag)) + _ = viper.BindPFlag(util.CandidateFeeInitFlag, cmd.Flags().Lookup(candidateFeeCLIFlag)) + _ = viper.BindPFlag(util.ContainerFeeInitFlag, cmd.Flags().Lookup(containerFeeCLIFlag)) + _ = viper.BindPFlag(util.ContainerAliasFeeInitFlag, cmd.Flags().Lookup(containerAliasFeeCLIFlag)) + _ = viper.BindPFlag(util.WithdrawFeeInitFlag, cmd.Flags().Lookup(withdrawFeeCLIFlag)) + _ = viper.BindPFlag(util.ProtoConfigPath, cmd.Flags().Lookup(util.ProtoConfigPath)) + }, + RunE: initializeSideChainCmd, +} + +func initInitCmd() { + Cmd.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) + Cmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) + Cmd.Flags().String(util.ContractsInitFlag, "", util.ContractsInitFlagDesc) + Cmd.Flags().String(util.ContractsURLFlag, "", util.ContractsURLFlagDesc) + Cmd.Flags().Uint(epochDurationCLIFlag, 240, "Amount of side chain blocks in one FrostFS epoch") + Cmd.Flags().Uint(maxObjectSizeCLIFlag, 67108864, "Max single object size in bytes") + Cmd.Flags().Bool(homomorphicHashDisabledCLIFlag, false, "Disable object homomorphic hashing") + // Defaults are taken from neo-preodolenie. + Cmd.Flags().Uint64(containerFeeCLIFlag, 1000, "Container registration fee") + Cmd.Flags().Uint64(containerAliasFeeCLIFlag, 500, "Container alias fee") + Cmd.Flags().String(util.ProtoConfigPath, "", "Path to the consensus node configuration") + Cmd.Flags().String(util.LocalDumpFlag, "", "Path to the blocks dump file") + Cmd.MarkFlagsMutuallyExclusive(util.ContractsInitFlag, util.ContractsURLFlag) +} + +func init() { + initInitCmd() +} diff --git a/cmd/frostfs-adm/internal/modules/morph/root.go b/cmd/frostfs-adm/internal/modules/morph/root.go index e2a4517f3..9d2b25ceb 100644 --- a/cmd/frostfs-adm/internal/modules/morph/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/root.go @@ -8,60 +8,24 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/contract" "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/generate" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/initialize" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/netmap" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/node" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/notary" "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/proxy" - "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" "github.com/spf13/cobra" - "github.com/spf13/viper" ) -const ( - maxObjectSizeCLIFlag = "max-object-size" - - epochDurationCLIFlag = "epoch-duration" - - containerFeeCLIFlag = "container-fee" - containerAliasFeeCLIFlag = "container-alias-fee" - - candidateFeeCLIFlag = "candidate-fee" - - homomorphicHashDisabledCLIFlag = "homomorphic-disabled" - - withdrawFeeCLIFlag = "withdraw-fee" -) - -var ( - // RootCmd is a root command of config section. - RootCmd = &cobra.Command{ - Use: "morph", - Short: "Section for morph network configuration commands", - } - - initCmd = &cobra.Command{ - Use: "init", - Short: "Initialize side chain network with smart-contracts and network settings", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.AlphabetWalletsFlag, cmd.Flags().Lookup(util.AlphabetWalletsFlag)) - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - _ = viper.BindPFlag(util.EpochDurationInitFlag, cmd.Flags().Lookup(epochDurationCLIFlag)) - _ = viper.BindPFlag(util.MaxObjectSizeInitFlag, cmd.Flags().Lookup(maxObjectSizeCLIFlag)) - _ = viper.BindPFlag(util.HomomorphicHashDisabledInitFlag, cmd.Flags().Lookup(homomorphicHashDisabledCLIFlag)) - _ = viper.BindPFlag(util.CandidateFeeInitFlag, cmd.Flags().Lookup(candidateFeeCLIFlag)) - _ = viper.BindPFlag(util.ContainerFeeInitFlag, cmd.Flags().Lookup(containerFeeCLIFlag)) - _ = viper.BindPFlag(util.ContainerAliasFeeInitFlag, cmd.Flags().Lookup(containerAliasFeeCLIFlag)) - _ = viper.BindPFlag(util.WithdrawFeeInitFlag, cmd.Flags().Lookup(withdrawFeeCLIFlag)) - _ = viper.BindPFlag(util.ProtoConfigPath, cmd.Flags().Lookup(util.ProtoConfigPath)) - }, - RunE: initializeSideChainCmd, - } -) +// RootCmd is a root command of config section. +var RootCmd = &cobra.Command{ + Use: "morph", + Short: "Section for morph network configuration commands", +} func init() { RootCmd.AddCommand(generate.RefillGasCmd) - initInitCmd() + RootCmd.AddCommand(initialize.Cmd) RootCmd.AddCommand(contract.DeployCmd) RootCmd.AddCommand(generate.GenerateStorageCmd) RootCmd.AddCommand(netmap.ForceNewEpoch) @@ -86,20 +50,3 @@ func init() { RootCmd.AddCommand(frostfsid.Cmd) } - -func initInitCmd() { - RootCmd.AddCommand(initCmd) - initCmd.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) - initCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) - initCmd.Flags().String(util.ContractsInitFlag, "", util.ContractsInitFlagDesc) - initCmd.Flags().String(util.ContractsURLFlag, "", util.ContractsURLFlagDesc) - initCmd.Flags().Uint(epochDurationCLIFlag, 240, "Amount of side chain blocks in one FrostFS epoch") - initCmd.Flags().Uint(maxObjectSizeCLIFlag, 67108864, "Max single object size in bytes") - initCmd.Flags().Bool(homomorphicHashDisabledCLIFlag, false, "Disable object homomorphic hashing") - // Defaults are taken from neo-preodolenie. - initCmd.Flags().Uint64(containerFeeCLIFlag, 1000, "Container registration fee") - initCmd.Flags().Uint64(containerAliasFeeCLIFlag, 500, "Container alias fee") - initCmd.Flags().String(util.ProtoConfigPath, "", "Path to the consensus node configuration") - initCmd.Flags().String(util.LocalDumpFlag, "", "Path to the blocks dump file") - initCmd.MarkFlagsMutuallyExclusive(util.ContractsInitFlag, util.ContractsURLFlag) -}