[REV]Update eid get

This commit is contained in:
崔斌 2017-12-07 10:42:32 +08:00
parent 5f7f63ae42
commit 9c5764a3c1
2 changed files with 28 additions and 28 deletions

View File

@ -31,6 +31,7 @@ import (
"math/big"
"time"
"github.com/Sirupsen/logrus"
"github.com/jinzhu/gorm"
"github.com/goodrain/rainbond/cmd/api/option"
@ -78,32 +79,31 @@ func (c *CloudAction) TokenDispatcher(gt *api_model.GetUserToken) (*api_model.To
return ti, nil
CREATE:
token := c.createToken(gt)
if !c.APISSL {
return ti, nil
}
//TODO: ca, key
ca, key, err := c.CertDispatcher(gt)
if err != nil {
return nil, util.CreateAPIHandleError(500, fmt.Errorf("create ca or key error"))
}
ti.Token = token
logrus.Debugf("create token %v", token)
rui := &dbmodel.RegionUserInfo{
EID: gt.Body.EID,
RegionTag: c.RegionTag,
ValidityPeriod: gt.Body.ValidityPeriod,
Token: token,
}
if gt.Body.Range == "" {
rui.APIRange = "source"
if c.APISSL {
ca, key, err := c.CertDispatcher(gt)
if err != nil {
return nil, util.CreateAPIHandleError(500, fmt.Errorf("create ca or key error"))
}
GetTokenIdenHandler().AddTokenIntoMap(rui)
rui.CA = string(ca)
rui.Key = string(key)
ti.CA = string(ca)
ti.Key = string(key)
}
if gt.Body.Range == "" {
rui.APIRange = dbmodel.SERVERSOURCE
}
GetTokenIdenHandler().AddTokenIntoMap(rui)
if err := db.GetManager().RegionUserInfoDao().AddModel(rui); err != nil {
return nil, util.CreateAPIHandleErrorFromDBError("create region user info", err)
}
ti.CA = string(ca)
ti.Key = string(key)
ti.Token = token
return ti, nil
}

View File

@ -26,7 +26,7 @@ type GetUserToken struct {
// eid
// in: body
// required: true
EID string `json:"eid" validate:"eid"`
EID string `json:"eid" validate:"eid|required"`
// 可控范围
// in: body
// required: false
@ -34,7 +34,7 @@ type GetUserToken struct {
// 有效期
// in: body
// required: true
ValidityPeriod int `json:"validity_period" validate:"validity_period|required"` //20191120
ValidityPeriod int `json:"validity_period" validate:"validity_period|required"` //1549812345
// 数据中心标识
// in: body
// required: true