From 5b672fb3927e4a709d857a1da4f6deb72fd351ba Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 21 Dec 2023 16:33:37 +0300 Subject: [PATCH] [#876] adm: Add `morph ape get/set-admin` commands Signed-off-by: Anton Nikiforov --- cmd/frostfs-adm/internal/modules/morph/ape.go | 58 +++++++++++++++++++ .../internal/modules/morph/root.go | 4 ++ go.mod | 2 +- go.sum | 4 +- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/ape.go b/cmd/frostfs-adm/internal/modules/morph/ape.go index 6dd2bd185..9f1d75adb 100644 --- a/cmd/frostfs-adm/internal/modules/morph/ape.go +++ b/cmd/frostfs-adm/internal/modules/morph/ape.go @@ -7,6 +7,7 @@ import ( parseutil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util" commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -26,6 +27,8 @@ const ( targetNameDesc = "Resource name in APE resource name format" targetTypeFlag = "target-type" targetTypeDesc = "Resource type(container/namespace)" + addrAdminFlag = "addr" + addrAdminDesc = "The address of the admins wallet" ) var ( @@ -63,6 +66,26 @@ var ( }, Run: listRuleChains, } + + setAdminCmd = &cobra.Command{ + Use: "set-admin", + Short: "Set admin", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(endpointFlag, cmd.Flags().Lookup(endpointFlag)) + _ = viper.BindPFlag(alphabetWalletsFlag, cmd.Flags().Lookup(alphabetWalletsFlag)) + }, + Run: setAdmin, + } + + getAdminCmd = &cobra.Command{ + Use: "get-admin", + Short: "Get admin", + PreRun: func(cmd *cobra.Command, _ []string) { + _ = viper.BindPFlag(endpointFlag, cmd.Flags().Lookup(endpointFlag)) + _ = viper.BindPFlag(alphabetWalletsFlag, cmd.Flags().Lookup(alphabetWalletsFlag)) + }, + Run: getAdmin, + } ) func initAddRuleChainCmd() { @@ -110,6 +133,22 @@ func initListRuleChainsCmd() { listRuleChainsCmd.Flags().Bool(jsonFlag, false, jsonFlagDesc) } +func initSetAdminCmd() { + apeCmd.AddCommand(setAdminCmd) + + setAdminCmd.Flags().StringP(endpointFlag, endpointFlagShort, "", endpointFlagDesc) + setAdminCmd.Flags().String(alphabetWalletsFlag, "", alphabetWalletsFlagDesc) + setAdminCmd.Flags().String(addrAdminFlag, "", addrAdminDesc) + _ = setAdminCmd.MarkFlagRequired(addrAdminFlag) +} + +func initGetAdminCmd() { + apeCmd.AddCommand(getAdminCmd) + + getAdminCmd.Flags().StringP(endpointFlag, endpointFlagShort, "", endpointFlagDesc) + getAdminCmd.Flags().String(alphabetWalletsFlag, "", alphabetWalletsFlagDesc) +} + func addRuleChain(cmd *cobra.Command, _ []string) { chain := parseChain(cmd) target := parseTarget(cmd) @@ -151,6 +190,25 @@ func listRuleChains(cmd *cobra.Command, _ []string) { } } +func setAdmin(cmd *cobra.Command, _ []string) { + s, _ := cmd.Flags().GetString(addrAdminFlag) + addr, err := util.Uint160DecodeStringLE(s) + commonCmd.ExitOnErr(cmd, "can't decode admin addr: %w", err) + pci, ac := newPolicyContractInterface(cmd) + h, vub, err := pci.SetAdmin(addr) + cmd.Println("Waiting for transaction to persist...") + _, err = ac.Wait(h, vub, err) + commonCmd.ExitOnErr(cmd, "can't set admin: %w", err) + cmd.Println("Admin set successfully") +} + +func getAdmin(cmd *cobra.Command, _ []string) { + pci, _ := newPolicyContractInterface(cmd) + addr, err := pci.GetAdmin() + commonCmd.ExitOnErr(cmd, "unable to get admin: %w", err) + cmd.Println(addr.StringLE()) +} + func prettyJSONFormat(cmd *cobra.Command, chains []*apechain.Chain) { wr := bytes.NewBufferString("") data, err := json.Marshal(chains) diff --git a/cmd/frostfs-adm/internal/modules/morph/root.go b/cmd/frostfs-adm/internal/modules/morph/root.go index 75409421a..4176a6470 100644 --- a/cmd/frostfs-adm/internal/modules/morph/root.go +++ b/cmd/frostfs-adm/internal/modules/morph/root.go @@ -283,10 +283,14 @@ func init() { initRefillGasCmd() initDepositoryNotaryCmd() initNetmapCandidatesCmd() + RootCmd.AddCommand(apeCmd) initAddRuleChainCmd() initRemoveRuleChainCmd() initListRuleChainsCmd() + initSetAdminCmd() + initGetAdminCmd() + initProxyAddAccount() initProxyRemoveAccount() } diff --git a/go.mod b/go.mod index 6463c3b2b..2b8ffea31 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20231101111734-b3ad3335ff65 git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231122162120-56debcfa569e git.frostfs.info/TrueCloudLab/hrw v1.2.1 - git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231214122253-62ea96b82ce3 + git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231221121354-ed93bb5cc574 git.frostfs.info/TrueCloudLab/tzhash v1.8.0 github.com/cheggaaa/pb v1.0.29 github.com/chzyer/readline v1.5.1 diff --git a/go.sum b/go.sum index c18e291f2..56f4cba5a 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,8 @@ git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231122162120-56debcfa569e git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231122162120-56debcfa569e/go.mod h1:t1akKcUH7iBrFHX8rSXScYMP17k2kYQXMbZooiL5Juw= git.frostfs.info/TrueCloudLab/hrw v1.2.1 h1:ccBRK21rFvY5R1WotI6LNoPlizk7qSvdfD8lNIRudVc= git.frostfs.info/TrueCloudLab/hrw v1.2.1/go.mod h1:C1Ygde2n843yTZEQ0FP69jYiuaYV0kriLvP4zm8JuvM= -git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231214122253-62ea96b82ce3 h1:xnS/YalLqCRplvpF3E9/PRGevj4cDe7qFNZT0mkjZcs= -git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231214122253-62ea96b82ce3/go.mod h1:v43imcuSmDwSNrePe4UTQh8jaE8FmsiKN3FcaEzmRzc= +git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231221121354-ed93bb5cc574 h1:PmPaHc4P/Rjn1WQcDF5gcwILzWjkMOuRHLqzm9OZCdA= +git.frostfs.info/TrueCloudLab/policy-engine v0.0.0-20231221121354-ed93bb5cc574/go.mod h1:ps6oKO0mxaPJzK3admTB3iwoBXKkHnS73n4PCrqpHBg= git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 h1:M2KR3iBj7WpY3hP10IevfIB9MURr4O9mwVfJ+SjT3HA= git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0/go.mod h1:okpbKfVYf/BpejtfFTfhZqFP+sZ8rsHrP8Rr/jYPNRc= git.frostfs.info/TrueCloudLab/tzhash v1.8.0 h1:UFMnUIk0Zh17m8rjGHJMqku2hCgaXDqjqZzS4gsb4UA=