当前位置: 首页>>代码示例>>Golang>>正文


Golang api.StringSubjectsFor函数代码示例

本文整理汇总了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
}
开发者ID:AXA-GROUP-SOLUTIONS,项目名称:openshift-cucumber,代码行数:32,代码来源:role.go

示例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
}
开发者ID:ncantor,项目名称:origin,代码行数:9,代码来源:conversion.go

示例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
}
开发者ID:johnmccawley,项目名称:origin,代码行数:20,代码来源:modify_scc.go

示例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
}
开发者ID:johnmccawley,项目名称:origin,代码行数:20,代码来源:modify_scc.go

示例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
}
开发者ID:AXA-GROUP-SOLUTIONS,项目名称:openshift-cucumber,代码行数:23,代码来源:role.go

示例6: Groups

func (a ClusterRoleBindingAdapter) Groups() sets.String {
	_, groups := authorizationapi.StringSubjectsFor(a.roleBinding.Namespace, a.roleBinding.Subjects)

	return sets.NewString(groups...)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:5,代码来源:interfaces.go

示例7: Users

func (a ClusterRoleBindingAdapter) Users() sets.String {
	users, _ := authorizationapi.StringSubjectsFor(a.roleBinding.Namespace, a.roleBinding.Subjects)

	return sets.NewString(users...)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:5,代码来源:interfaces.go

示例8: Groups

func (a RoleBindingAdapter) Groups() util.StringSet {
	_, groups := authorizationapi.StringSubjectsFor(a.roleBinding.Namespace, a.roleBinding.Subjects)

	return util.NewStringSet(groups...)
}
开发者ID:nitintutlani,项目名称:origin,代码行数:5,代码来源:interfaces.go

示例9: Users

func (a RoleBindingAdapter) Users() util.StringSet {
	users, _ := authorizationapi.StringSubjectsFor(a.roleBinding.Namespace, a.roleBinding.Subjects)

	return util.NewStringSet(users...)
}
开发者ID:nitintutlani,项目名称:origin,代码行数:5,代码来源:interfaces.go


注:本文中的github.com/openshift/origin/pkg/authorization/api.StringSubjectsFor函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。