[#876] adm: Add morph ape get/set-admin commands
All checks were successful
DCO action / DCO (pull_request) Successful in 2m56s
Vulncheck / Vulncheck (pull_request) Successful in 3m1s
Build / Build Components (1.20) (pull_request) Successful in 3m46s
Build / Build Components (1.21) (pull_request) Successful in 3m45s
Tests and linters / Staticcheck (pull_request) Successful in 4m41s
Tests and linters / Lint (pull_request) Successful in 6m6s
Tests and linters / Tests (1.20) (pull_request) Successful in 12m18s
Tests and linters / Tests (1.21) (pull_request) Successful in 13m7s
Tests and linters / Tests with -race (pull_request) Successful in 13m22s

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-12-21 16:33:37 +03:00
parent eab981bf1a
commit 5b672fb392
4 changed files with 63 additions and 1 deletions

View file

@ -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)

View file

@ -283,10 +283,14 @@ func init() {
initRefillGasCmd()
initDepositoryNotaryCmd()
initNetmapCandidatesCmd()
RootCmd.AddCommand(apeCmd)
initAddRuleChainCmd()
initRemoveRuleChainCmd()
initListRuleChainsCmd()
initSetAdminCmd()
initGetAdminCmd()
initProxyAddAccount()
initProxyRemoveAccount()
}

2
go.mod
View file

@ -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

BIN
go.sum

Binary file not shown.