-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Use TypeDurationSecond for TTL values in PKI. #3270
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -728,48 +728,38 @@ func generateCreationBundle(b *backend, | |
} | ||
|
||
// Get the TTL and very it against the max allowed | ||
var ttlField string | ||
var ttl time.Duration | ||
var maxTTL time.Duration | ||
var notAfter time.Time | ||
var ttlFieldInt interface{} | ||
{ | ||
ttlFieldInt, ok = data.GetOk("ttl") | ||
if !ok { | ||
ttlField = role.TTL | ||
} else { | ||
ttlField = ttlFieldInt.(string) | ||
} | ||
ttl = time.Duration(data.Get("ttl").(int)) * time.Second | ||
|
||
if len(ttlField) == 0 { | ||
ttl = b.System().DefaultLeaseTTL() | ||
} else { | ||
ttl, err = parseutil.ParseDurationSecond(ttlField) | ||
if err != nil { | ||
return nil, errutil.UserError{Err: fmt.Sprintf( | ||
"invalid requested ttl: %s", err)} | ||
if ttl == 0 { | ||
if role.TTL != "" { | ||
ttl, err = parseutil.ParseDurationSecond(role.TTL) | ||
if err != nil { | ||
return nil, errutil.UserError{Err: fmt.Sprintf( | ||
"invalid requested ttl: %s", err)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may not be a requested There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah |
||
} | ||
} | ||
} | ||
|
||
if len(role.MaxTTL) == 0 { | ||
maxTTL = b.System().MaxLeaseTTL() | ||
} else { | ||
if role.MaxTTL != "" { | ||
maxTTL, err = parseutil.ParseDurationSecond(role.MaxTTL) | ||
if err != nil { | ||
return nil, errutil.UserError{Err: fmt.Sprintf( | ||
"invalid ttl: %s", err)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. max_ttl |
||
} | ||
} | ||
|
||
if ttl == 0 { | ||
ttl = b.System().DefaultLeaseTTL() | ||
} | ||
if maxTTL == 0 { | ||
maxTTL = b.System().MaxLeaseTTL() | ||
} | ||
if ttl > maxTTL { | ||
// Don't error if they were using system defaults, only error if | ||
// they specifically chose a bad TTL | ||
if len(ttlField) == 0 { | ||
ttl = maxTTL | ||
} else { | ||
return nil, errutil.UserError{Err: fmt.Sprintf( | ||
"ttl is larger than maximum allowed (%d)", maxTTL/time.Second)} | ||
} | ||
ttl = maxTTL | ||
} | ||
|
||
notAfter = time.Now().Add(ttl) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need for double
Error()
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe if I switch it to t.Fatal -- t.Fatalf expects a string, and resp.Error() returns an
error