@@ -8,76 +8,90 @@ import (
8
8
9
9
// Claims so that individual provisioners can override global claims.
10
10
type Claims struct {
11
- globalClaims * Claims
12
11
MinTLSDur * Duration `json:"minTLSCertDuration,omitempty"`
13
12
MaxTLSDur * Duration `json:"maxTLSCertDuration,omitempty"`
14
13
DefaultTLSDur * Duration `json:"defaultTLSCertDuration,omitempty"`
15
14
DisableRenewal * bool `json:"disableRenewal,omitempty"`
16
15
}
17
16
18
- // Init initializes and validates the individual provisioner claims.
19
- func (pc * Claims ) Init (global * Claims ) (* Claims , error ) {
20
- if pc == nil {
21
- pc = & Claims {}
17
+ // Claimer is the type that controls claims. It provides an interface around the
18
+ // current claim and the global one.
19
+ type Claimer struct {
20
+ global Claims
21
+ claims * Claims
22
+ }
23
+
24
+ // NewClaimer initializes a new claimer with the given claims.
25
+ func NewClaimer (claims * Claims , global Claims ) (* Claimer , error ) {
26
+ c := & Claimer {global : global , claims : claims }
27
+ return c , c .Validate ()
28
+ }
29
+
30
+ // Claims returns the merge of the inner and global claims.
31
+ func (c * Claimer ) Claims () Claims {
32
+ disableRenewal := c .IsDisableRenewal ()
33
+ return Claims {
34
+ MinTLSDur : & Duration {c .MinTLSCertDuration ()},
35
+ MaxTLSDur : & Duration {c .MaxTLSCertDuration ()},
36
+ DefaultTLSDur : & Duration {c .DefaultTLSCertDuration ()},
37
+ DisableRenewal : & disableRenewal ,
22
38
}
23
- pc .globalClaims = global
24
- return pc , pc .Validate ()
25
39
}
26
40
27
41
// DefaultTLSCertDuration returns the default TLS cert duration for the
28
42
// provisioner. If the default is not set within the provisioner, then the global
29
43
// default from the authority configuration will be used.
30
- func (pc * Claims ) DefaultTLSCertDuration () time.Duration {
31
- if pc . DefaultTLSDur == nil || pc . DefaultTLSDur . Duration == 0 {
32
- return pc . globalClaims . DefaultTLSCertDuration ()
44
+ func (c * Claimer ) DefaultTLSCertDuration () time.Duration {
45
+ if c . claims == nil || c . claims . DefaultTLSDur == nil {
46
+ return c . global . DefaultTLSDur . Duration
33
47
}
34
- return pc .DefaultTLSDur .Duration
48
+ return c . claims .DefaultTLSDur .Duration
35
49
}
36
50
37
51
// MinTLSCertDuration returns the minimum TLS cert duration for the provisioner.
38
52
// If the minimum is not set within the provisioner, then the global
39
53
// minimum from the authority configuration will be used.
40
- func (pc * Claims ) MinTLSCertDuration () time.Duration {
41
- if pc . MinTLSDur == nil || pc . MinTLSDur . Duration == 0 {
42
- return pc . globalClaims . MinTLSCertDuration ()
54
+ func (c * Claimer ) MinTLSCertDuration () time.Duration {
55
+ if c . claims == nil || c . claims . MinTLSDur == nil {
56
+ return c . global . MinTLSDur . Duration
43
57
}
44
- return pc .MinTLSDur .Duration
58
+ return c . claims .MinTLSDur .Duration
45
59
}
46
60
47
61
// MaxTLSCertDuration returns the maximum TLS cert duration for the provisioner.
48
62
// If the maximum is not set within the provisioner, then the global
49
63
// maximum from the authority configuration will be used.
50
- func (pc * Claims ) MaxTLSCertDuration () time.Duration {
51
- if pc . MaxTLSDur == nil || pc . MaxTLSDur . Duration == 0 {
52
- return pc . globalClaims . MaxTLSCertDuration ()
64
+ func (c * Claimer ) MaxTLSCertDuration () time.Duration {
65
+ if c . claims == nil || c . claims . MaxTLSDur == nil {
66
+ return c . global . MaxTLSDur . Duration
53
67
}
54
- return pc .MaxTLSDur .Duration
68
+ return c . claims .MaxTLSDur .Duration
55
69
}
56
70
57
71
// IsDisableRenewal returns if the renewal flow is disabled for the
58
72
// provisioner. If the property is not set within the provisioner, then the
59
73
// global value from the authority configuration will be used.
60
- func (pc * Claims ) IsDisableRenewal () bool {
61
- if pc .DisableRenewal == nil {
62
- return pc . globalClaims . IsDisableRenewal ()
74
+ func (c * Claimer ) IsDisableRenewal () bool {
75
+ if c . claims == nil || c . claims .DisableRenewal == nil {
76
+ return * c . global . DisableRenewal
63
77
}
64
- return * pc .DisableRenewal
78
+ return * c . claims .DisableRenewal
65
79
}
66
80
67
81
// Validate validates and modifies the Claims with default values.
68
- func (pc * Claims ) Validate () error {
82
+ func (c * Claimer ) Validate () error {
69
83
var (
70
- min = pc .MinTLSCertDuration ()
71
- max = pc .MaxTLSCertDuration ()
72
- def = pc .DefaultTLSCertDuration ()
84
+ min = c .MinTLSCertDuration ()
85
+ max = c .MaxTLSCertDuration ()
86
+ def = c .DefaultTLSCertDuration ()
73
87
)
74
88
switch {
75
- case min = = 0 :
76
- return errors .Errorf ("claims: MinTLSCertDuration cannot be empty " )
77
- case max = = 0 :
78
- return errors .Errorf ("claims: MaxTLSCertDuration cannot be empty " )
79
- case def = = 0 :
80
- return errors .Errorf ("claims: DefaultTLSCertDuration cannot be empty " )
89
+ case min < = 0 :
90
+ return errors .Errorf ("claims: MinTLSCertDuration must be greater than 0 " )
91
+ case max < = 0 :
92
+ return errors .Errorf ("claims: MaxTLSCertDuration must be greater than 0 " )
93
+ case def < = 0 :
94
+ return errors .Errorf ("claims: DefaultTLSCertDuration must be greater than 0 " )
81
95
case max < min :
82
96
return errors .Errorf ("claims: MaxCertDuration cannot be less " +
83
97
"than MinCertDuration: MaxCertDuration - %v, MinCertDuration - %v" , max , min )
0 commit comments