From 5e72453b4950ac6dad7eed0e981ac58f566eb8a8 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 30 Oct 2015 17:45:01 -0400 Subject: [PATCH] Use TypeDurationSecond instead of TypeString --- builtin/credential/cert/path_certs.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/builtin/credential/cert/path_certs.go b/builtin/credential/cert/path_certs.go index 114d5fdce..5e7046f5d 100644 --- a/builtin/credential/cert/path_certs.go +++ b/builtin/credential/cert/path_certs.go @@ -42,7 +42,7 @@ seconds. Defaults to system/backend default TTL.`, }, "ttl": &framework.FieldSchema{ - Type: framework.TypeString, + Type: framework.TypeDurationSecond, Description: `TTL for tokens issued by this backend. Defaults to system/backend default TTL time.`, }, @@ -142,15 +142,9 @@ func (b *backend) pathCertWrite( // Parse the lease duration or default to backend/system default var err error maxTTL := b.System().MaxLeaseTTL() - ttlStr := d.Get("ttl").(string) - var ttl time.Duration - if len(ttlStr) == 0 { + ttl := time.Duration(d.Get("ttl").(int)) * time.Second + if ttl == time.Duration(0) { ttl = time.Second * time.Duration(d.Get("lease").(int)) - } else { - ttl, err = time.ParseDuration(ttlStr) - if err != nil { - return logical.ErrorResponse(fmt.Sprintf("Failed to parse ttl of %d", ttlStr)), nil - } } if ttl > maxTTL { return logical.ErrorResponse(fmt.Sprintf("Given TTL of %d seconds greater than current mount/system default of %d seconds", ttl/time.Second, maxTTL/time.Second)), nil