From 4b8ca752740c7f0271d5ff6ea3b85c1a285da01b Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 30 Nov 2021 14:58:15 +0300 Subject: [PATCH] [#979] adm: Fix problems after testing Use persistent flags on parent command in order to inherit flags in sub-commands. Turn on notary mode of morph client in `subnet` command of admin utility for notary environments. Signed-off-by: Leonard Lyubich --- .../internal/modules/morph/subnet.go | 26 +++++++++++-------- pkg/morph/client/subnet/get.go | 12 ++++----- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/subnet.go b/cmd/neofs-adm/internal/modules/morph/subnet.go index 38fdc66ea..c4c21b21f 100644 --- a/cmd/neofs-adm/internal/modules/morph/subnet.go +++ b/cmd/neofs-adm/internal/modules/morph/subnet.go @@ -42,7 +42,7 @@ func viperBindFlags(cmd *cobra.Command, flags ...string) { var cmdSubnet = &cobra.Command{ Use: "subnet", Short: "NeoFS subnet management.", - PreRun: func(cmd *cobra.Command, _ []string) { + PersistentPreRun: func(cmd *cobra.Command, _ []string) { viperBindFlags(cmd, flagSubnetEndpoint, flagSubnetKey, @@ -109,10 +109,19 @@ func initSubnetClient(c *morphsubnet.Client, key *keys.PrivateKey) error { return err } + nonNotary := viper.GetBool(flagSubnetNonNotary) + + if nonNotary { + err = cMorph.EnableNotarySupport() + if err != nil { + return fmt.Errorf("enable notary support: %w", err) + } + } + // calc client mode cMode := morphsubnet.NotaryNonAlphabet - if viper.GetBool(flagSubnetNonNotary) { + if nonNotary { cMode = morphsubnet.NonNotary } @@ -173,11 +182,6 @@ var cmdSubnetCreate = &cobra.Command{ // declare creator ID and encode it creator := *owner.NewIDFromNeo3Wallet(n3Wallet) - binCreator, err := creator.Marshal() - if err != nil { - return fmt.Errorf("marshal creator ID: %w", err) - } - // fill subnet info and encode it var info subnet.Info @@ -201,7 +205,7 @@ var cmdSubnetCreate = &cobra.Command{ var prm morphsubnet.PutPrm prm.SetID(binID) - prm.SetOwner(binCreator) + prm.SetOwner(key.PublicKey().Bytes()) prm.SetInfo(binInfo) _, err = cSubnet.Put(prm) @@ -653,7 +657,7 @@ func init() { _ = cmdSubnetRemove.MarkFlagRequired(flagSubnetRemoveID) // subnet administer flags - adminFlags := cmdSubnetAdmin.Flags() + adminFlags := cmdSubnetAdmin.PersistentFlags() adminFlags.String(flagSubnetAdminSubnet, "", "ID of the subnet to manage administrators") _ = cmdSubnetAdmin.MarkFlagRequired(flagSubnetAdminSubnet) adminFlags.String(flagSubnetAdminID, "", "Hex-encoded public key of the admin") @@ -670,7 +674,7 @@ func init() { cmdSubnetAdminRemoveFlags.Bool(flagSubnetAdminClient, false, "Remove client admin instead of node one") // client managements flags - clientFlags := cmdSubnetClient.Flags() + clientFlags := cmdSubnetClient.PersistentFlags() clientFlags.String(flagSubnetClientSubnet, "", "ID of the subnet to be managed") _ = cmdSubnetClient.MarkFlagRequired(flagSubnetClientSubnet) clientFlags.String(flagSubnetClientGroup, "", "ID of the client group to work with") @@ -691,7 +695,7 @@ func init() { ) // subnet global flags - cmdSubnetFlags := cmdSubnet.Flags() + cmdSubnetFlags := cmdSubnet.PersistentFlags() cmdSubnetFlags.StringP(flagSubnetEndpoint, "r", "", "N3 RPC node endpoint") _ = cmdSubnet.MarkFlagRequired(flagSubnetEndpoint) cmdSubnetFlags.StringP(flagSubnetKey, "k", "", "Path to file with private key") diff --git a/pkg/morph/client/subnet/get.go b/pkg/morph/client/subnet/get.go index b5fab8dff..88ab2e7b8 100644 --- a/pkg/morph/client/subnet/get.go +++ b/pkg/morph/client/subnet/get.go @@ -2,15 +2,12 @@ package morphsubnet import ( "errors" - "fmt" "github.com/nspcc-dev/neofs-node/pkg/morph/client" ) // GetPrm groups parameters of Get method of Subnet contract. type GetPrm struct { - cliPrm client.TestInvokePrm - args [1]interface{} } @@ -33,12 +30,13 @@ var errEmptyResponse = errors.New("empty response") // Get reads the subnet through the call of the corresponding method of the Subnet contract. func (x *Client) Get(prm GetPrm) (*GetRes, error) { - prm.cliPrm.SetMethod("get") - prm.cliPrm.SetArgs(prm.args[:]...) + var prmGet client.TestInvokePrm - res, err := x.client.TestInvoke(prm.cliPrm) + prmGet.SetMethod("get") + prmGet.SetArgs(prm.args[:]...) + + res, err := x.client.TestInvoke(prmGet) if err != nil { - fmt.Println() return nil, err }