-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
32 lines (28 loc) · 918 Bytes
/
client.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
package aliyun
import (
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
"github.com/fimreal/goutils/ezap"
"github.com/spf13/viper"
)
type AliyunAccessKey struct {
ACCESS_KEY_ID string
ACCESS_KEY_SECRET string
REGION_ID string
}
var ak = &AliyunAccessKey{}
func NewClient() *ecs.Client {
ak = &AliyunAccessKey{
REGION_ID: viper.GetString("aliyun.regionid"),
ACCESS_KEY_ID: viper.GetString("aliyun.akid"),
ACCESS_KEY_SECRET: viper.GetString("aliyun.aksecret"),
}
ezap.Debugf("获取 阿里云 ecs 连接配置,ACCESS_KEY_ID: %s,ACCESS_KEY_SECRET: ***,REGION_ID: %s", ak.ACCESS_KEY_ID, ak.REGION_ID)
client, err := ecs.NewClientWithAccessKey(ak.REGION_ID, ak.ACCESS_KEY_ID, ak.ACCESS_KEY_SECRET)
if err != nil {
ezap.Fatal(err.Error())
}
if viper.GetBool("aliyun.insecureskipverify") {
client.SetHTTPSInsecure(true) // 跳过证书验证
}
return client
}