-
Notifications
You must be signed in to change notification settings - Fork 36
/
option.go
169 lines (144 loc) · 4.75 KB
/
option.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package bmclib
import (
"context"
"crypto/x509"
"net/http"
"time"
"github.com/bmc-toolbox/bmclib/v2/internal/httpclient"
"github.com/bmc-toolbox/bmclib/v2/providers/rpc"
"github.com/go-logr/logr"
"github.com/jacobweinstock/registrar"
oteltrace "go.opentelemetry.io/otel/trace"
)
// Option for setting optional Client values
type Option func(*Client)
// WithLogger sets the logger
func WithLogger(logger logr.Logger) Option {
return func(args *Client) { args.Logger = logger }
}
// WithRegistry sets the Registry
func WithRegistry(registry *registrar.Registry) Option {
return func(args *Client) { args.Registry = registry }
}
// WithSecureTLS enforces trusted TLS connections, with an optional CA certificate pool.
// Using this option with an nil pool uses the system CAs.
func WithSecureTLS(rootCAs *x509.CertPool) Option {
return func(args *Client) {
args.httpClientSetupFuncs = append(args.httpClientSetupFuncs, httpclient.SecureTLSOption(rootCAs))
}
}
// WithHTTPClient sets an http client
func WithHTTPClient(c *http.Client) Option {
return func(args *Client) {
args.httpClient = c
}
}
// WithPerProviderTimeout sets the timeout when interacting with a BMC.
// This timeout value is applied per provider.
// When not defined and a context with a timeout is passed to a method, the default timeout
// will be the context timeout duration divided by the number of providers in the registry,
// meaning, the len(Client.Registry.Drivers).
// If this per provider timeout is not defined and no context timeout is defined,
// the defaultConnectTimeout is used.
func WithPerProviderTimeout(timeout time.Duration) Option {
return func(args *Client) {
args.perProviderTimeout = func(context.Context) time.Duration { return timeout }
}
}
func WithIpmitoolCipherSuite(cipherSuite string) Option {
return func(args *Client) {
args.providerConfig.ipmitool.CipherSuite = cipherSuite
}
}
func WithIpmitoolPort(port string) Option {
return func(args *Client) {
args.providerConfig.ipmitool.Port = port
}
}
func WithIpmitoolPath(path string) Option {
return func(args *Client) {
args.providerConfig.ipmitool.IpmitoolPath = path
}
}
func WithAsrockrackHTTPClient(httpClient *http.Client) Option {
return func(args *Client) {
args.providerConfig.asrock.HttpClient = httpClient
}
}
func WithAsrockrackPort(port string) Option {
return func(args *Client) {
args.providerConfig.asrock.Port = port
}
}
func WithRedfishHTTPClient(httpClient *http.Client) Option {
return func(args *Client) {
args.providerConfig.gofish.HttpClient = httpClient
}
}
func WithRedfishPort(port string) Option {
return func(args *Client) {
args.providerConfig.gofish.Port = port
}
}
// WithRedfishVersionsNotCompatible sets the list of incompatible redfish versions.
//
// With this option set, The bmclib.Registry.FilterForCompatible(ctx) method will not proceed on
// devices with the given redfish version(s).
func WithRedfishVersionsNotCompatible(versions []string) Option {
return func(args *Client) {
args.providerConfig.gofish.VersionsNotCompatible = append(args.providerConfig.gofish.VersionsNotCompatible, versions...)
}
}
func WithRedfishUseBasicAuth(useBasicAuth bool) Option {
return func(args *Client) {
args.providerConfig.gofish.UseBasicAuth = useBasicAuth
}
}
func WithRedfishEtagMatchDisabled(d bool) Option {
return func(args *Client) {
args.providerConfig.gofish.DisableEtagMatch = d
}
}
func WithRedfishSystemName(name string) Option {
return func(args *Client) {
args.providerConfig.gofish.SystemName = name
}
}
func WithIntelAMTHostScheme(hostScheme string) Option {
return func(args *Client) {
args.providerConfig.intelamt.HostScheme = hostScheme
}
}
func WithIntelAMTPort(port uint32) Option {
return func(args *Client) {
args.providerConfig.intelamt.Port = port
}
}
// WithDellRedfishVersionsNotCompatible sets the list of incompatible redfish versions.
//
// With this option set, The bmclib.Registry.FilterForCompatible(ctx) method will not proceed on
// devices with the given redfish version(s).
func WithDellRedfishVersionsNotCompatible(versions []string) Option {
return func(args *Client) {
args.providerConfig.dell.VersionsNotCompatible = append(args.providerConfig.dell.VersionsNotCompatible, versions...)
}
}
func WithDellRedfishUseBasicAuth(useBasicAuth bool) Option {
return func(args *Client) {
args.providerConfig.dell.UseBasicAuth = useBasicAuth
}
}
func WithRPCOpt(opt rpc.Provider) Option {
return func(args *Client) {
args.providerConfig.rpc = opt
}
}
// WithTracerProvider specifies a tracer provider to use for creating a tracer.
// If none is specified a noop tracerprovider is used.
func WithTracerProvider(provider oteltrace.TracerProvider) Option {
return func(args *Client) {
if provider != nil {
args.traceprovider = provider
}
}
}