From d1aaf91f8adce949447ae65c2caa4c92a0e688ff Mon Sep 17 00:00:00 2001 From: Congqi Xia Date: Thu, 22 Aug 2024 19:20:28 +0800 Subject: [PATCH] enhance: Support Tencent myqcloud as OSS source Add tencent myqcloud support with `tke` & `cvm` credential Signed-off-by: Congqi Xia --- oss/minio.go | 9 ++++++--- oss/tencent.go | 11 ++++++++--- states/scan_binlog.go | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/oss/minio.go b/oss/minio.go index fd3e8f6..dc11c14 100644 --- a/oss/minio.go +++ b/oss/minio.go @@ -47,6 +47,7 @@ func NewMinioClient(ctx context.Context, p MinioClientParam) (*MinioClient, erro } endpoint := fmt.Sprintf("%s:%s", p.Addr, p.Port) + var err error switch p.CloudProvider { case CloudProviderAWS: processMinioAwsOptions(p, opts) @@ -59,15 +60,17 @@ func NewMinioClient(ctx context.Context, p MinioClientParam) (*MinioClient, erro case CloudProviderAliyun: processMinioAliyunOptions(p, opts) case CloudProviderTencent: - // processMinioTencentOptions(p, opts) - // cos address issue WIP - fallthrough + err = processMinioTencentOptions(p, opts) case CloudProviderAzure: // TODO support azure fallthrough default: return nil, errors.Newf("Cloud provider %s not supported yet", p.CloudProvider) } + if err != nil { + return nil, err + } + fmt.Printf("Start to connect to oss endpoind: %s\n", endpoint) client, err := minio.New(endpoint, opts) if err != nil { diff --git a/oss/tencent.go b/oss/tencent.go index 1b76ed5..644f4d9 100644 --- a/oss/tencent.go +++ b/oss/tencent.go @@ -31,11 +31,16 @@ type TencentCredentialProvider struct { } func NewTencentCredentialProvider() (minioCred.Provider, error) { - provider, err := common.DefaultTkeOIDCRoleArnProvider() - if err != nil { - return nil, errors.Wrap(err, "failed to create tencent credential provider") + var provider interface { + GetCredential() (common.CredentialIface, error) } + var err error + provider, err = common.DefaultTkeOIDCRoleArnProvider() + if err != nil { + // try cvm role provider + provider = common.DefaultCvmRoleProvider() + } cred, err := provider.GetCredential() if err != nil { return nil, errors.Wrap(err, "failed to get tencent credential") diff --git a/states/scan_binlog.go b/states/scan_binlog.go index 85befb4..782d46b 100644 --- a/states/scan_binlog.go +++ b/states/scan_binlog.go @@ -64,6 +64,7 @@ func (s *InstanceState) ScanBinlogCommand(ctx context.Context, p *ScanBinlogPara minioClient, bucketName, rootPath, err := s.GetMinioClientFromCfg(ctx, p.MinioAddress) if err != nil { fmt.Println("Failed to create folder,", err.Error()) + return err } fmt.Printf("=== start to execute \"%s\" task with filter expresion: \"%s\" ===\n", p.Action, p.Expr) @@ -161,7 +162,7 @@ func (s *InstanceState) ScanBinlogCommand(ctx context.Context, p *ScanBinlogPara switch strings.ToLower(p.Action) { case "count": - fmt.Printf("Total %d entries found", count) + fmt.Printf("Total %d entries found\n", count) case "dedup": total := len(dedupResult) fmt.Printf("%d duplicated entries found\n", total)