From 4b742042eedfbe734eb5f92398529fd15fa3663f Mon Sep 17 00:00:00 2001 From: max furman Date: Fri, 18 Jan 2019 10:39:12 -0800 Subject: [PATCH] make Duration wrapper publicly accessible --- authority/config.go | 6 +++--- authority/provisioner.go | 6 +++--- authority/types.go | 13 +++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/authority/config.go b/authority/config.go index a6a78523..3bc8e810 100644 --- a/authority/config.go +++ b/authority/config.go @@ -26,9 +26,9 @@ var ( } defaultDisableRenewal = false globalProvisionerClaims = ProvisionerClaims{ - MinTLSDur: &duration{5 * time.Minute}, - MaxTLSDur: &duration{24 * time.Hour}, - DefaultTLSDur: &duration{24 * time.Hour}, + MinTLSDur: &Duration{5 * time.Minute}, + MaxTLSDur: &Duration{24 * time.Hour}, + DefaultTLSDur: &Duration{24 * time.Hour}, DisableRenewal: &defaultDisableRenewal, } ) diff --git a/authority/provisioner.go b/authority/provisioner.go index 53372f11..6dd1b1ac 100644 --- a/authority/provisioner.go +++ b/authority/provisioner.go @@ -12,9 +12,9 @@ import ( // ProvisionerClaims so that individual provisioners can override global claims. type ProvisionerClaims struct { globalClaims *ProvisionerClaims - MinTLSDur *duration `json:"minTLSCertDuration,omitempty"` - MaxTLSDur *duration `json:"maxTLSCertDuration,omitempty"` - DefaultTLSDur *duration `json:"defaultTLSCertDuration,omitempty"` + MinTLSDur *Duration `json:"minTLSCertDuration,omitempty"` + MaxTLSDur *Duration `json:"maxTLSCertDuration,omitempty"` + DefaultTLSDur *Duration `json:"defaultTLSCertDuration,omitempty"` DisableRenewal *bool `json:"disableRenewal,omitempty"` } diff --git a/authority/types.go b/authority/types.go index d9120f59..0d003eac 100644 --- a/authority/types.go +++ b/authority/types.go @@ -7,25 +7,26 @@ import ( "github.com/pkg/errors" ) -type duration struct { +// Duration is a wrapper around Time.Duration to aid with marshal/unmarshal. +type Duration struct { time.Duration } -// MarshalJSON parses a duration string and sets it to the duration. +// MarshalJSON parses a Duration string and sets it to the duration. // // A duration string is a possibly signed sequence of decimal numbers, each with // optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". -func (d *duration) MarshalJSON() ([]byte, error) { +func (d *Duration) MarshalJSON() ([]byte, error) { return json.Marshal(d.String()) } -// UnmarshalJSON parses a duration string and sets it to the duration. +// UnmarshalJSON parses a Duration string and sets it to the duration. // -// A duration string is a possibly signed sequence of decimal numbers, each with +// A Duration string is a possibly signed sequence of decimal numbers, each with // optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". // Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". -func (d *duration) UnmarshalJSON(data []byte) (err error) { +func (d *Duration) UnmarshalJSON(data []byte) (err error) { var s string if err = json.Unmarshal(data, &s); err != nil { return errors.Wrapf(err, "error unmarshalling %s", data)