本文整理汇总了Golang中github.com/openshift/origin/pkg/authorization/api.ToPolicy函数的典型用法代码示例。如果您正苦于以下问题:Golang ToPolicy函数的具体用法?Golang ToPolicy怎么用?Golang ToPolicy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ToPolicy函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getReferencedRole
func (m *VirtualStorage) getReferencedRole(roleRef kapi.ObjectReference) (*authorizationapi.Role, error) {
ctx := kapi.WithNamespace(kapi.NewContext(), roleRef.Namespace)
var policy *authorizationapi.Policy
var err error
switch {
case len(roleRef.Namespace) == 0:
var clusterPolicy *authorizationapi.ClusterPolicy
clusterPolicy, err = m.ClusterPolicyRegistry.GetClusterPolicy(ctx, authorizationapi.PolicyName)
policy = authorizationapi.ToPolicy(clusterPolicy)
default:
policy, err = m.PolicyRegistry.GetPolicy(ctx, authorizationapi.PolicyName)
}
if err != nil {
return nil, err
}
role, exists := policy.Roles[roleRef.Name]
if !exists {
return nil, kapierrors.NewNotFound("Role", roleRef.Name)
}
return role, nil
}
示例2: Describe
// Describe returns the description of a policy
// TODO make something a lot prettier
func (d *ClusterPolicyDescriber) Describe(namespace, name string) (string, error) {
c := d.ClusterPolicies()
policy, err := c.Get(name)
if err != nil {
return "", err
}
return DescribePolicy(authorizationapi.ToPolicy(policy))
}
示例3: GetPolicy
// GetPolicy retrieves a specific policy. It conforms to rulevalidation.PolicyGetter.
func (c readOnlyAuthorizationCache) GetPolicy(ctx kapi.Context, name string) (*authorizationapi.Policy, error) {
namespace, _ := kapi.NamespaceFrom(ctx)
if namespaceRefersToCluster(namespace) {
clusterPolicy, err := c.ReadOnlyClusterPolicies().Get(name)
if err != nil {
return &authorizationapi.Policy{}, err
}
return authorizationapi.ToPolicy(clusterPolicy), nil
} else {
policy, err := c.ReadOnlyPolicies(namespace).Get(name)
if err != nil {
return &authorizationapi.Policy{}, err
}
return policy, nil
}
}
示例4: printClusterPolicy
func printClusterPolicy(policy *authorizationapi.ClusterPolicy, w io.Writer, opts kctl.PrintOptions) error {
return printPolicy(authorizationapi.ToPolicy(policy), w, opts)
}
示例5: ValidateClusterPolicyUpdate
func ValidateClusterPolicyUpdate(policy *authorizationapi.ClusterPolicy, oldPolicy *authorizationapi.ClusterPolicy) fielderrors.ValidationErrorList {
return ValidatePolicyUpdate(authorizationapi.ToPolicy(policy), authorizationapi.ToPolicy(oldPolicy), false)
}
示例6: GetPolicy
func (s *simulatedStorage) GetPolicy(ctx kapi.Context, name string) (*authorizationapi.Policy, error) {
ret, err := s.clusterRegistry.GetClusterPolicy(ctx, name)
return authorizationapi.ToPolicy(ret), err
}
示例7: printClusterPolicy
func printClusterPolicy(policy *authorizationapi.ClusterPolicy, w io.Writer, withNamespace, wide bool, columnLabels []string) error {
return printPolicy(authorizationapi.ToPolicy(policy), w, withNamespace, wide, columnLabels)
}
示例8: ValidateClusterPolicy
func ValidateClusterPolicy(policy *authorizationapi.ClusterPolicy) field.ErrorList {
return ValidatePolicy(authorizationapi.ToPolicy(policy), false)
}
示例9: printClusterPolicy
func printClusterPolicy(policy *authorizationapi.ClusterPolicy, w io.Writer, withNamespace bool) error {
return printPolicy(authorizationapi.ToPolicy(policy), w, withNamespace)
}