From d5584e12bc2599dcbeaac005386c679f3beae896 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 29 Jan 2016 20:02:15 -0500 Subject: [PATCH] invert logic to prefer client increment --- logical/framework/lease.go | 14 +++++++------- logical/framework/lease_test.go | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/logical/framework/lease.go b/logical/framework/lease.go index 62965b8d1..3e5ebe154 100644 --- a/logical/framework/lease.go +++ b/logical/framework/lease.go @@ -57,15 +57,15 @@ func LeaseExtend(backendIncrement, backendMax time.Duration, systemView logical. } // Basic max safety checks have passed, now let's figure out our - // increment. We'll use the backend-provided value if possible, or the - // mount/system default if not. We won't change the LeaseOpts value, - // just adjust accordingly. + // increment. We'll use the user-supplied value first, then backend-provided default if possible, or the + // mount/system default if not. increment := leaseOpts.Increment - if backendIncrement > 0 { - increment = backendIncrement - } if increment <= 0 { - increment = systemView.DefaultLeaseTTL() + if backendIncrement > 0 { + increment = backendIncrement + } else { + increment = systemView.DefaultLeaseTTL() + } } // We are proposing a time of the current time plus the increment diff --git a/logical/framework/lease_test.go b/logical/framework/lease_test.go index b089b2059..0ab036a61 100644 --- a/logical/framework/lease_test.go +++ b/logical/framework/lease_test.go @@ -23,25 +23,25 @@ func TestLeaseExtend(t *testing.T) { Result time.Duration Error bool }{ - "valid request, good bounds": { + "valid request, good bounds, increment is preferred": { BackendDefault: 30 * time.Hour, Increment: 1 * time.Hour, - Result: 30 * time.Hour, + Result: 1 * time.Hour, }, - "valid request, zero backend default": { + "valid request, zero backend default, uses increment": { BackendDefault: 0, Increment: 1 * time.Hour, Result: 1 * time.Hour, }, - "lease increment is zero": { + "lease increment is zero, uses backend default": { BackendDefault: 30 * time.Hour, Increment: 0, Result: 30 * time.Hour, }, - "lease increment and default are zero, use sysview": { + "lease increment and default are zero, uses systemview": { BackendDefault: 0, Increment: 0, Result: 5 * time.Hour, @@ -53,7 +53,7 @@ func TestLeaseExtend(t *testing.T) { Result: 30 * time.Hour, }, - "request would go past max backend values and increment": { + "all request values are larger than the system view, so the system view limits": { BackendDefault: 40 * time.Hour, BackendMax: 50 * time.Hour, Increment: 40 * time.Hour, @@ -64,7 +64,7 @@ func TestLeaseExtend(t *testing.T) { BackendDefault: 9 * time.Hour, BackendMax: 5 * time.Hour, Increment: 4 * time.Hour, - Result: 5 * time.Hour, + Result: 4 * time.Hour, }, "request outside backend max": {