Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neofs-cli: bugfix expire-at flag for session create command. #2546

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions cmd/neofs-cli/modules/session/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 none of --` + commonflags.ExpireAt + ` or --` + commonflags.Lifetime + ` flags is 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))
Expand Down Expand Up @@ -69,12 +75,9 @@ func createSession(cmd *cobra.Command, _ []string) {
currEpoch, err := internalclient.GetCurrentEpoch(ctx, endpoint)
common.ExitOnErr(cmd, "can't get current epoch: %w", err)

exp, _ := cmd.Flags().GetUint64(commonflags.ExpireAt)
lifetime := uint64(defaultLifetime)
if lfArg, _ := cmd.Flags().GetUint64(commonflags.Lifetime); lfArg != 0 {
exp = currEpoch + lfArg
}
if exp == 0 {
var exp uint64
carpawell marked this conversation as resolved.
Show resolved Hide resolved
if exp, _ = cmd.Flags().GetUint64(commonflags.ExpireAt); exp == 0 {
lifetime, _ := cmd.Flags().GetUint64(commonflags.Lifetime)
exp = currEpoch + lifetime
}
if exp <= currEpoch {
Expand Down
Loading