37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
indexes.go 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
Craig Jellick 提交于 2018-03-02 15:54 . Don't unset userPrincipalName
package auth
import (
"k8s.io/api/rbac/v1"
)
func rbByOwner(obj interface{}) ([]string, error) {
rb, ok := obj.(*v1.RoleBinding)
if !ok {
return []string{}, nil
}
return getRBOwnerKey(rb), nil
}
func getRBOwnerKey(rb *v1.RoleBinding) []string {
var owners []string
for _, o := range rb.OwnerReferences {
owners = append(owners, string(o.UID))
}
return owners
}
func rbRoleSubjectKey(roleName string, subject v1.Subject) string {
return roleName + "." + subject.Kind + "." + subject.Name
}
func rbRoleSubjectKeys(roleName string, subjects []v1.Subject) []string {
var keys []string
for _, s := range subjects {
keys = append(keys, rbRoleSubjectKey(roleName, s))
}
return keys
}
func rbByRoleAndSubject(obj interface{}) ([]string, error) {
var subjects []v1.Subject
var roleName string
if rb, ok := obj.(*v1.ClusterRoleBinding); ok {
roleName = rb.RoleRef.Name
subjects = rb.Subjects
} else if rb, ok := obj.(*v1.RoleBinding); ok {
roleName = rb.RoleRef.Name
subjects = rb.Subjects
} else {
return []string{}, nil
}
return rbRoleSubjectKeys(roleName, subjects), nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.1-rc1

搜索帮助