Skip to content

Commit c57d309

Browse files
author
jojoliang
committed
update crypto kms endpoint
1 parent 49c83ae commit c57d309

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

crypto/master_kms_cipher.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/tencentyun/cos-go-sdk-v5"
1212
)
1313

14-
const (
14+
var (
1515
KMSEndPoint = "kms.tencentcloudapi.com"
1616
)
1717

@@ -21,7 +21,15 @@ type MasterKMSCipher struct {
2121
MatDesc string
2222
}
2323

24-
func NewKMSClient(cred *cos.Credential, region string) (*kms.Client, error) {
24+
type KMSClientOptions = func(*profile.HttpProfile)
25+
26+
func KMSEndpoint(endpoint string) KMSClientOptions {
27+
return func(pf *profile.HttpProfile) {
28+
pf.Endpoint = endpoint
29+
}
30+
}
31+
32+
func NewKMSClient(cred *cos.Credential, region string, opt ...KMSClientOptions) (*kms.Client, error) {
2533
if cred == nil {
2634
fmt.Errorf("credential is nil")
2735
}
@@ -32,6 +40,10 @@ func NewKMSClient(cred *cos.Credential, region string) (*kms.Client, error) {
3240
)
3341
cpf := profile.NewClientProfile()
3442
cpf.HttpProfile.Endpoint = KMSEndPoint
43+
44+
for _, fn := range opt {
45+
fn(cpf.HttpProfile)
46+
}
3547
client, err := kms.NewClient(credential, region, cpf)
3648
return client, err
3749
}

example/crypto/crypto_sample.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func simple_put_object() {
7070
materialDesc := make(map[string]string)
7171
//materialDesc["desc"] = "material information of your master encrypt key"
7272

73-
// 创建KMS客户端
73+
// 创建KMS客户端, 可通过 coscrypto.KMSEndpoint 指定KMS域名
74+
// kmsclient, _ := coscrypto.NewKMSClient(c.GetCredential(), "ap-guangzhou", coscrypto.KMSEndpoint("kms.internal.tencentcloudapi.com"))
7475
kmsclient, _ := coscrypto.NewKMSClient(c.GetCredential(), "ap-guangzhou")
7576
// 创建KMS主加密密钥,标识信息和主密钥一一对应
7677
kmsID := os.Getenv("KMSID")

0 commit comments

Comments
 (0)