From bae9898d4b83aa0e651dcbc06bfd7c7fc0735c04 Mon Sep 17 00:00:00 2001 From: kobyt2 <68537607+kobyt2@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:54:04 +0800 Subject: [PATCH 1/3] Update config.go --- pkg/config/config.go | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 15a0906..770a03d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -85,6 +85,7 @@ var QcloudNamespace = []string{"COS", "CDN", "QAAP", "WAF"} type TencentCredential struct { AccessKey string `yaml:"access_key"` SecretKey string `yaml:"secret_key"` + EncryptionKey string `yaml:"encryption_key"` Role string `yaml:"role"` Region string `yaml:"region"` Token string `yaml:"token"` @@ -156,21 +157,37 @@ func NewConfig() *TencentConfig { } func (c *TencentConfig) LoadFile(filename string) error { - c.Filename = filename - content, err := ioutil.ReadFile(c.Filename) - if err != nil { - return err - } - if err = yaml.UnmarshalStrict(content, c); err != nil { - return err - } - if err = c.check(); err != nil { - return err - } - c.fillDefault() - return nil + c.Filename = filename + content, err := ioutil.ReadFile(c.Filename) + if err != nil { + return err + } + + // 解析 YAML 文件 + if err = yaml.UnmarshalStrict(content, c); err != nil { + return err + } + + // 假设加密密钥存储在 YAML 中 + crypto := aes.NewCryptoDB(c.Credential.EncryptionKey) // 直接读取配置中的密钥 + + // 解密 access_key 和 secret_key + decryptedAccessKey := crypto.Decrypt(c.Credential.AccessKey) + decryptedSecretKey := crypto.Decrypt(c.Credential.SecretKey) + + c.Credential.AccessKey = decryptedAccessKey + c.Credential.SecretKey = decryptedSecretKey + + // 检查配置文件是否合法 + if err = c.check(); err != nil { + return err + } + + c.fillDefault() + return nil } + func (c *TencentConfig) check() (err error) { if c.Credential.AccessKey == "" { c.Credential.AccessKey = os.Getenv(EnvAccessKey) From d1494e0a5610f916277fddc71190a0c24d537062 Mon Sep 17 00:00:00 2001 From: kobyt2 <68537607+kobyt2@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:56:08 +0800 Subject: [PATCH 2/3] Update config.go --- pkg/config/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index 770a03d..8f9ff18 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -9,6 +9,7 @@ import ( "github.com/tencentyun/tencentcloud-exporter/pkg/constant" "github.com/tencentyun/tencentcloud-exporter/pkg/util" "gopkg.in/yaml.v2" + "github.com/kobyt2/common-services/utils/aes" ) const ( From 82a1022c5a06d3ef62fb11631f5403baa32bb3c5 Mon Sep 17 00:00:00 2001 From: kobyt2 <68537607+kobyt2@users.noreply.github.com> Date: Fri, 29 Aug 2025 11:28:58 +0800 Subject: [PATCH 3/3] Update repository_redis.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改redis 状态参数 问题 --- pkg/instance/repository_redis.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/instance/repository_redis.go b/pkg/instance/repository_redis.go index df2b710..88e0c30 100644 --- a/pkg/instance/repository_redis.go +++ b/pkg/instance/repository_redis.go @@ -72,7 +72,13 @@ func (repo *RedisTcInstanceRepository) ListByFilters(filters map[string]string) var total int64 = -1 req.Offset = &offset req.Limit = &limit - req.Status = []*int64{common.Int64Ptr(2)} + req.Status = []*int64{ + common.Int64Ptr(0), // 待初始化 + common.Int64Ptr(1), // 初始化中 + common.Int64Ptr(2), // 运行中 +} + + // req.Status = []*int64{common.Int64Ptr(2)} getMoreInstances: resp, err := repo.client.DescribeInstances(req)