2021-07-28 18:03:19 +08:00
|
|
|
package entity
|
|
|
|
|
|
|
|
|
|
import (
|
2024-10-16 17:24:50 +08:00
|
|
|
"mayfly-go/internal/common/utils"
|
2023-10-27 17:41:45 +08:00
|
|
|
"mayfly-go/internal/redis/rdm"
|
2024-04-13 17:01:12 +08:00
|
|
|
tagentity "mayfly-go/internal/tag/domain/entity"
|
2024-10-16 17:24:50 +08:00
|
|
|
"mayfly-go/pkg/logx"
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/pkg/model"
|
2023-10-27 17:41:45 +08:00
|
|
|
"mayfly-go/pkg/utils/structx"
|
2021-07-28 18:03:19 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Redis struct {
|
|
|
|
|
model.Model
|
|
|
|
|
|
2025-02-13 21:11:23 +08:00
|
|
|
Code string `json:"code" gorm:"size:32;not null;"` // code
|
|
|
|
|
Name string `json:"name" gorm:"size:255;not null;"` // 名称
|
|
|
|
|
Host string `json:"host" gorm:"size:255;not null;"` // 主机地址
|
|
|
|
|
Mode string `json:"mode" gorm:"size:32;"` // 模式
|
|
|
|
|
Db string `json:"db" gorm:"size:64;comment:库号: 多个库用,分割"` // 库号: 多个库用,分割
|
|
|
|
|
SshTunnelMachineId int `json:"sshTunnelMachineId" gorm:"comment:ssh隧道的机器id"` // ssh隧道机器id
|
|
|
|
|
Remark string `json:"remark" gorm:"size:255;"`
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
2022-07-10 12:14:06 +08:00
|
|
|
|
2024-01-05 08:55:34 +08:00
|
|
|
// ToRedisInfo 转换为redisInfo进行连接
|
2024-04-13 17:01:12 +08:00
|
|
|
func (r *Redis) ToRedisInfo(db int, authCert *tagentity.ResourceAuthCert, tagPath ...string) *rdm.RedisInfo {
|
2023-10-27 17:41:45 +08:00
|
|
|
redisInfo := new(rdm.RedisInfo)
|
2024-01-05 08:55:34 +08:00
|
|
|
_ = structx.Copy(redisInfo, r)
|
2024-04-13 17:01:12 +08:00
|
|
|
redisInfo.Username = authCert.Username
|
|
|
|
|
redisInfo.Password = authCert.Ciphertext
|
2023-10-27 17:41:45 +08:00
|
|
|
redisInfo.Db = db
|
2024-05-08 21:04:25 +08:00
|
|
|
redisInfo.CodePath = tagPath
|
2024-10-16 17:24:50 +08:00
|
|
|
|
|
|
|
|
if redisInfo.Mode == rdm.SentinelMode {
|
|
|
|
|
// // 密码替换为解密后的密码
|
|
|
|
|
password, err := utils.PwdAesDecrypt(authCert.GetExtraString("redisNodePassword"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
logx.Errorf("redis节点密码解密失败: %s", err.Error())
|
|
|
|
|
} else {
|
|
|
|
|
redisInfo.RedisNodePassword = password
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 17:41:45 +08:00
|
|
|
return redisInfo
|
|
|
|
|
}
|