-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
41 lines (31 loc) · 851 Bytes
/
client.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
package proxmox
import (
"crypto/tls"
"errors"
"fmt"
pxapi "github.com/Telmate/proxmox-api-go/proxmox"
)
type proxmoxClient struct {
*pxapi.Client
}
func newClient(config *proxmoxConfig) (*proxmoxClient, error) {
if config == nil {
return nil, errors.New("client configuration was nil")
}
if config.ApiTokenID == "" {
return nil, errors.New("client api token was not defined")
}
fullToken := fmt.Sprintf("%s@%s!%s", config.User, config.Realm, config.ApiTokenID)
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
}
if !config.SkipCertValidation {
tlsConfig = nil
}
c, err := pxapi.NewClient(config.ApiURL, nil, config.HTTPHeaders, tlsConfig, config.ProxyServer, int(config.TaskTimeout.Seconds()))
if err != nil {
return nil, err
}
c.SetAPIToken(fullToken, config.ApiTokenSecret)
return &proxmoxClient{c}, nil
}