forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
42 lines (36 loc) · 887 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"
govcd "github.com/ukcloud/govcloudair" // Forked from vmware/govcloudair
)
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
}