From e2557b2f0b23b0c3163b274d524f9cefb74e77b0 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Fri, 2 Feb 2024 09:06:24 +0300 Subject: [PATCH] [#932] adm: Move `dump-hashes` to package `contract` Signed-off-by: Anton Nikiforov --- .../morph/{ => contract}/dump_hashes.go | 4 +-- .../internal/modules/morph/contract/root.go | 25 +++++++++++++++++++ .../internal/modules/morph/deploy.go | 5 ++-- .../internal/modules/morph/root.go | 18 ++----------- .../internal/modules/morph/util/const.go | 1 + 5 files changed, 32 insertions(+), 21 deletions(-) rename cmd/frostfs-adm/internal/modules/morph/{ => contract}/dump_hashes.go (98%) create mode 100644 cmd/frostfs-adm/internal/modules/morph/contract/root.go diff --git a/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go b/cmd/frostfs-adm/internal/modules/morph/contract/dump_hashes.go similarity index 98% rename from cmd/frostfs-adm/internal/modules/morph/dump_hashes.go rename to cmd/frostfs-adm/internal/modules/morph/contract/dump_hashes.go index c92c25690..8f7fbe6e0 100644 --- a/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go +++ b/cmd/frostfs-adm/internal/modules/morph/contract/dump_hashes.go @@ -1,4 +1,4 @@ -package morph +package contract import ( "bytes" @@ -45,7 +45,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { return err } - zone, _ := cmd.Flags().GetString(customZoneFlag) + zone, _ := cmd.Flags().GetString(morphUtil.CustomZoneFlag) if zone != "" { return dumpCustomZoneHashes(cmd, cs.Hash, zone, c) } diff --git a/cmd/frostfs-adm/internal/modules/morph/contract/root.go b/cmd/frostfs-adm/internal/modules/morph/contract/root.go new file mode 100644 index 000000000..8decfd4a3 --- /dev/null +++ b/cmd/frostfs-adm/internal/modules/morph/contract/root.go @@ -0,0 +1,25 @@ +package contract + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var DumpHashesCmd = &cobra.Command{ + Use: "dump-hashes", + Short: "Dump deployed contract hashes", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) + }, + RunE: dumpContractHashes, +} + +func initDumpContractHashesCmd() { + DumpHashesCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) + DumpHashesCmd.Flags().String(util.CustomZoneFlag, "", "Custom zone to search.") +} + +func init() { + initDumpContractHashesCmd() +} diff --git a/cmd/frostfs-adm/internal/modules/morph/deploy.go b/cmd/frostfs-adm/internal/modules/morph/deploy.go index e6fdbbcf7..a312b34cd 100644 --- a/cmd/frostfs-adm/internal/modules/morph/deploy.go +++ b/cmd/frostfs-adm/internal/modules/morph/deploy.go @@ -24,7 +24,6 @@ import ( const ( contractPathFlag = "contract" updateFlag = "update" - customZoneFlag = "domain" ) var deployCmd = &cobra.Command{ @@ -55,7 +54,7 @@ func init() { _ = deployCmd.MarkFlagFilename(contractPathFlag) ff.Bool(updateFlag, false, "Update an existing contract") - ff.String(customZoneFlag, "frostfs", "Custom zone for NNS") + ff.String(util.CustomZoneFlag, "frostfs", "Custom zone for NNS") } func deployContractCmd(cmd *cobra.Command, args []string) error { @@ -85,7 +84,7 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { callHash := management.Hash method := deployMethodName - zone, _ := cmd.Flags().GetString(customZoneFlag) + zone, _ := cmd.Flags().GetString(util.CustomZoneFlag) domain := ctrName + "." + zone isUpdate, _ := cmd.Flags().GetBool(updateFlag) if isUpdate { diff --git a/cmd/frostfs-adm/internal/modules/morph/root.go b/cmd/frostfs-adm/internal/modules/morph/root.go index 6546b6dee..66dd77556 100644 --- a/cmd/frostfs-adm/internal/modules/morph/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/root.go @@ -5,6 +5,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/balance" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/config" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/container" + "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/netmap" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/node" @@ -98,15 +99,6 @@ var ( }, } - dumpContractHashesCmd = &cobra.Command{ - Use: "dump-hashes", - Short: "Dump deployed contract hashes", - PreRun: func(cmd *cobra.Command, _ []string) { - _ = viper.BindPFlag(util.EndpointFlag, cmd.Flags().Lookup(util.EndpointFlag)) - }, - RunE: dumpContractHashes, - } - updateContractsCmd = &cobra.Command{ Use: "update-contracts", Short: "Update FrostFS contracts", @@ -127,7 +119,7 @@ func init() { RootCmd.AddCommand(node.RemoveCmd) RootCmd.AddCommand(policy.Set) RootCmd.AddCommand(policy.Dump) - initDumpContractHashesCmd() + RootCmd.AddCommand(contract.DumpHashesCmd) RootCmd.AddCommand(config.SetCmd) RootCmd.AddCommand(config.DumpCmd) RootCmd.AddCommand(balance.DumpCmd) @@ -165,12 +157,6 @@ func initUpdateContractsCmd() { updateContractsCmd.MarkFlagsMutuallyExclusive(util.ContractsInitFlag, util.ContractsURLFlag) } -func initDumpContractHashesCmd() { - RootCmd.AddCommand(dumpContractHashesCmd) - dumpContractHashesCmd.Flags().StringP(util.EndpointFlag, util.EndpointFlagShort, "", util.EndpointFlagDesc) - dumpContractHashesCmd.Flags().String(customZoneFlag, "", "Custom zone to search.") -} - func initGenerateStorageCmd() { RootCmd.AddCommand(generateStorageCmd) generateStorageCmd.Flags().String(util.AlphabetWalletsFlag, "", util.AlphabetWalletsFlagDesc) diff --git a/cmd/frostfs-adm/internal/modules/morph/util/const.go b/cmd/frostfs-adm/internal/modules/morph/util/const.go index c4a674bd6..cdf1cd443 100644 --- a/cmd/frostfs-adm/internal/modules/morph/util/const.go +++ b/cmd/frostfs-adm/internal/modules/morph/util/const.go @@ -31,6 +31,7 @@ const ( WithdrawFeeInitFlag = "network.fee.withdraw" MaintenanceModeAllowedInitFlag = "network.maintenance_mode_allowed" HomomorphicHashDisabledInitFlag = "network.homomorphic_hash_disabled" + CustomZoneFlag = "domain" SingleAccountName = "single" CommitteeAccountName = "committee"