36 Star 396 Fork 71

GVPrancher / rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
roletemplate.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-06-12 13:38 . goimport linting changes
package roletemplate
import (
"fmt"
"net/http"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
client "github.com/rancher/types/client/management/v3"
)
type Wrapper struct {
RoleTemplateLister v3.RoleTemplateLister
}
func (w Wrapper) Validator(request *types.APIContext, schema *types.Schema, data map[string]interface{}) error {
if request.Method != http.MethodPut && request.Method != http.MethodPost {
return nil
}
// Only cluster roles can be administrative for now. So this validation will prevent users from creating any "project" context
// roleTemplates with administrative bit set to true
if request.Method == http.MethodPost || request.Method == http.MethodPut {
administrative := convert.ToBool(data[client.RoleTemplateFieldAdministrative])
context := convert.ToString(data[client.RoleTemplateFieldContext])
if administrative && context != "cluster" {
return fmt.Errorf("Only cluster roles can be administrative")
}
}
if request.Method != http.MethodPut {
return nil
}
rt, err := w.RoleTemplateLister.Get("", request.ID)
if err != nil {
return err
}
if rt.Builtin == true {
// Drop everything but locked and defaults. If it's builtin nothing else can change.
for k := range data {
if k == "locked" || k == "clusterCreatorDefault" || k == "projectCreatorDefault" {
continue
}
delete(data, k)
}
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.6-rc2

搜索帮助

344bd9b3 5694891 D2dac590 5694891