Skip to content

Commit

Permalink
fix: 新增修改入参适配时区的功能 #2092
Browse files Browse the repository at this point in the history
  • Loading branch information
fanfanyangyang authored and zhangzhw8 committed Nov 27, 2023
1 parent ce54fcf commit 6f6800a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
9 changes: 3 additions & 6 deletions dbm-services/mysql/db-priv/assests/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,9 @@ func DoMigratePlatformPassword() error {
return fmt.Errorf("%s error: %s", "init platform password, get password", err.Error())
}
if count == 0 {
insertPara := &service.ModifyPasswordPara{
UserName: user,
Component: component.Component, Operator: "admin",
Instances: []service.Address{{"0.0.0.0", 0, &defaultCloudId}},
InitPlatform: true,
SecurityRuleName: "password"}
insertPara := &service.ModifyPasswordPara{UserName: user, Component: component.Component, Operator: "admin",
Instances: []service.Address{{"0.0.0.0", 0, &defaultCloudId}},
InitPlatform: true, SecurityRuleName: "password"}
err = insertPara.ModifyPassword()
if err != nil {
return fmt.Errorf("%s error: %s", "init platform password, modify password", err.Error())
Expand Down
10 changes: 6 additions & 4 deletions dbm-services/mysql/db-priv/service/admin_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ func (m *GetAdminUserPasswordPara) GetMysqlAdminPassword() ([]*TbPasswords, int,
return passwords, 0, errno.ComponentNull
}
// mysql实例中ADMIN用户的密码,仅能查看人为修改密码且在有效期的密码,不可以查看随机化生成的密码
where := fmt.Sprintf(" username='%s' and component='%s' and lock_until is not null", m.UserName, m.Component)
where := fmt.Sprintf(" username='%s' and component='%s' and lock_until is not null and "+
"lock_until > now()", m.UserName, m.Component)
var filter []string
for _, item := range m.Instances {
filter = append(filter, fmt.Sprintf("(ip='%s' and port=%d)", item.Ip, item.Port))
Expand Down Expand Up @@ -382,11 +383,12 @@ func (m *ModifyAdminUserPasswordPara) ModifyMysqlAdminPassword() (BatchResult, e
sql := fmt.Sprintf("replace into tb_passwords(ip,port,bk_cloud_id,username,"+
"password,component,operator) values('%s',%d,%d,'%s','%s','%s','%s')",
address.Ip, address.Port, *cluster.BkCloudId, m.UserName, encrypt, m.Component, m.Operator)
if m.LockUntil != "" {
if m.LockHour != 0 {
sql = fmt.Sprintf("replace into tb_passwords(ip,port,bk_cloud_id,username,"+
"password,component,operator,lock_until) values('%s',%d,%d,'%s','%s','%s','%s','%s')",
"password,component,operator,lock_until) values('%s',%d,%d,'%s','%s','%s','%s',date_add("+
"now(),INTERVAL %d hour))",
address.Ip, address.Port, *cluster.BkCloudId, m.UserName, encrypt, m.Component,
m.Operator, m.LockUntil)
m.Operator, m.LockHour)
}
result := DB.Self.Exec(sql)
if result.Error != nil {
Expand Down
31 changes: 17 additions & 14 deletions dbm-services/mysql/db-priv/service/admin_password_object.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package service

import "dbm-services/mysql/priv-service/util"
import (
"time"
)

// ModifyAdminUserPasswordPara 函数的入参
type ModifyAdminUserPasswordPara struct {
UserName string `json:"username"`
Component string `json:"component"`
Psw string `json:"password"`
LockUntil util.TimeFormat `json:"lock_until"`
Operator string `json:"operator"`
Clusters []OneCluster `json:"clusters"`
SecurityRuleName string `json:"security_rule_name"`
Range string `json:"range"`
Async bool `json:"async"` // 是否异步的方式执行
UserName string `json:"username"`
Component string `json:"component"`
Psw string `json:"password"`
//LockUntil util.TimeFormat `json:"lock_until"`
LockHour int `json:"lock_hour"`
Operator string `json:"operator"`
Clusters []OneCluster `json:"clusters"`
SecurityRuleName string `json:"security_rule_name"`
Range string `json:"range"`
Async bool `json:"async"` // 是否异步的方式执行
}

// ModifyPasswordPara 函数的入参
Expand Down Expand Up @@ -61,10 +64,10 @@ type TbPasswords struct {
// Password 加密后的密码
Password string `gorm:"column:password;not_null" json:"password"`
// Component 组件,比如mysql、proxy
Component string `gorm:"column:component;not_null" json:"component"`
LockUntil util.TimeFormat `gorm:"column:lock_until" json:"lock_until"`
Operator string `gorm:"column:operator" json:"operator"`
UpdateTime util.TimeFormat `gorm:"column:update_time" json:"update_time"`
Component string `gorm:"column:component;not_null" json:"component"`
LockUntil time.Time `gorm:"column:lock_until" json:"lock_until"`
Operator string `gorm:"column:operator" json:"operator"`
UpdateTime time.Time `gorm:"column:update_time" json:"update_time"`
}

type OneCluster struct {
Expand Down

0 comments on commit 6f6800a

Please sign in to comment.