mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: class action 统一使用keywords包裹
This commit is contained in:
@@ -179,6 +179,19 @@ func init() {
|
||||
},
|
||||
)
|
||||
|
||||
R(&options.ServerCreateOptions{}, "server-check-create-data", "Check create server data", func(s *mcclient.ClientSession, opts *options.ServerCreateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
server, err := modules.Servers.PerformClassAction(s, "check-create-data", params.JSON(params))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(server)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.ServerCreateOptions{}, "server-create", "Create a server", func(s *mcclient.ClientSession, opts *options.ServerCreateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
|
||||
@@ -1331,11 +1331,7 @@ func managerPerformCheckCreateData(
|
||||
query jsonutils.JSONObject,
|
||||
data jsonutils.JSONObject,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
body, err := data.(*jsonutils.JSONDict).Get(manager.Keyword())
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
bodyDict := body.(*jsonutils.JSONDict)
|
||||
bodyDict := data.(*jsonutils.JSONDict)
|
||||
|
||||
if consts.IsRbacEnabled() {
|
||||
err := isClassRbacAllowed(manager, userCred, ownerId, policy.PolicyActionPerform, action)
|
||||
|
||||
@@ -114,7 +114,7 @@ func (this *JointResourceManager) ListAscendent(s *mcclient.ClientSession, mid s
|
||||
|
||||
func (this *JointResourceManager) Attach(s *mcclient.ClientSession, mid, sid string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
path := fmt.Sprintf("/%s/%s/%s/%s", this.Master.KeyString(), url.PathEscape(mid), this.Slave.KeyString(), url.PathEscape(sid))
|
||||
result, err := this._post(s, path, this.params2Body(s, params), this.Keyword)
|
||||
result, err := this._post(s, path, this.params2Body(s, params, this.Keyword), this.Keyword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func (this *JointResourceManager) Update(s *mcclient.ClientSession, mid, sid str
|
||||
path = fmt.Sprintf("%s?%s", path, queryStr)
|
||||
}
|
||||
}
|
||||
result, err := this._put(s, path, this.params2Body(s, params), this.Keyword)
|
||||
result, err := this._put(s, path, this.params2Body(s, params, this.Keyword), this.Keyword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -183,7 +183,7 @@ func (this *JointResourceManager) Patch(s *mcclient.ClientSession, mid, sid stri
|
||||
path = fmt.Sprintf("%s?%s", path, queryStr)
|
||||
}
|
||||
}
|
||||
result, err := this._patch(s, path, this.params2Body(s, params), this.Keyword)
|
||||
result, err := this._patch(s, path, this.params2Body(s, params, this.Keyword), this.Keyword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ func (this *ResourceManager) HeadInContexts(session *mcclient.ClientSession, id
|
||||
return this.filterSingleResult(session, result, params)
|
||||
}
|
||||
|
||||
func (this *ResourceManager) params2Body(s *mcclient.ClientSession, params jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
func (this *ResourceManager) params2Body(s *mcclient.ClientSession, params jsonutils.JSONObject, key string) *jsonutils.JSONDict {
|
||||
body := jsonutils.NewDict()
|
||||
if params != nil {
|
||||
if this.enableFilter && this.writeFilter != nil {
|
||||
@@ -310,7 +310,7 @@ func (this *ResourceManager) params2Body(s *mcclient.ClientSession, params jsonu
|
||||
log.Warningf("writeFilter fail %s: %s", params, err)
|
||||
}
|
||||
}
|
||||
body.Add(params, this.Keyword)
|
||||
body.Add(params, key)
|
||||
}
|
||||
return body
|
||||
}
|
||||
@@ -325,7 +325,7 @@ func (this *ResourceManager) CreateInContext(session *mcclient.ClientSession, pa
|
||||
|
||||
func (this *ResourceManager) CreateInContexts(session *mcclient.ClientSession, params jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error) {
|
||||
path := fmt.Sprintf("/%s", this.ContextPath(ctxs))
|
||||
result, err := this._post(session, path, this.params2Body(session, params), this.Keyword)
|
||||
result, err := this._post(session, path, this.params2Body(session, params, this.Keyword), this.Keyword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -342,7 +342,7 @@ func (this *ResourceManager) BatchCreateInContext(session *mcclient.ClientSessio
|
||||
|
||||
func (this *ResourceManager) BatchCreateInContexts(session *mcclient.ClientSession, params jsonutils.JSONObject, count int, ctxs []ManagerContext) []SubmitResult {
|
||||
path := fmt.Sprintf("/%s", this.ContextPath(ctxs))
|
||||
body := this.params2Body(session, params)
|
||||
body := this.params2Body(session, params, this.Keyword)
|
||||
body.Add(jsonutils.NewInt(int64(count)), "count")
|
||||
ret := make([]SubmitResult, count)
|
||||
respbody, err := this._post(session, path, body, this.KeywordPlural)
|
||||
@@ -402,7 +402,7 @@ func (this *ResourceManager) PutInContext(session *mcclient.ClientSession, id st
|
||||
|
||||
func (this *ResourceManager) PutInContexts(session *mcclient.ClientSession, id string, params jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error) {
|
||||
path := fmt.Sprintf("/%s/%s", this.ContextPath(ctxs), url.PathEscape(id))
|
||||
result, err := this._put(session, path, this.params2Body(session, params), this.Keyword)
|
||||
result, err := this._put(session, path, this.params2Body(session, params, this.Keyword), this.Keyword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -437,7 +437,7 @@ func (this *ResourceManager) PatchInContext(session *mcclient.ClientSession, id
|
||||
|
||||
func (this *ResourceManager) PatchInContexts(session *mcclient.ClientSession, id string, params jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error) {
|
||||
path := fmt.Sprintf("/%s/%s", this.ContextPath(ctxs), url.PathEscape(id))
|
||||
result, err := this._patch(session, path, this.params2Body(session, params), this.Keyword)
|
||||
result, err := this._patch(session, path, this.params2Body(session, params, this.Keyword), this.Keyword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -468,7 +468,7 @@ func (this *ResourceManager) PerformActionInContext(session *mcclient.ClientSess
|
||||
|
||||
func (this *ResourceManager) PerformActionInContexts(session *mcclient.ClientSession, id string, action string, params jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error) {
|
||||
path := fmt.Sprintf("/%s/%s/%s", this.ContextPath(ctxs), url.PathEscape(id), url.PathEscape(action))
|
||||
result, err := this._post(session, path, this.params2Body(session, params), this.Keyword)
|
||||
result, err := this._post(session, path, this.params2Body(session, params, this.Keyword), this.Keyword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -481,7 +481,7 @@ func (this *ResourceManager) PerformClassAction(session *mcclient.ClientSession,
|
||||
|
||||
func (this *ResourceManager) PerformClassActionInContexts(session *mcclient.ClientSession, action string, params jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error) {
|
||||
path := fmt.Sprintf("/%s/%s", this.ContextPath(ctxs), url.PathEscape(action))
|
||||
return this._post(session, path, params, this.KeywordPlural)
|
||||
return this._post(session, path, this.params2Body(session, params, this.KeywordPlural), this.KeywordPlural)
|
||||
}
|
||||
|
||||
func (this *ResourceManager) BatchPerformClassAction(session *mcclient.ClientSession, action string, batchParams []jsonutils.JSONObject) []SubmitResult {
|
||||
@@ -541,7 +541,7 @@ func (this *ResourceManager) deleteInContexts(session *mcclient.ClientSession, i
|
||||
}
|
||||
}
|
||||
if body != nil {
|
||||
body = this.params2Body(session, body)
|
||||
body = this.params2Body(session, body, this.Keyword)
|
||||
}
|
||||
result, err := this._delete(session, path, body, this.Keyword)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user