本文整理汇总了Golang中github.com/openshift/origin/pkg/authorization/api.StringSubjectsFor函数的典型用法代码示例。如果您正苦于以下问题:Golang StringSubjectsFor函数的具体用法?Golang StringSubjectsFor怎么用?Golang StringSubjectsFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringSubjectsFor函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UserHasRole
// UserHasRole checks if the given user has the given role
// if the userName is empty, the current user will be used
func (c *Context) UserHasRole(userName string, roleName string) (bool, error) {
roleBindings, err := c.GetRoleBindingsForRole(roleName)
if err != nil {
return false, err
}
if len(roleBindings) == 0 {
return false, fmt.Errorf("Could not find a Role Binding for role '%s'", roleName)
}
if len(userName) == 0 {
user, err := c.GetCurrentUser()
if err != nil {
return false, err
}
userName = user.Name
}
namespace, err := c.Namespace()
if err != nil {
return false, err
}
allUsers := []string{}
for _, rb := range roleBindings {
users, _ := authapi.StringSubjectsFor(namespace, rb.Subjects)
allUsers = append(allUsers, users...)
}
return contains(userName, allUsers), nil
}
示例2: convert_api_ClusterRoleBinding_To_v1_ClusterRoleBinding
func convert_api_ClusterRoleBinding_To_v1_ClusterRoleBinding(in *newer.ClusterRoleBinding, out *ClusterRoleBinding, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.UserNames, out.GroupNames = newer.StringSubjectsFor(in.Namespace, in.Subjects)
return nil
}
示例3: RemoveSCC
func (o *SCCModificationOptions) RemoveSCC() error {
scc, err := o.SCCInterface.SecurityContextConstraints().Get(o.SCCName)
if err != nil {
return err
}
users, groups := authorizationapi.StringSubjectsFor(o.DefaultSubjectNamespace, o.Subjects)
_, remainingUsers := diff(users, scc.Users)
_, remainingGroups := diff(groups, scc.Groups)
scc.Users = remainingUsers
scc.Groups = remainingGroups
_, err = o.SCCInterface.SecurityContextConstraints().Update(scc)
if err != nil {
return err
}
return nil
}
示例4: AddSCC
func (o *SCCModificationOptions) AddSCC() error {
scc, err := o.SCCInterface.SecurityContextConstraints().Get(o.SCCName)
if err != nil {
return err
}
users, groups := authorizationapi.StringSubjectsFor(o.DefaultSubjectNamespace, o.Subjects)
usersToAdd, _ := diff(users, scc.Users)
groupsToAdd, _ := diff(groups, scc.Groups)
scc.Users = append(scc.Users, usersToAdd...)
scc.Groups = append(scc.Groups, groupsToAdd...)
_, err = o.SCCInterface.SecurityContextConstraints().Update(scc)
if err != nil {
return err
}
return nil
}
示例5: GroupHasRole
// GroupHasRole checks that the given group has the given role
func (c *Context) GroupHasRole(groupName string, roleName string) (bool, error) {
roleBindings, err := c.GetRoleBindingsForRole(roleName)
if err != nil {
return false, err
}
if len(roleBindings) == 0 {
return false, fmt.Errorf("Could not find a Role Binding for role '%s'", roleName)
}
namespace, err := c.Namespace()
if err != nil {
return false, err
}
allGroups := []string{}
for _, rb := range roleBindings {
_, groups := authapi.StringSubjectsFor(namespace, rb.Subjects)
allGroups = append(allGroups, groups...)
}
return contains(groupName, allGroups), nil
}
示例6: Groups
func (a ClusterRoleBindingAdapter) Groups() sets.String {
_, groups := authorizationapi.StringSubjectsFor(a.roleBinding.Namespace, a.roleBinding.Subjects)
return sets.NewString(groups...)
}
示例7: Users
func (a ClusterRoleBindingAdapter) Users() sets.String {
users, _ := authorizationapi.StringSubjectsFor(a.roleBinding.Namespace, a.roleBinding.Subjects)
return sets.NewString(users...)
}
示例8: Groups
func (a RoleBindingAdapter) Groups() util.StringSet {
_, groups := authorizationapi.StringSubjectsFor(a.roleBinding.Namespace, a.roleBinding.Subjects)
return util.NewStringSet(groups...)
}
示例9: Users
func (a RoleBindingAdapter) Users() util.StringSet {
users, _ := authorizationapi.StringSubjectsFor(a.roleBinding.Namespace, a.roleBinding.Subjects)
return util.NewStringSet(users...)
}