Add option to enable TLS verification
This commit is contained in:
parent
2d68f5d5f7
commit
7d7b26b82c
|
@ -23,15 +23,17 @@ type Client struct {
|
||||||
Host string
|
Host string
|
||||||
Port int
|
Port int
|
||||||
ApiVersion int
|
ApiVersion int
|
||||||
|
TlsVerify bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(username, password, host string, port, apiversion int) *Client {
|
func NewClient(username, password, host string, port, apiversion int, tlsverify bool) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
Host: host,
|
Host: host,
|
||||||
Port: port,
|
Port: port,
|
||||||
ApiVersion: apiversion,
|
ApiVersion: apiversion,
|
||||||
|
TlsVerify: tlsverify,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +124,7 @@ func (s *Client) GetHttpClient() (*http.Client) {
|
||||||
// Ganeti often has a self-signed certificate that is used for the RAPI
|
// Ganeti often has a self-signed certificate that is used for the RAPI
|
||||||
// @TODO This should be configural
|
// @TODO This should be configural
|
||||||
tr := &http.Transport{
|
tr := &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: !s.TlsVerify},
|
||||||
}
|
}
|
||||||
return &http.Client{Transport: tr}
|
return &http.Client{Transport: tr}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,15 @@ func getTestClient(t *testing.T) *Client {
|
||||||
if version_error != nil {
|
if version_error != nil {
|
||||||
t.Errorf("Failed to convert '%v' to integer: %v", version, version_error)
|
t.Errorf("Failed to convert '%v' to integer: %v", version, version_error)
|
||||||
}
|
}
|
||||||
return NewClient(username, password, host, _port, _version)
|
tlsverify := os.Getenv("RAPI_TLS_VERIFY")
|
||||||
|
if len(tlsverify) == 0 {
|
||||||
|
tlsverify = "false"
|
||||||
|
}
|
||||||
|
_tlsverify, tlsverify_err := strconv.ParseBool(tlsverify)
|
||||||
|
if tlsverify_err != nil {
|
||||||
|
t.Errorf("Failed to convert '%v' to bool: %v'", tlsverify, tlsverify_err)
|
||||||
|
}
|
||||||
|
return NewClient(username, password, host, _port, _version, _tlsverify)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClusterInfo(t *testing.T) {
|
func TestClusterInfo(t *testing.T) {
|
||||||
|
@ -64,7 +72,7 @@ func TestGetNetworksBulk(t *testing.T) {
|
||||||
|
|
||||||
func TestGetNetworkInformation(t *testing.T) {
|
func TestGetNetworkInformation(t *testing.T) {
|
||||||
c := getTestClient(t)
|
c := getTestClient(t)
|
||||||
n, err := c.GetNetworks()
|
_, err := c.GetNetworks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got error requesting network list %s", err)
|
t.Errorf("Got error requesting network list %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue