當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。