From b3939291e161179d57c284f842f889e6dfb31660 Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Tue, 5 Sep 2023 16:31:39 +0400 Subject: [PATCH] neofs-cli: bugfix expire-at flag for session create command. Added a check for changes to the lifetime flag when it's passed by the user to prevent the settlement of the default lifetime value even if expire-at flag passed. Closes #2539. Signed-off-by: Ekaterina Pavlova --- cmd/neofs-cli/modules/session/create.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/neofs-cli/modules/session/create.go b/cmd/neofs-cli/modules/session/create.go index a3f5fe04e75..88aeacaefae 100644 --- a/cmd/neofs-cli/modules/session/create.go +++ b/cmd/neofs-cli/modules/session/create.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "os" + "strconv" "github.com/google/uuid" internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client" @@ -30,8 +31,13 @@ const defaultLifetime = 10 var createCmd = &cobra.Command{ Use: "create", Short: "Create session token", - Args: cobra.NoArgs, - Run: createSession, + Long: `Create session token. + +Default lifetime of session token is ` + strconv.Itoa(defaultLifetime) + ` epochs +if one of --` + commonflags.ExpireAt + ` or --` + commonflags.Lifetime + ` flags is not specified. +`, + Args: cobra.NoArgs, + Run: createSession, PersistentPreRun: func(cmd *cobra.Command, _ []string) { _ = viper.BindPFlag(commonflags.WalletPath, cmd.Flags().Lookup(commonflags.WalletPath)) _ = viper.BindPFlag(commonflags.Account, cmd.Flags().Lookup(commonflags.Account)) @@ -68,11 +74,13 @@ func createSession(cmd *cobra.Command, _ []string) { endpoint, _ := cmd.Flags().GetString(commonflags.RPC) currEpoch, err := internalclient.GetCurrentEpoch(ctx, endpoint) common.ExitOnErr(cmd, "can't get current epoch: %w", err) + cmd.Println("Current epoch:", currEpoch) exp, _ := cmd.Flags().GetUint64(commonflags.ExpireAt) lifetime := uint64(defaultLifetime) - if lfArg, _ := cmd.Flags().GetUint64(commonflags.Lifetime); lfArg != 0 { - exp = currEpoch + lfArg + if cmd.Flags().Changed(commonflags.Lifetime) { + lifetime, _ = cmd.Flags().GetUint64(commonflags.Lifetime) + exp = currEpoch + lifetime } if exp == 0 { exp = currEpoch + lifetime @@ -80,6 +88,7 @@ func createSession(cmd *cobra.Command, _ []string) { if exp <= currEpoch { common.ExitOnErr(cmd, "", errors.New("expiration epoch must be greater than current epoch")) } + cmd.Println("Expiration epoch:", exp) var tok session.Object err = CreateSession(ctx, &tok, c, *privKey, exp, currEpoch) common.ExitOnErr(cmd, "can't create session: %w", err)