本文整理匯總了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...)
}