代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。