2015-10-26 15:45:48 +01:00
|
|
|
package vcd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
2015-11-06 11:19:59 +01:00
|
|
|
"github.com/hmrc/vmware-govcd"
|
2015-10-26 15:45:48 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2015-12-07 22:24:34 +01:00
|
|
|
User string
|
|
|
|
Password string
|
|
|
|
Org string
|
|
|
|
Href string
|
|
|
|
VDC string
|
2015-11-19 00:56:17 +01:00
|
|
|
MaxRetryTimeout int
|
2016-01-24 20:25:41 +01:00
|
|
|
InsecureFlag bool
|
2015-10-26 15:45:48 +01:00
|
|
|
}
|
|
|
|
|
2015-11-19 00:56:17 +01:00
|
|
|
type VCDClient struct {
|
|
|
|
*govcd.VCDClient
|
|
|
|
MaxRetryTimeout int
|
2016-01-24 20:25:41 +01:00
|
|
|
InsecureFlag bool
|
2015-11-19 00:56:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) Client() (*VCDClient, error) {
|
2015-10-26 15:45:48 +01:00
|
|
|
u, err := url.ParseRequestURI(c.Href)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Something went wrong: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-11-19 00:56:17 +01:00
|
|
|
vcdclient := &VCDClient{
|
2016-01-24 20:25:41 +01:00
|
|
|
govcd.NewVCDClient(*u, c.InsecureFlag),
|
|
|
|
c.MaxRetryTimeout, c.InsecureFlag}
|
2015-10-26 15:45:48 +01:00
|
|
|
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
|
|
|
|
}
|