-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
38 lines (34 loc) · 1.28 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package common
import (
"crypto/tls"
"net/http"
"strings"
"time"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/config"
)
// NewCustomClient creates a custom client assembled from user-provided endpoints.
// URLs will be assembled according to the endpoints array, separated each element by slashes.
// for example, array ["https://www.example.com", "v2", "test", ...] will form the address
// "https://www.example.com/v2/test/.../".
// NOTE: You can decide whether to skip the SSL certificate check with the insecure parameter.
func NewCustomClient(insecure bool, endpoints ...string) *golangsdk.ServiceClient {
p := new(golangsdk.ProviderClient)
p.HTTPClient = http.Client{
Transport: &config.LogRoundTripper{
Rt: &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
// The version fields of the TLS ver.1.2 and ver.1.3 are filled with 0x0303 (ver.1.2)
MinVersion: tls.VersionTLS12,
InsecureSkipVerify: insecure, // Pay attention to the security risks after skip verify.
},
},
},
Timeout: 30 * time.Minute,
}
return &golangsdk.ServiceClient{
ProviderClient: p,
ResourceBase: strings.Join(endpoints, "/") + "/",
}
}