Skip to content

Commit 615b500

Browse files
committed
feat(tencent): add demo replay support
1 parent 8e2ac04 commit 615b500

9 files changed

Lines changed: 1715 additions & 11 deletions

File tree

pkg/providers/providers.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111
"github.com/404tk/cloudtoolkit/pkg/providers/gcp"
1212
"github.com/404tk/cloudtoolkit/pkg/providers/huawei"
1313
"github.com/404tk/cloudtoolkit/pkg/providers/jdcloud"
14-
demoreplay "github.com/404tk/cloudtoolkit/pkg/providers/replay"
14+
"github.com/404tk/cloudtoolkit/pkg/providers/replay"
1515
"github.com/404tk/cloudtoolkit/pkg/providers/tencent"
16+
txreplay "github.com/404tk/cloudtoolkit/pkg/providers/tencent/replay"
1617
"github.com/404tk/cloudtoolkit/pkg/providers/volcengine"
1718
volcreplay "github.com/404tk/cloudtoolkit/pkg/providers/volcengine/replay"
1819
"github.com/404tk/cloudtoolkit/pkg/schema"
@@ -32,7 +33,7 @@ var catalog = []entry{
3233
{
3334
info: Info{Name: "alibaba", Desc: "Alibaba Cloud"},
3435
new: func(block schema.Options) (schema.Provider, error) {
35-
if demoreplay.IsActiveForProvider("alibaba") {
36+
if replay.IsActiveForProvider("alibaba") {
3637
return alibaba.NewWithConfig(block, alireplay.ClientConfig())
3738
}
3839
return alibaba.New(block)
@@ -47,6 +48,9 @@ var catalog = []entry{
4748
{
4849
info: Info{Name: "tencent", Desc: "Tencent Cloud"},
4950
new: func(block schema.Options) (schema.Provider, error) {
51+
if replay.IsActiveForProvider("tencent") {
52+
return tencent.NewWithConfig(block, txreplay.ClientConfig())
53+
}
5054
return tencent.New(block)
5155
},
5256
},
@@ -65,7 +69,7 @@ var catalog = []entry{
6569
{
6670
info: Info{Name: "volcengine", Desc: "Volcengine"},
6771
new: func(block schema.Options) (schema.Provider, error) {
68-
if demoreplay.IsActiveForProvider("volcengine") {
72+
if replay.IsActiveForProvider("volcengine") {
6973
return volcengine.NewWithConfig(block, volcreplay.ClientConfig())
7074
}
7175
return volcengine.New(block)

pkg/providers/replay/replay.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ var providers = map[string]providerMeta{
5252
"instance-cmd-check",
5353
},
5454
},
55+
"tencent": {
56+
Credentials: Credentials{
57+
AccessKey: "AKIDz8krbsJ5yKBZQpn74WFkmLPx3EXAMPLE",
58+
SecretKey: "Gu5t9xGARNpq86cd98joQYCN3EXAMPLE",
59+
},
60+
Payloads: []string{
61+
"cloudlist",
62+
"iam-user-check",
63+
"bucket-check",
64+
"instance-cmd-check",
65+
},
66+
},
5567
}
5668

5769
func Enable(provider string) {

pkg/providers/tencent/cos/bucket.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@ import (
99
)
1010

1111
type Driver struct {
12-
Credential auth.Credential
13-
Client *Client
12+
Credential auth.Credential
13+
Client *Client
14+
clientOptions []Option
15+
}
16+
17+
// NewDriver creates a COS driver with optional client injections.
18+
func NewDriver(cred auth.Credential, opts ...Option) *Driver {
19+
return &Driver{
20+
Credential: cred,
21+
clientOptions: append([]Option(nil), opts...),
22+
}
23+
}
24+
25+
// SetClientOptions replaces the client options used by lazy client creation.
26+
func (d *Driver) SetClientOptions(opts ...Option) {
27+
d.clientOptions = append([]Option(nil), opts...)
1428
}
1529

1630
func (d *Driver) client() *Client {
1731
if d.Client == nil {
18-
d.Client = NewClient(d.Credential)
32+
d.Client = NewClient(d.Credential, d.clientOptions...)
1933
}
2034
return d.Client
2135
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package replay
2+
3+
import (
4+
"github.com/404tk/cloudtoolkit/pkg/providers/tencent"
5+
"github.com/404tk/cloudtoolkit/pkg/providers/tencent/api"
6+
"github.com/404tk/cloudtoolkit/pkg/providers/tencent/cos"
7+
)
8+
9+
func ClientConfig() tencent.ClientConfig {
10+
httpClient := replayHTTPClient()
11+
return tencent.ClientConfig{
12+
APIOptions: []api.Option{api.WithHTTPClient(httpClient)},
13+
COSOptions: []cos.Option{cos.WithHTTPClient(httpClient)},
14+
SkipCredentialCache: true,
15+
}
16+
}

0 commit comments

Comments
 (0)