fix(region): check qga set password username is equal login_account

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
This commit is contained in:
wanyaoqi
2022-09-08 18:00:58 +08:00
parent 5b8d97c8f3
commit 9f38fced2c
@@ -18,6 +18,7 @@ import (
"context"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/util/timeutils"
"yunion.io/x/pkg/utils"
api "yunion.io/x/onecloud/pkg/apis/compute"
@@ -89,11 +90,13 @@ func (self *GuestQgaSetPasswordTask) OnQgaSetUserPassword(ctx context.Context, g
input := &api.ServerQgaSetPasswordInput{}
self.GetParams().Unmarshal(input)
info := make(map[string]interface{})
secret, _ := utils.EncryptAESBase64(guest.Id, input.Password)
info["login_account"] = input.Username
info["login_key"] = secret
guest.SetAllMetadata(ctx, info, self.UserCred)
if guest.GetMetadata(ctx, "login_account", self.UserCred) == input.Username {
info := make(map[string]interface{})
secret, _ := utils.EncryptAESBase64(guest.Id, input.Password)
info["login_key"] = secret
info["login_key_timestamp"] = timeutils.UtcNow()
guest.SetAllMetadata(ctx, info, self.UserCred)
}
logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_SET_USER_PASSWORD, "", self.UserCred, true)
self.SetStageComplete(ctx, nil)