-
Notifications
You must be signed in to change notification settings - Fork 578
/
bucket_client.go
40 lines (36 loc) · 1.26 KB
/
bucket_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
33
34
35
36
37
38
39
40
package cos
import (
"github.com/go-kit/log"
"github.com/prometheus/common/model"
"github.com/thanos-io/objstore"
"github.com/thanos-io/objstore/exthttp"
"github.com/thanos-io/objstore/providers/cos"
"gopkg.in/yaml.v3"
)
// NewBucketClient creates a bucket client for COS
func NewBucketClient(cfg Config, name string, logger log.Logger) (objstore.Bucket, error) {
bucketConfig := &cos.Config{
Bucket: cfg.Bucket,
Region: cfg.Region,
AppId: cfg.AppID,
Endpoint: cfg.Endpoint,
SecretKey: cfg.SecretKey,
SecretId: cfg.SecretID,
HTTPConfig: exthttp.HTTPConfig{
IdleConnTimeout: model.Duration(cfg.HTTP.IdleConnTimeout),
ResponseHeaderTimeout: model.Duration(cfg.HTTP.ResponseHeaderTimeout),
InsecureSkipVerify: cfg.HTTP.InsecureSkipVerify,
TLSHandshakeTimeout: model.Duration(cfg.HTTP.TLSHandshakeTimeout),
ExpectContinueTimeout: model.Duration(cfg.HTTP.ExpectContinueTimeout),
MaxIdleConns: cfg.HTTP.MaxIdleConns,
MaxIdleConnsPerHost: cfg.HTTP.MaxIdleConnsPerHost,
MaxConnsPerHost: cfg.HTTP.MaxConnsPerHost,
Transport: cfg.HTTP.Transport,
},
}
serializedConfig, err := yaml.Marshal(bucketConfig)
if err != nil {
return nil, err
}
return cos.NewBucket(logger, serializedConfig, name)
}