get login-info add 404 return & elasticcache account reset password api

add input params
This commit is contained in:
TangBin
2020-01-18 17:56:12 +08:00
parent 187d8e72fe
commit b97ef4a95a
5 changed files with 56 additions and 18 deletions

View File

@@ -411,6 +411,13 @@ func (self *SElasticcacheAccount) AllowPerformResetPassword(ctx context.Context,
}
func (self *SElasticcacheAccount) ValidatorResetPasswordData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
if reset, _ := data.Bool("reset_password"); reset {
if _, err := data.GetString("password"); err != nil {
randomPasswd := seclib2.RandomPassword2(12)
data.(*jsonutils.JSONDict).Set("password", jsonutils.NewString(randomPasswd))
}
}
passwd, err := data.GetString("password")
if err == nil && !seclib2.MeetComplxity(passwd) {
return nil, httperrors.NewWeakPasswordError()
@@ -448,14 +455,9 @@ func (self *SElasticcacheAccount) AllowGetDetailsLoginInfo(ctx context.Context,
}
func (self *SElasticcacheAccount) GetDetailsLoginInfo(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
password, err := self.GetDecodedPassword()
if err != nil {
return nil, err
}
ret := jsonutils.NewDict()
ret.Add(jsonutils.NewString(self.Name), "username")
ret.Add(jsonutils.NewString(password), "password")
ret.Add(jsonutils.NewString(self.Password), "password")
return ret, nil
}

View File

@@ -229,14 +229,10 @@ func (self *SElasticcache) GetDetailsLoginInfo(ctx context.Context, userCred mcc
return nil, err
}
password, err := account.GetDecodedPassword()
if err != nil {
return nil, err
}
ret := jsonutils.NewDict()
ret.Add(jsonutils.NewString(account.Id), "account_id")
ret.Add(jsonutils.NewString(account.Name), "username")
ret.Add(jsonutils.NewString(password), "password")
ret.Add(jsonutils.NewString(account.Password), "password")
return ret, nil
}

View File

@@ -15,13 +15,12 @@
package modules
import (
"fmt"
"github.com/pkg/errors"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/utils"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
)
@@ -52,7 +51,7 @@ func (this *SDBInstanceAccountManager) GetLoginInfo(s *mcclient.ClientSession, i
}
if len(account.Secret) == 0 {
return nil, fmt.Errorf("No login secret found")
return nil, httperrors.NewNotFoundError("No login secret found")
}
password, err := utils.DescryptAESBase64(account.Id, account.Secret)

View File

@@ -16,7 +16,9 @@ package modules
import (
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/utils"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
)
@@ -66,9 +68,48 @@ func init() {
}
func (self *ElasticCacheManager) GetLoginInfo(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
return self.GetSpecific(s, id, "login-info", params)
data, e := self.GetSpecific(s, id, "login-info", params)
if e != nil {
return nil, e
}
ret := jsonutils.NewDict()
username, _ := data.GetString("username")
ret.Set("username", jsonutils.NewString(username))
account_id, _ := data.GetString("account_id")
password, _ := data.GetString("password")
if len(password) == 0 {
return nil, httperrors.NewNotFoundError("No password found")
}
passwd, e := utils.DescryptAESBase64(account_id, password)
if e != nil {
return nil, e
}
ret.Set("password", jsonutils.NewString(passwd))
return ret, nil
}
func (self *ElasticCacheAccountManager) GetLoginInfo(s *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
return self.GetSpecific(s, id, "login-info", params)
data, e := self.GetSpecific(s, id, "login-info", params)
if e != nil {
return nil, e
}
ret := jsonutils.NewDict()
username, _ := data.GetString("username")
ret.Set("username", jsonutils.NewString(username))
password, _ := data.GetString("password")
if len(password) == 0 {
return nil, httperrors.NewNotFoundError("No password found")
}
passwd, e := utils.DescryptAESBase64(id, password)
if e != nil {
return nil, e
}
ret.Set("password", jsonutils.NewString(passwd))
return ret, nil
}

View File

@@ -42,7 +42,7 @@ func (this *HostManager) GetLoginInfo(s *mcclient.ClientSession, id string, para
ret := jsonutils.NewDict()
login_key, e := data.GetString("password")
if e != nil {
return nil, fmt.Errorf("No ssh password: %s", e)
return nil, httperrors.NewNotFoundError("No ssh password: %s", e)
}
passwd, e := utils.DescryptAESBase64(id, login_key)
if e != nil {