aboutsummaryrefslogtreecommitdiff
path: root/vendor/cloud.google.com/go/iam/iam.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/cloud.google.com/go/iam/iam.go')
-rw-r--r--vendor/cloud.google.com/go/iam/iam.go60
1 files changed, 48 insertions, 12 deletions
diff --git a/vendor/cloud.google.com/go/iam/iam.go b/vendor/cloud.google.com/go/iam/iam.go
index 8722ee8..87d468a 100644
--- a/vendor/cloud.google.com/go/iam/iam.go
+++ b/vendor/cloud.google.com/go/iam/iam.go
@@ -1,4 +1,4 @@
-// Copyright 2016 Google Inc. All Rights Reserved.
+// Copyright 2016 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -22,9 +22,13 @@
package iam
import (
+ "time"
+
+ gax "github.com/googleapis/gax-go"
"golang.org/x/net/context"
pb "google.golang.org/genproto/googleapis/iam/v1"
"google.golang.org/grpc"
+ "google.golang.org/grpc/codes"
)
// client abstracts the IAMPolicy API to allow multiple implementations.
@@ -39,26 +43,50 @@ type grpcClient struct {
c pb.IAMPolicyClient
}
+var withRetry = gax.WithRetry(func() gax.Retryer {
+ return gax.OnCodes([]codes.Code{
+ codes.DeadlineExceeded,
+ codes.Unavailable,
+ }, gax.Backoff{
+ Initial: 100 * time.Millisecond,
+ Max: 60 * time.Second,
+ Multiplier: 1.3,
+ })
+})
+
func (g *grpcClient) Get(ctx context.Context, resource string) (*pb.Policy, error) {
- proto, err := g.c.GetIamPolicy(ctx, &pb.GetIamPolicyRequest{Resource: resource})
+ var proto *pb.Policy
+ err := gax.Invoke(ctx, func(ctx context.Context, _ gax.CallSettings) error {
+ var err error
+ proto, err = g.c.GetIamPolicy(ctx, &pb.GetIamPolicyRequest{Resource: resource})
+ return err
+ }, withRetry)
if err != nil {
return nil, err
}
return proto, nil
}
+
func (g *grpcClient) Set(ctx context.Context, resource string, p *pb.Policy) error {
- _, err := g.c.SetIamPolicy(ctx, &pb.SetIamPolicyRequest{
- Resource: resource,
- Policy: p,
- })
- return err
+ return gax.Invoke(ctx, func(ctx context.Context, _ gax.CallSettings) error {
+ _, err := g.c.SetIamPolicy(ctx, &pb.SetIamPolicyRequest{
+ Resource: resource,
+ Policy: p,
+ })
+ return err
+ }, withRetry)
}
func (g *grpcClient) Test(ctx context.Context, resource string, perms []string) ([]string, error) {
- res, err := g.c.TestIamPermissions(ctx, &pb.TestIamPermissionsRequest{
- Resource: resource,
- Permissions: perms,
- })
+ var res *pb.TestIamPermissionsResponse
+ err := gax.Invoke(ctx, func(ctx context.Context, _ gax.CallSettings) error {
+ var err error
+ res, err = g.c.TestIamPermissions(ctx, &pb.TestIamPermissionsRequest{
+ Resource: resource,
+ Permissions: perms,
+ })
+ return err
+ }, withRetry)
if err != nil {
return nil, err
}
@@ -76,7 +104,15 @@ type Handle struct {
// InternalNewHandle returns a Handle for resource.
// The conn parameter refers to a server that must support the IAMPolicy service.
func InternalNewHandle(conn *grpc.ClientConn, resource string) *Handle {
- return InternalNewHandleClient(&grpcClient{c: pb.NewIAMPolicyClient(conn)}, resource)
+ return InternalNewHandleGRPCClient(pb.NewIAMPolicyClient(conn), resource)
+}
+
+// InternalNewHandleGRPCClient is for use by the Google Cloud Libraries only.
+//
+// InternalNewHandleClient returns a Handle for resource using the given
+// grpc service that implements IAM as a mixin
+func InternalNewHandleGRPCClient(c pb.IAMPolicyClient, resource string) *Handle {
+ return InternalNewHandleClient(&grpcClient{c: c}, resource)
}
// InternalNewHandleClient is for use by the Google Cloud Libraries only.