Skip to content

Commit 4bb66b2

Browse files
author
Peter Jönsson
committed
Add possibility to ignore certificate chains
For test installation of Cloudstack we might be running with a broken certificate. Add an option to pass through an option to TLS. Please note that this should only be used for testing. Also rename CloudStack to Cloudstack in all comments.
1 parent 708f07d commit 4bb66b2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

client.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gopherstack
33
import (
44
"crypto/hmac"
55
"crypto/sha1"
6+
"crypto/tls"
67
"encoding/base64"
78
"encoding/json"
89
"errors"
@@ -26,11 +27,12 @@ type CloudStackClient struct {
2627
Secret string
2728
}
2829

29-
// Creates a new client for communicating with CloudStack
30-
func (cloudstack CloudStackClient) New(apiurl string, apikey string, secret string) *CloudStackClient {
30+
// Creates a new client for communicating with Cloudstack
31+
func (cloudstack CloudStackClient) New(apiurl string, apikey string, secret string, insecureskipverify bool) *CloudStackClient {
3132
c := &CloudStackClient{
3233
client: &http.Client{
3334
Transport: &http.Transport{
35+
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureskipverify},
3436
Proxy: http.ProxyFromEnvironment,
3537
},
3638
},
@@ -50,9 +52,9 @@ func NewRequest(c CloudStackClient, request string, params url.Values) (interfac
5052

5153
// Generate signature for API call
5254
// * Serialize parameters and sort them by key, done by Encode()
53-
// * Use byte sequence for '+' character as CloudStack requires this
55+
// * Use byte sequence for '+' character as Cloudstack requires this
5456
// * Convert the entire argument string to lowercase
55-
// * Calculate HMAC SHA1 of argument string with CloudStack secret
57+
// * Calculate HMAC SHA1 of argument string with Cloudstack secret
5658
// * URL encode the string and convert to base64
5759
s := params.Encode()
5860
s2 := strings.Replace(s, "+", "%20", -1)
@@ -63,7 +65,7 @@ func NewRequest(c CloudStackClient, request string, params url.Values) (interfac
6365
signature = url.QueryEscape(signature)
6466

6567
// Create the final URL before we issue the request
66-
// For some reason CloudStack refuses to accept '+' as a space character so we byte escape it instead.
68+
// For some reason Cloudstack refuses to accept '+' as a space character so we byte escape it instead.
6769
url := c.BaseURL + "?" + s2 + "&signature=" + signature
6870

6971
log.Printf("Calling %s ", url)
@@ -79,7 +81,7 @@ func NewRequest(c CloudStackClient, request string, params url.Values) (interfac
7981
return nil, err
8082
}
8183

82-
log.Printf("response from cloudstack: %d - %s", resp.StatusCode, body)
84+
log.Printf("Response from Cloudstack: %d - %s", resp.StatusCode, body)
8385
if resp.StatusCode != 200 {
8486
err = errors.New(fmt.Sprintf("Received HTTP client/server error from CloudStack: %d", resp.StatusCode))
8587
return nil, err

0 commit comments

Comments
 (0)