66 "bytes"
77 "context"
88 "crypto/tls"
9+ "crypto/x509"
10+ "encoding/base64"
911 "encoding/json"
1012 "fmt"
1113 "io"
@@ -32,20 +34,22 @@ type Client struct {
3234 DefaultBlockSize int64
3335 DebugTraceFlags map [string ]bool
3436 AccountID int64
37+ httpClient * http.Client
3538}
3639
3740// Config holds the configuration data for the Client to communicate with a SolidFire storage system
3841type Config struct {
39- TenantName string
40- EndPoint string
41- MountPoint string
42- SVIP string
43- InitiatorIFace string // iface to use of iSCSI initiator
44- Types * []VolType
45- LegacyNamePrefix string
46- AccessGroups []int64
47- DefaultBlockSize int64
48- DebugTraceFlags map [string ]bool
42+ TenantName string
43+ EndPoint string
44+ MountPoint string
45+ SVIP string
46+ InitiatorIFace string // iface to use of iSCSI initiator
47+ Types * []VolType
48+ LegacyNamePrefix string
49+ AccessGroups []int64
50+ DefaultBlockSize int64
51+ DebugTraceFlags map [string ]bool
52+ TrustedCACertificate string
4953}
5054
5155// VolType holds quality of service configuration data
@@ -56,6 +60,25 @@ type VolType struct {
5660
5761// NewFromParameters is a factory method to create a new sfapi.Client object using the supplied parameters
5862func NewFromParameters (pendpoint , psvip string , pcfg Config ) (c * Client , err error ) {
63+ tcfg := tls.Config {MinVersion : tridentconfig .MinClientTLSVersion , InsecureSkipVerify : true }
64+ if pcfg .TrustedCACertificate != "" {
65+ caCert , err := base64 .StdEncoding .DecodeString (pcfg .TrustedCACertificate )
66+ if err != nil {
67+ return nil , err
68+ }
69+ caCertPool := x509 .NewCertPool ()
70+ if ! caCertPool .AppendCertsFromPEM (caCert ) {
71+ return nil , fmt .Errorf ("failed to append CA certificate, certificate may be invalid or malformed" )
72+ }
73+ tcfg .RootCAs = caCertPool
74+ tcfg .InsecureSkipVerify = false
75+ }
76+ httpClient := & http.Client {
77+ Transport : & http.Transport {
78+ TLSClientConfig : & tcfg ,
79+ },
80+ Timeout : tridentconfig .StorageAPITimeoutSeconds * time .Second ,
81+ }
5982 SFClient := & Client {
6083 Endpoint : pendpoint ,
6184 SVIP : psvip ,
@@ -64,6 +87,7 @@ func NewFromParameters(pendpoint, psvip string, pcfg Config) (c *Client, err err
6487 VolumeTypes : pcfg .Types ,
6588 DefaultBlockSize : pcfg .DefaultBlockSize ,
6689 DebugTraceFlags : pcfg .DebugTraceFlags ,
90+ httpClient : httpClient ,
6791 }
6892 return SFClient , nil
6993}
@@ -104,14 +128,7 @@ func (c *Client) Request(ctx context.Context, method string, params interface{},
104128 c .Config .DebugTraceFlags ["api" ])
105129
106130 // Send the request
107- tr := & http.Transport {
108- TLSClientConfig : & tls.Config {InsecureSkipVerify : true , MinVersion : tridentconfig .MinClientTLSVersion },
109- }
110- httpClient := & http.Client {
111- Transport : tr ,
112- Timeout : tridentconfig .StorageAPITimeoutSeconds * time .Second ,
113- }
114- response , err = httpClient .Do (request )
131+ response , err = c .httpClient .Do (request )
115132 if err != nil {
116133 Logc (ctx ).Errorf ("Error response from SolidFire API request: %v" , err )
117134 return nil , errors .New ("device API error" )
0 commit comments