mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
allow delete role-policy-binding
This commit is contained in:
@@ -73,4 +73,16 @@ func init() {
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type RolePolicyDeleteOptions struct {
|
||||
ID string `json:"-" help:"id or role policy binding"`
|
||||
}
|
||||
R(&RolePolicyDeleteOptions{}, "role-policy-delete", "Delete role policy binding", func(s *mcclient.ClientSession, args *RolePolicyDeleteOptions) error {
|
||||
result, err := modules.RolePolicies.Delete(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -449,3 +449,29 @@ func (manager *SRolePolicyManager) fetchByRoleId(roleId string) ([]SRolePolicy,
|
||||
}
|
||||
return rps, nil
|
||||
}
|
||||
|
||||
func (manager *SRolePolicyManager) FilterById(q *sqlchemy.SQuery, idStr string) *sqlchemy.SQuery {
|
||||
parts := strings.Split(idStr, ":")
|
||||
if len(parts) == 3 {
|
||||
return q.Equals("role_id", parts[0]).Equals("project_id", parts[1]).Equals("policy_id", parts[2])
|
||||
} else {
|
||||
return q.Equals("ips", idStr)
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *SRolePolicyManager) FilterByNotId(q *sqlchemy.SQuery, idStr string) *sqlchemy.SQuery {
|
||||
parts := strings.Split(idStr, ":")
|
||||
if len(parts) == 3 {
|
||||
return q.Filter(sqlchemy.OR(
|
||||
sqlchemy.NotEquals(q.Field("role_id"), parts[0]),
|
||||
sqlchemy.NotEquals(q.Field("project_id"), parts[1]),
|
||||
sqlchemy.NotEquals(q.Field("policy_id"), parts[2]),
|
||||
))
|
||||
} else {
|
||||
return q
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *SRolePolicyManager) FilterByName(q *sqlchemy.SQuery, name string) *sqlchemy.SQuery {
|
||||
return manager.FilterById(q, name)
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func init() {
|
||||
RolePolicies = SRolePolicyManager{NewIdentityV3Manager(
|
||||
"rolepolicy",
|
||||
"rolepolicies",
|
||||
[]string{"role", "role_id", "project", "project_id", "policy", "policy_id", "ips", "scope"},
|
||||
[]string{"id", "name", "role", "role_id", "project", "project_id", "policy", "policy_id", "ips", "scope"},
|
||||
[]string{},
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user