github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/builtin/providers/vcd/config.go (about) 1 package vcd 2 3 import ( 4 "fmt" 5 "net/url" 6 7 "github.com/hmrc/vmware-govcd" 8 ) 9 10 type Config struct { 11 User string 12 Password string 13 Org string 14 Href string 15 VDC string 16 MaxRetryTimeout int 17 InsecureFlag bool 18 } 19 20 type VCDClient struct { 21 *govcd.VCDClient 22 MaxRetryTimeout int 23 InsecureFlag bool 24 } 25 26 func (c *Config) Client() (*VCDClient, error) { 27 u, err := url.ParseRequestURI(c.Href) 28 if err != nil { 29 return nil, fmt.Errorf("Something went wrong: %s", err) 30 } 31 32 vcdclient := &VCDClient{ 33 govcd.NewVCDClient(*u, c.InsecureFlag), 34 c.MaxRetryTimeout, c.InsecureFlag} 35 org, vcd, err := vcdclient.Authenticate(c.User, c.Password, c.Org, c.VDC) 36 if err != nil { 37 return nil, fmt.Errorf("Something went wrong: %s", err) 38 } 39 vcdclient.Org = org 40 vcdclient.OrgVdc = vcd 41 return vcdclient, nil 42 }