mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 07:50:25 +08:00
* fix: 保存 LastResult 时截断字符串过长部分,以避免数据库报错 * refactor: 新增 entity.DbTaskBase 和 persistence.dbTaskBase, 用于实现数据库备份和恢复任务处理相关部分 * fix: aeskey变更后,解密密码出现数组越界访问错误 * fix: 时间属性为零值时,保存到 mysql 数据库报错 * refactor db.infrastructure.service.scheduler * feat: 实现立即备份功能 * refactor db.infrastructure.service.db_instance * refactor: 从数据库中获取数据库备份目录、mysql文件路径等配置信息 * fix: 数据库备份和恢复问题 * fix: 修改 .gitignore 文件,忽略数据库备份目录和数据库程序目录
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package entity
|
|
|
|
import (
|
|
"errors"
|
|
"mayfly-go/internal/common/utils"
|
|
"mayfly-go/pkg/model"
|
|
)
|
|
|
|
// 授权凭证
|
|
type AuthCert struct {
|
|
model.Model
|
|
|
|
Name string `json:"name"`
|
|
AuthMethod int8 `json:"authMethod"` // 1.密码 2.秘钥
|
|
Password string `json:"password" gorm:"column:password;type:varchar(4200)"` // 密码or私钥
|
|
Passphrase string `json:"passphrase"` // 私钥口令
|
|
Remark string `json:"remark"`
|
|
}
|
|
|
|
func (ac *AuthCert) TableName() string {
|
|
return "t_auth_cert"
|
|
}
|
|
|
|
const (
|
|
AuthCertAuthMethodPassword int8 = 1 // 密码
|
|
MachineAuthMethodPublicKey int8 = 2 // 密钥
|
|
|
|
AuthCertTypePrivate int8 = 1
|
|
AuthCertTypePublic int8 = 2
|
|
)
|
|
|
|
// PwdEncrypt 密码加密
|
|
func (ac *AuthCert) PwdEncrypt() error {
|
|
password, err := utils.PwdAesEncrypt(ac.Password)
|
|
if err != nil {
|
|
return errors.New("加密授权凭证密码失败")
|
|
}
|
|
passphrase, err := utils.PwdAesEncrypt(ac.Passphrase)
|
|
if err != nil {
|
|
return errors.New("加密授权凭证私钥失败")
|
|
}
|
|
ac.Password = password
|
|
ac.Passphrase = passphrase
|
|
return nil
|
|
}
|
|
|
|
// PwdDecrypt 密码解密
|
|
func (ac *AuthCert) PwdDecrypt() error {
|
|
password, err := utils.PwdAesDecrypt(ac.Password)
|
|
if err != nil {
|
|
return errors.New("解密授权凭证密码失败")
|
|
}
|
|
passphrase, err := utils.PwdAesDecrypt(ac.Passphrase)
|
|
if err != nil {
|
|
return errors.New("解密授权凭证私钥失败")
|
|
}
|
|
ac.Password = password
|
|
ac.Passphrase = passphrase
|
|
return nil
|
|
}
|