本文整理匯總了Golang中github.com/openshift/origin/pkg/client.Client.SubjectAccessReviews方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.SubjectAccessReviews方法的具體用法?Golang Client.SubjectAccessReviews怎麽用?Golang Client.SubjectAccessReviews使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/origin/pkg/client.Client
的用法示例。
在下文中一共展示了Client.SubjectAccessReviews方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: adminCan
func adminCan(client *osclient.Client, action authorizationapi.AuthorizationAttributes) (bool, error) {
if resp, err := client.SubjectAccessReviews().Create(&authorizationapi.SubjectAccessReview{Action: action}); err != nil {
return false, err
} else if resp.Allowed {
return true, nil
}
return false, nil
}
示例2: WaitForPolicyUpdate
// WaitForPolicyUpdate checks if the given client can perform the named verb and action.
// If PolicyCachePollTimeout is reached without the expected condition matching, an error is returned
func WaitForPolicyUpdate(c *client.Client, namespace, verb, resource string, allowed bool) error {
review := &authorizationapi.SubjectAccessReview{Verb: verb, Resource: resource}
err := wait.Poll(PolicyCachePollInterval, PolicyCachePollTimeout, func() (bool, error) {
response, err := c.SubjectAccessReviews(namespace).Create(review)
if err != nil {
return false, err
}
if response.Allowed != allowed {
return false, nil
}
return true, nil
})
return err
}
示例3: WaitForClusterPolicyUpdate
// WaitForClusterPolicyUpdate checks if the given client can perform the named verb and action.
// If PolicyCachePollTimeout is reached without the expected condition matching, an error is returned
func WaitForClusterPolicyUpdate(c *client.Client, verb string, resource unversioned.GroupResource, allowed bool) error {
review := &authorizationapi.SubjectAccessReview{Action: authorizationapi.AuthorizationAttributes{Verb: verb, Group: resource.Group, Resource: resource.Resource}}
err := wait.Poll(PolicyCachePollInterval, PolicyCachePollTimeout, func() (bool, error) {
response, err := c.SubjectAccessReviews().Create(review)
if err != nil {
return false, err
}
if response.Allowed != allowed {
return false, nil
}
return true, nil
})
return err
}
示例4: verifyImageStreamAccess
func verifyImageStreamAccess(namespace, imageRepo, verb string, client *client.Client) error {
sar := authorizationapi.SubjectAccessReview{
Verb: verb,
Resource: "imagestreams/layers",
ResourceName: imageRepo,
}
response, err := client.SubjectAccessReviews(namespace).Create(&sar)
if err != nil {
log.Errorf("OpenShift client error: %s", err)
if kerrors.IsUnauthorized(err) || kerrors.IsForbidden(err) {
return ErrOpenShiftAccessDenied
}
return err
}
if !response.Allowed {
log.Errorf("OpenShift access denied: %s", response.Reason)
return ErrOpenShiftAccessDenied
}
return nil
}
示例5: verifyPruneAccess
func verifyPruneAccess(ctx context.Context, client *client.Client) error {
sar := authorizationapi.SubjectAccessReview{
Action: authorizationapi.AuthorizationAttributes{
Verb: "delete",
Resource: "images",
},
}
response, err := client.SubjectAccessReviews().Create(&sar)
if err != nil {
context.GetLogger(ctx).Errorf("OpenShift client error: %s", err)
if kerrors.IsUnauthorized(err) || kerrors.IsForbidden(err) {
return ErrOpenShiftAccessDenied
}
return err
}
if !response.Allowed {
context.GetLogger(ctx).Errorf("OpenShift access denied: %s", response.Reason)
return ErrOpenShiftAccessDenied
}
return nil
}