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 | Bin 45864 -> 45864 bytes 4 files changed, 63 insertions(+), 1 deletion(-) 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 c18e291f27398c2660fd12296644df53513cfa0a..56f4cba5ac3d6f4f81b8813ba6dd9d1da9f09cd0 100644 GIT binary patch delta 169 zcmZ4SjA_L)rVSx%E=GoiMux_wCc3F9mc~g*rpd{s<|YamhE@T&0f`>TCIR|ES$T%x zfypjzrs>J$o<3FKS=qk+r9mD(g;lwh{!z{;juQhFCR?&edt)_AKRsVBH$MerWI?f6 zzPG0IkV3 AZvX%Q delta 169 zcmZ4SjA_L)rVSx%E`}zCMn*=a#=2%ksfm_mNft)Qsm2N!hE^4M!TOPjIX;EXK?ONw z1#ZT!mihrf?x|&2Cdn?T=7ny4Q6UDo*;!G^#S;S+CR?&edt)_AKRsVBH$MerWSNO^ zW^Qt6aIQ;vuwPMXK&nY-NMMFVR-&tgTW)ctx1X_Fa-wThZctS+(8$ep?5|b>0H?n; ArT_o{