代码拉取完成,页面将自动刷新
package roletemplatebinding
import (
"fmt"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/client/management/v3"
"github.com/rancher/types/config"
)
func NewPRTBValidator(management *config.ScaledContext) types.Validator {
return newValidator(management, client.ProjectRoleTemplateBindingFieldRoleTemplateID)
}
func NewCRTBValidator(management *config.ScaledContext) types.Validator {
return newValidator(management, client.ClusterRoleTemplateBindingFieldRoleTemplateID)
}
func newValidator(management *config.ScaledContext, field string) types.Validator {
validator := &Validator{
roleTemplateLister: management.Management.RoleTemplates("").Controller().Lister(),
field: field,
}
return validator.Validator
}
type Validator struct {
roleTemplateLister v3.RoleTemplateLister
field string
}
func (v *Validator) Validator(request *types.APIContext, schema *types.Schema, data map[string]interface{}) error {
return v.ValidateRoleTemplateBinding(data[v.field])
}
func (v *Validator) ValidateRoleTemplateBinding(obj interface{}) error {
roleTemplateID, ok := obj.(string)
if !ok {
return httperror.NewAPIError(httperror.MissingRequired, "Request does not have a valid roleTemplateId")
}
roleTemplate, err := v.roleTemplateLister.Get("", roleTemplateID)
if err != nil {
return httperror.NewAPIError(httperror.ServerError, fmt.Sprintf("Error getting role template: %v", err))
}
if roleTemplate.Locked {
return httperror.NewAPIError(httperror.InvalidState, "Role is locked and cannot be assigned")
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。