forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
42 lines (36 loc) · 845 Bytes
/
config.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
package vcd
import (
"fmt"
"net/url"
"github.com/hmrc/vmware-govcd"
)
type Config struct {
User string
Password string
Org string
Href string
VDC string
MaxRetryTimeout int
InsecureFlag bool
}
type VCDClient struct {
*govcd.VCDClient
MaxRetryTimeout int
InsecureFlag bool
}
func (c *Config) Client() (*VCDClient, error) {
u, err := url.ParseRequestURI(c.Href)
if err != nil {
return nil, fmt.Errorf("Something went wrong: %s", err)
}
vcdclient := &VCDClient{
govcd.NewVCDClient(*u, c.InsecureFlag),
c.MaxRetryTimeout, c.InsecureFlag}
org, vcd, err := vcdclient.Authenticate(c.User, c.Password, c.Org, c.VDC)
if err != nil {
return nil, fmt.Errorf("Something went wrong: %s", err)
}
vcdclient.Org = org
vcdclient.OrgVdc = vcd
return vcdclient, nil
}