@@ -227,29 +227,30 @@ func initConfigWithViperCtx(c *config) error {
227
227
certificateAuthorityData := viper .GetString ("certificate-authority-data" )
228
228
229
229
var (
230
- client metalgo.Client
231
- err error
232
- transport * http.Transport
230
+ client metalgo.Client
231
+ clientOptions []metalgo.ClientOption
232
+ err error
233
+ transport * http.Transport
233
234
)
234
235
235
- if certificateAuthorityData == "" {
236
- if hmacAuthType == "" {
237
- client , err = metalgo .NewClient (driverURL , metalgo .BearerToken (apiToken ), metalgo .HMACAuth (hmacKey , "Metal-Admin" ))
238
- } else {
239
- client , err = metalgo .NewClient (driverURL , metalgo .BearerToken (apiToken ), metalgo .HMACAuth (hmacKey , hmacAuthType ))
240
- }
241
- } else {
236
+ clientOptions = append (clientOptions , metalgo .BearerToken (apiToken ))
237
+
238
+ if certificateAuthorityData != "" {
242
239
transport , err = createTLSTransport (certificateAuthorityData )
243
240
if err != nil {
244
241
return err
245
242
}
246
243
247
- if hmacAuthType == "" {
248
- client , err = metalgo .NewClient (driverURL , metalgo .BearerToken (apiToken ), metalgo .HMACAuth (hmacKey , "Metal-Admin" ), metalgo .Transport (transport ))
249
- } else {
250
- client , err = metalgo .NewClient (driverURL , metalgo .BearerToken (apiToken ), metalgo .HMACAuth (hmacKey , hmacAuthType ), metalgo .Transport (transport ))
251
- }
244
+ clientOptions = append (clientOptions , metalgo .Transport (transport ))
252
245
}
246
+
247
+ if hmacAuthType != "" {
248
+ clientOptions = append (clientOptions , metalgo .HMACAuth (hmacKey , hmacAuthType ))
249
+ } else {
250
+ clientOptions = append (clientOptions , metalgo .HMACAuth (hmacKey , "Metal-Admin" ))
251
+ }
252
+
253
+ client , err = metalgo .NewClient (driverURL , clientOptions ... )
253
254
if err != nil {
254
255
return err
255
256
}
0 commit comments