From 17e127d22b5091fc6ea7d7053c378373eef9d972 Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Thu, 4 May 2023 11:37:30 -0400 Subject: [PATCH] backport of commit fb9324c3c9e3876e3e5120c126e0ce3ee5982c7c (#20514) Co-authored-by: Hamid Ghaf <83242695+hghaf099@users.noreply.github.com> --- changelog/20477.txt | 3 +++ command/base_flags.go | 4 ++-- command/token_create_test.go | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelog/20477.txt diff --git a/changelog/20477.txt b/changelog/20477.txt new file mode 100644 index 000000000000..e95305a70bec --- /dev/null +++ b/changelog/20477.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: CLI should take days as a unit of time for ttl like flags +``` diff --git a/command/base_flags.go b/command/base_flags.go index 4865d7163125..652ac177c685 100644 --- a/command/base_flags.go +++ b/command/base_flags.go @@ -591,7 +591,7 @@ type DurationVar struct { func (f *FlagSet) DurationVar(i *DurationVar) { initial := i.Default if v, exist := os.LookupEnv(i.EnvVar); exist { - if d, err := time.ParseDuration(appendDurationSuffix(v)); err == nil { + if d, err := parseutil.ParseDurationSecond(v); err == nil { initial = d } } @@ -631,7 +631,7 @@ func (d *durationValue) Set(s string) error { s = "-1" } - v, err := time.ParseDuration(appendDurationSuffix(s)) + v, err := parseutil.ParseDurationSecond(s) if err != nil { return err } diff --git a/command/token_create_test.go b/command/token_create_test.go index 1fd11b1e9f84..a7e767926ae6 100644 --- a/command/token_create_test.go +++ b/command/token_create_test.go @@ -68,6 +68,12 @@ func TestTokenCreateCommand_Run(t *testing.T) { "not present in secret", 1, }, + { + "ttl", + []string{"-ttl", "1d", "-explicit-max-ttl", "2d"}, + "token", + 0, + }, } t.Run("validations", func(t *testing.T) {