From 6f6800accbf3d9927591e1bc7cc8c6c89c491bc8 Mon Sep 17 00:00:00 2001 From: fanfanyangyang Date: Fri, 24 Nov 2023 17:51:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=B0=E5=A2=9E=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=85=A5=E5=8F=82=E9=80=82=E9=85=8D=E6=97=B6=E5=8C=BA=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20#2092?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-services/mysql/db-priv/assests/migrate.go | 9 ++---- .../mysql/db-priv/service/admin_password.go | 10 +++--- .../db-priv/service/admin_password_object.go | 31 ++++++++++--------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/dbm-services/mysql/db-priv/assests/migrate.go b/dbm-services/mysql/db-priv/assests/migrate.go index c2adb2574b..de39127c85 100644 --- a/dbm-services/mysql/db-priv/assests/migrate.go +++ b/dbm-services/mysql/db-priv/assests/migrate.go @@ -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()) diff --git a/dbm-services/mysql/db-priv/service/admin_password.go b/dbm-services/mysql/db-priv/service/admin_password.go index df8099912f..7849f60b28 100644 --- a/dbm-services/mysql/db-priv/service/admin_password.go +++ b/dbm-services/mysql/db-priv/service/admin_password.go @@ -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)) @@ -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 { diff --git a/dbm-services/mysql/db-priv/service/admin_password_object.go b/dbm-services/mysql/db-priv/service/admin_password_object.go index 8a3db4db2a..abe07e29e5 100644 --- a/dbm-services/mysql/db-priv/service/admin_password_object.go +++ b/dbm-services/mysql/db-priv/service/admin_password_object.go @@ -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 函数的入参 @@ -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 {