-
Notifications
You must be signed in to change notification settings - Fork 4
/
control_options.go
93 lines (81 loc) · 1.9 KB
/
control_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) Jim Lambert
// SPDX-License-Identifier: MIT
package gldap
type controlOptions struct {
withGrace int
withExpire int
withErrorCode int
withCriticality bool
withControlValue string
// test options
withTestType string
withTestToString string
}
func controlDefaults() controlOptions {
return controlOptions{
withGrace: -1,
withExpire: -1,
withErrorCode: -1,
}
}
func getControlOpts(opt ...Option) controlOptions {
opts := controlDefaults()
applyOpts(&opts, opt...)
return opts
}
// WithGraceAuthNsRemaining specifies the number of grace authentication
// remaining.
func WithGraceAuthNsRemaining(remaining uint) Option {
return func(o interface{}) {
if o, ok := o.(*controlOptions); ok {
o.withGrace = int(remaining)
}
}
}
// WithSecondsBeforeExpiration specifies the number of seconds before a password
// will expire
func WithSecondsBeforeExpiration(seconds uint) Option {
return func(o interface{}) {
if o, ok := o.(*controlOptions); ok {
o.withExpire = int(seconds)
}
}
}
// WithErrorCode specifies the error code
func WithErrorCode(code uint) Option {
return func(o interface{}) {
if o, ok := o.(*controlOptions); ok {
o.withErrorCode = int(code)
}
}
}
// WithCriticality specifies the criticality
func WithCriticality(criticality bool) Option {
return func(o interface{}) {
if o, ok := o.(*controlOptions); ok {
o.withCriticality = criticality
}
}
}
// WithControlValue specifies the control value
func WithControlValue(value string) Option {
return func(o interface{}) {
if o, ok := o.(*controlOptions); ok {
o.withControlValue = value
}
}
}
func withTestType(s string) Option {
return func(o interface{}) {
if o, ok := o.(*controlOptions); ok {
o.withTestType = s
}
}
}
func withTestToString(s string) Option {
return func(o interface{}) {
if o, ok := o.(*controlOptions); ok {
o.withTestToString = s
}
}
}