...

Source file src/cloud.google.com/go/storage/internal/apiv2/storage_client.go

Documentation: cloud.google.com/go/storage/internal/apiv2

     1  // Copyright 2024 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
    16  
    17  package storage
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"math"
    23  	"net/url"
    24  	"regexp"
    25  	"strings"
    26  	"time"
    27  
    28  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    29  	storagepb "cloud.google.com/go/storage/internal/apiv2/storagepb"
    30  	gax "github.com/googleapis/gax-go/v2"
    31  	"google.golang.org/api/iterator"
    32  	"google.golang.org/api/option"
    33  	"google.golang.org/api/option/internaloption"
    34  	gtransport "google.golang.org/api/transport/grpc"
    35  	"google.golang.org/grpc"
    36  	"google.golang.org/grpc/codes"
    37  	"google.golang.org/protobuf/proto"
    38  )
    39  
    40  var newClientHook clientHook
    41  
    42  // CallOptions contains the retry settings for each method of Client.
    43  type CallOptions struct {
    44  	DeleteBucket              []gax.CallOption
    45  	GetBucket                 []gax.CallOption
    46  	CreateBucket              []gax.CallOption
    47  	ListBuckets               []gax.CallOption
    48  	LockBucketRetentionPolicy []gax.CallOption
    49  	GetIamPolicy              []gax.CallOption
    50  	SetIamPolicy              []gax.CallOption
    51  	TestIamPermissions        []gax.CallOption
    52  	UpdateBucket              []gax.CallOption
    53  	DeleteNotificationConfig  []gax.CallOption
    54  	GetNotificationConfig     []gax.CallOption
    55  	CreateNotificationConfig  []gax.CallOption
    56  	ListNotificationConfigs   []gax.CallOption
    57  	ComposeObject             []gax.CallOption
    58  	DeleteObject              []gax.CallOption
    59  	RestoreObject             []gax.CallOption
    60  	CancelResumableWrite      []gax.CallOption
    61  	GetObject                 []gax.CallOption
    62  	ReadObject                []gax.CallOption
    63  	UpdateObject              []gax.CallOption
    64  	WriteObject               []gax.CallOption
    65  	BidiWriteObject           []gax.CallOption
    66  	ListObjects               []gax.CallOption
    67  	RewriteObject             []gax.CallOption
    68  	StartResumableWrite       []gax.CallOption
    69  	QueryWriteStatus          []gax.CallOption
    70  	GetServiceAccount         []gax.CallOption
    71  	CreateHmacKey             []gax.CallOption
    72  	DeleteHmacKey             []gax.CallOption
    73  	GetHmacKey                []gax.CallOption
    74  	ListHmacKeys              []gax.CallOption
    75  	UpdateHmacKey             []gax.CallOption
    76  }
    77  
    78  func defaultGRPCClientOptions() []option.ClientOption {
    79  	return []option.ClientOption{
    80  		internaloption.WithDefaultEndpoint("storage.googleapis.com:443"),
    81  		internaloption.WithDefaultEndpointTemplate("storage.UNIVERSE_DOMAIN:443"),
    82  		internaloption.WithDefaultMTLSEndpoint("storage.mtls.googleapis.com:443"),
    83  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    84  		internaloption.WithDefaultAudience("https://storage.googleapis.com/"),
    85  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    86  		internaloption.EnableJwtWithScope(),
    87  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    88  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    89  	}
    90  }
    91  
    92  func defaultCallOptions() *CallOptions {
    93  	return &CallOptions{
    94  		DeleteBucket: []gax.CallOption{
    95  			gax.WithTimeout(60000 * time.Millisecond),
    96  			gax.WithRetry(func() gax.Retryer {
    97  				return gax.OnCodes([]codes.Code{
    98  					codes.DeadlineExceeded,
    99  					codes.Unavailable,
   100  				}, gax.Backoff{
   101  					Initial:    1000 * time.Millisecond,
   102  					Max:        60000 * time.Millisecond,
   103  					Multiplier: 2.00,
   104  				})
   105  			}),
   106  		},
   107  		GetBucket: []gax.CallOption{
   108  			gax.WithTimeout(60000 * time.Millisecond),
   109  			gax.WithRetry(func() gax.Retryer {
   110  				return gax.OnCodes([]codes.Code{
   111  					codes.DeadlineExceeded,
   112  					codes.Unavailable,
   113  				}, gax.Backoff{
   114  					Initial:    1000 * time.Millisecond,
   115  					Max:        60000 * time.Millisecond,
   116  					Multiplier: 2.00,
   117  				})
   118  			}),
   119  		},
   120  		CreateBucket: []gax.CallOption{
   121  			gax.WithTimeout(60000 * time.Millisecond),
   122  			gax.WithRetry(func() gax.Retryer {
   123  				return gax.OnCodes([]codes.Code{
   124  					codes.DeadlineExceeded,
   125  					codes.Unavailable,
   126  				}, gax.Backoff{
   127  					Initial:    1000 * time.Millisecond,
   128  					Max:        60000 * time.Millisecond,
   129  					Multiplier: 2.00,
   130  				})
   131  			}),
   132  		},
   133  		ListBuckets: []gax.CallOption{
   134  			gax.WithTimeout(60000 * time.Millisecond),
   135  			gax.WithRetry(func() gax.Retryer {
   136  				return gax.OnCodes([]codes.Code{
   137  					codes.DeadlineExceeded,
   138  					codes.Unavailable,
   139  				}, gax.Backoff{
   140  					Initial:    1000 * time.Millisecond,
   141  					Max:        60000 * time.Millisecond,
   142  					Multiplier: 2.00,
   143  				})
   144  			}),
   145  		},
   146  		LockBucketRetentionPolicy: []gax.CallOption{
   147  			gax.WithTimeout(60000 * time.Millisecond),
   148  			gax.WithRetry(func() gax.Retryer {
   149  				return gax.OnCodes([]codes.Code{
   150  					codes.DeadlineExceeded,
   151  					codes.Unavailable,
   152  				}, gax.Backoff{
   153  					Initial:    1000 * time.Millisecond,
   154  					Max:        60000 * time.Millisecond,
   155  					Multiplier: 2.00,
   156  				})
   157  			}),
   158  		},
   159  		GetIamPolicy: []gax.CallOption{
   160  			gax.WithTimeout(60000 * time.Millisecond),
   161  			gax.WithRetry(func() gax.Retryer {
   162  				return gax.OnCodes([]codes.Code{
   163  					codes.DeadlineExceeded,
   164  					codes.Unavailable,
   165  				}, gax.Backoff{
   166  					Initial:    1000 * time.Millisecond,
   167  					Max:        60000 * time.Millisecond,
   168  					Multiplier: 2.00,
   169  				})
   170  			}),
   171  		},
   172  		SetIamPolicy: []gax.CallOption{
   173  			gax.WithTimeout(60000 * time.Millisecond),
   174  			gax.WithRetry(func() gax.Retryer {
   175  				return gax.OnCodes([]codes.Code{
   176  					codes.DeadlineExceeded,
   177  					codes.Unavailable,
   178  				}, gax.Backoff{
   179  					Initial:    1000 * time.Millisecond,
   180  					Max:        60000 * time.Millisecond,
   181  					Multiplier: 2.00,
   182  				})
   183  			}),
   184  		},
   185  		TestIamPermissions: []gax.CallOption{
   186  			gax.WithTimeout(60000 * time.Millisecond),
   187  			gax.WithRetry(func() gax.Retryer {
   188  				return gax.OnCodes([]codes.Code{
   189  					codes.DeadlineExceeded,
   190  					codes.Unavailable,
   191  				}, gax.Backoff{
   192  					Initial:    1000 * time.Millisecond,
   193  					Max:        60000 * time.Millisecond,
   194  					Multiplier: 2.00,
   195  				})
   196  			}),
   197  		},
   198  		UpdateBucket: []gax.CallOption{
   199  			gax.WithTimeout(60000 * time.Millisecond),
   200  			gax.WithRetry(func() gax.Retryer {
   201  				return gax.OnCodes([]codes.Code{
   202  					codes.DeadlineExceeded,
   203  					codes.Unavailable,
   204  				}, gax.Backoff{
   205  					Initial:    1000 * time.Millisecond,
   206  					Max:        60000 * time.Millisecond,
   207  					Multiplier: 2.00,
   208  				})
   209  			}),
   210  		},
   211  		DeleteNotificationConfig: []gax.CallOption{
   212  			gax.WithTimeout(60000 * time.Millisecond),
   213  			gax.WithRetry(func() gax.Retryer {
   214  				return gax.OnCodes([]codes.Code{
   215  					codes.DeadlineExceeded,
   216  					codes.Unavailable,
   217  				}, gax.Backoff{
   218  					Initial:    1000 * time.Millisecond,
   219  					Max:        60000 * time.Millisecond,
   220  					Multiplier: 2.00,
   221  				})
   222  			}),
   223  		},
   224  		GetNotificationConfig: []gax.CallOption{
   225  			gax.WithTimeout(60000 * time.Millisecond),
   226  			gax.WithRetry(func() gax.Retryer {
   227  				return gax.OnCodes([]codes.Code{
   228  					codes.DeadlineExceeded,
   229  					codes.Unavailable,
   230  				}, gax.Backoff{
   231  					Initial:    1000 * time.Millisecond,
   232  					Max:        60000 * time.Millisecond,
   233  					Multiplier: 2.00,
   234  				})
   235  			}),
   236  		},
   237  		CreateNotificationConfig: []gax.CallOption{
   238  			gax.WithTimeout(60000 * time.Millisecond),
   239  			gax.WithRetry(func() gax.Retryer {
   240  				return gax.OnCodes([]codes.Code{
   241  					codes.DeadlineExceeded,
   242  					codes.Unavailable,
   243  				}, gax.Backoff{
   244  					Initial:    1000 * time.Millisecond,
   245  					Max:        60000 * time.Millisecond,
   246  					Multiplier: 2.00,
   247  				})
   248  			}),
   249  		},
   250  		ListNotificationConfigs: []gax.CallOption{
   251  			gax.WithTimeout(60000 * time.Millisecond),
   252  			gax.WithRetry(func() gax.Retryer {
   253  				return gax.OnCodes([]codes.Code{
   254  					codes.DeadlineExceeded,
   255  					codes.Unavailable,
   256  				}, gax.Backoff{
   257  					Initial:    1000 * time.Millisecond,
   258  					Max:        60000 * time.Millisecond,
   259  					Multiplier: 2.00,
   260  				})
   261  			}),
   262  		},
   263  		ComposeObject: []gax.CallOption{
   264  			gax.WithTimeout(60000 * time.Millisecond),
   265  			gax.WithRetry(func() gax.Retryer {
   266  				return gax.OnCodes([]codes.Code{
   267  					codes.DeadlineExceeded,
   268  					codes.Unavailable,
   269  				}, gax.Backoff{
   270  					Initial:    1000 * time.Millisecond,
   271  					Max:        60000 * time.Millisecond,
   272  					Multiplier: 2.00,
   273  				})
   274  			}),
   275  		},
   276  		DeleteObject: []gax.CallOption{
   277  			gax.WithTimeout(60000 * time.Millisecond),
   278  			gax.WithRetry(func() gax.Retryer {
   279  				return gax.OnCodes([]codes.Code{
   280  					codes.DeadlineExceeded,
   281  					codes.Unavailable,
   282  				}, gax.Backoff{
   283  					Initial:    1000 * time.Millisecond,
   284  					Max:        60000 * time.Millisecond,
   285  					Multiplier: 2.00,
   286  				})
   287  			}),
   288  		},
   289  		RestoreObject: []gax.CallOption{
   290  			gax.WithTimeout(60000 * time.Millisecond),
   291  			gax.WithRetry(func() gax.Retryer {
   292  				return gax.OnCodes([]codes.Code{
   293  					codes.DeadlineExceeded,
   294  					codes.Unavailable,
   295  				}, gax.Backoff{
   296  					Initial:    1000 * time.Millisecond,
   297  					Max:        60000 * time.Millisecond,
   298  					Multiplier: 2.00,
   299  				})
   300  			}),
   301  		},
   302  		CancelResumableWrite: []gax.CallOption{
   303  			gax.WithTimeout(60000 * time.Millisecond),
   304  			gax.WithRetry(func() gax.Retryer {
   305  				return gax.OnCodes([]codes.Code{
   306  					codes.DeadlineExceeded,
   307  					codes.Unavailable,
   308  				}, gax.Backoff{
   309  					Initial:    1000 * time.Millisecond,
   310  					Max:        60000 * time.Millisecond,
   311  					Multiplier: 2.00,
   312  				})
   313  			}),
   314  		},
   315  		GetObject: []gax.CallOption{
   316  			gax.WithTimeout(60000 * time.Millisecond),
   317  			gax.WithRetry(func() gax.Retryer {
   318  				return gax.OnCodes([]codes.Code{
   319  					codes.DeadlineExceeded,
   320  					codes.Unavailable,
   321  				}, gax.Backoff{
   322  					Initial:    1000 * time.Millisecond,
   323  					Max:        60000 * time.Millisecond,
   324  					Multiplier: 2.00,
   325  				})
   326  			}),
   327  		},
   328  		ReadObject: []gax.CallOption{
   329  			gax.WithRetry(func() gax.Retryer {
   330  				return gax.OnCodes([]codes.Code{
   331  					codes.DeadlineExceeded,
   332  					codes.Unavailable,
   333  				}, gax.Backoff{
   334  					Initial:    1000 * time.Millisecond,
   335  					Max:        60000 * time.Millisecond,
   336  					Multiplier: 2.00,
   337  				})
   338  			}),
   339  		},
   340  		UpdateObject: []gax.CallOption{
   341  			gax.WithTimeout(60000 * time.Millisecond),
   342  			gax.WithRetry(func() gax.Retryer {
   343  				return gax.OnCodes([]codes.Code{
   344  					codes.DeadlineExceeded,
   345  					codes.Unavailable,
   346  				}, gax.Backoff{
   347  					Initial:    1000 * time.Millisecond,
   348  					Max:        60000 * time.Millisecond,
   349  					Multiplier: 2.00,
   350  				})
   351  			}),
   352  		},
   353  		WriteObject: []gax.CallOption{
   354  			gax.WithRetry(func() gax.Retryer {
   355  				return gax.OnCodes([]codes.Code{
   356  					codes.DeadlineExceeded,
   357  					codes.Unavailable,
   358  				}, gax.Backoff{
   359  					Initial:    1000 * time.Millisecond,
   360  					Max:        60000 * time.Millisecond,
   361  					Multiplier: 2.00,
   362  				})
   363  			}),
   364  		},
   365  		BidiWriteObject: []gax.CallOption{
   366  			gax.WithRetry(func() gax.Retryer {
   367  				return gax.OnCodes([]codes.Code{
   368  					codes.DeadlineExceeded,
   369  					codes.Unavailable,
   370  				}, gax.Backoff{
   371  					Initial:    1000 * time.Millisecond,
   372  					Max:        60000 * time.Millisecond,
   373  					Multiplier: 2.00,
   374  				})
   375  			}),
   376  		},
   377  		ListObjects: []gax.CallOption{
   378  			gax.WithTimeout(60000 * time.Millisecond),
   379  			gax.WithRetry(func() gax.Retryer {
   380  				return gax.OnCodes([]codes.Code{
   381  					codes.DeadlineExceeded,
   382  					codes.Unavailable,
   383  				}, gax.Backoff{
   384  					Initial:    1000 * time.Millisecond,
   385  					Max:        60000 * time.Millisecond,
   386  					Multiplier: 2.00,
   387  				})
   388  			}),
   389  		},
   390  		RewriteObject: []gax.CallOption{
   391  			gax.WithTimeout(60000 * time.Millisecond),
   392  			gax.WithRetry(func() gax.Retryer {
   393  				return gax.OnCodes([]codes.Code{
   394  					codes.DeadlineExceeded,
   395  					codes.Unavailable,
   396  				}, gax.Backoff{
   397  					Initial:    1000 * time.Millisecond,
   398  					Max:        60000 * time.Millisecond,
   399  					Multiplier: 2.00,
   400  				})
   401  			}),
   402  		},
   403  		StartResumableWrite: []gax.CallOption{
   404  			gax.WithTimeout(60000 * time.Millisecond),
   405  			gax.WithRetry(func() gax.Retryer {
   406  				return gax.OnCodes([]codes.Code{
   407  					codes.DeadlineExceeded,
   408  					codes.Unavailable,
   409  				}, gax.Backoff{
   410  					Initial:    1000 * time.Millisecond,
   411  					Max:        60000 * time.Millisecond,
   412  					Multiplier: 2.00,
   413  				})
   414  			}),
   415  		},
   416  		QueryWriteStatus: []gax.CallOption{
   417  			gax.WithTimeout(60000 * time.Millisecond),
   418  			gax.WithRetry(func() gax.Retryer {
   419  				return gax.OnCodes([]codes.Code{
   420  					codes.DeadlineExceeded,
   421  					codes.Unavailable,
   422  				}, gax.Backoff{
   423  					Initial:    1000 * time.Millisecond,
   424  					Max:        60000 * time.Millisecond,
   425  					Multiplier: 2.00,
   426  				})
   427  			}),
   428  		},
   429  		GetServiceAccount: []gax.CallOption{
   430  			gax.WithTimeout(60000 * time.Millisecond),
   431  			gax.WithRetry(func() gax.Retryer {
   432  				return gax.OnCodes([]codes.Code{
   433  					codes.DeadlineExceeded,
   434  					codes.Unavailable,
   435  				}, gax.Backoff{
   436  					Initial:    1000 * time.Millisecond,
   437  					Max:        60000 * time.Millisecond,
   438  					Multiplier: 2.00,
   439  				})
   440  			}),
   441  		},
   442  		CreateHmacKey: []gax.CallOption{
   443  			gax.WithTimeout(60000 * time.Millisecond),
   444  			gax.WithRetry(func() gax.Retryer {
   445  				return gax.OnCodes([]codes.Code{
   446  					codes.DeadlineExceeded,
   447  					codes.Unavailable,
   448  				}, gax.Backoff{
   449  					Initial:    1000 * time.Millisecond,
   450  					Max:        60000 * time.Millisecond,
   451  					Multiplier: 2.00,
   452  				})
   453  			}),
   454  		},
   455  		DeleteHmacKey: []gax.CallOption{
   456  			gax.WithTimeout(60000 * time.Millisecond),
   457  			gax.WithRetry(func() gax.Retryer {
   458  				return gax.OnCodes([]codes.Code{
   459  					codes.DeadlineExceeded,
   460  					codes.Unavailable,
   461  				}, gax.Backoff{
   462  					Initial:    1000 * time.Millisecond,
   463  					Max:        60000 * time.Millisecond,
   464  					Multiplier: 2.00,
   465  				})
   466  			}),
   467  		},
   468  		GetHmacKey: []gax.CallOption{
   469  			gax.WithTimeout(60000 * time.Millisecond),
   470  			gax.WithRetry(func() gax.Retryer {
   471  				return gax.OnCodes([]codes.Code{
   472  					codes.DeadlineExceeded,
   473  					codes.Unavailable,
   474  				}, gax.Backoff{
   475  					Initial:    1000 * time.Millisecond,
   476  					Max:        60000 * time.Millisecond,
   477  					Multiplier: 2.00,
   478  				})
   479  			}),
   480  		},
   481  		ListHmacKeys: []gax.CallOption{
   482  			gax.WithTimeout(60000 * time.Millisecond),
   483  			gax.WithRetry(func() gax.Retryer {
   484  				return gax.OnCodes([]codes.Code{
   485  					codes.DeadlineExceeded,
   486  					codes.Unavailable,
   487  				}, gax.Backoff{
   488  					Initial:    1000 * time.Millisecond,
   489  					Max:        60000 * time.Millisecond,
   490  					Multiplier: 2.00,
   491  				})
   492  			}),
   493  		},
   494  		UpdateHmacKey: []gax.CallOption{
   495  			gax.WithTimeout(60000 * time.Millisecond),
   496  			gax.WithRetry(func() gax.Retryer {
   497  				return gax.OnCodes([]codes.Code{
   498  					codes.DeadlineExceeded,
   499  					codes.Unavailable,
   500  				}, gax.Backoff{
   501  					Initial:    1000 * time.Millisecond,
   502  					Max:        60000 * time.Millisecond,
   503  					Multiplier: 2.00,
   504  				})
   505  			}),
   506  		},
   507  	}
   508  }
   509  
   510  // internalClient is an interface that defines the methods available from Cloud Storage API.
   511  type internalClient interface {
   512  	Close() error
   513  	setGoogleClientInfo(...string)
   514  	Connection() *grpc.ClientConn
   515  	DeleteBucket(context.Context, *storagepb.DeleteBucketRequest, ...gax.CallOption) error
   516  	GetBucket(context.Context, *storagepb.GetBucketRequest, ...gax.CallOption) (*storagepb.Bucket, error)
   517  	CreateBucket(context.Context, *storagepb.CreateBucketRequest, ...gax.CallOption) (*storagepb.Bucket, error)
   518  	ListBuckets(context.Context, *storagepb.ListBucketsRequest, ...gax.CallOption) *BucketIterator
   519  	LockBucketRetentionPolicy(context.Context, *storagepb.LockBucketRetentionPolicyRequest, ...gax.CallOption) (*storagepb.Bucket, error)
   520  	GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   521  	SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
   522  	TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
   523  	UpdateBucket(context.Context, *storagepb.UpdateBucketRequest, ...gax.CallOption) (*storagepb.Bucket, error)
   524  	DeleteNotificationConfig(context.Context, *storagepb.DeleteNotificationConfigRequest, ...gax.CallOption) error
   525  	GetNotificationConfig(context.Context, *storagepb.GetNotificationConfigRequest, ...gax.CallOption) (*storagepb.NotificationConfig, error)
   526  	CreateNotificationConfig(context.Context, *storagepb.CreateNotificationConfigRequest, ...gax.CallOption) (*storagepb.NotificationConfig, error)
   527  	ListNotificationConfigs(context.Context, *storagepb.ListNotificationConfigsRequest, ...gax.CallOption) *NotificationConfigIterator
   528  	ComposeObject(context.Context, *storagepb.ComposeObjectRequest, ...gax.CallOption) (*storagepb.Object, error)
   529  	DeleteObject(context.Context, *storagepb.DeleteObjectRequest, ...gax.CallOption) error
   530  	RestoreObject(context.Context, *storagepb.RestoreObjectRequest, ...gax.CallOption) (*storagepb.Object, error)
   531  	CancelResumableWrite(context.Context, *storagepb.CancelResumableWriteRequest, ...gax.CallOption) (*storagepb.CancelResumableWriteResponse, error)
   532  	GetObject(context.Context, *storagepb.GetObjectRequest, ...gax.CallOption) (*storagepb.Object, error)
   533  	ReadObject(context.Context, *storagepb.ReadObjectRequest, ...gax.CallOption) (storagepb.Storage_ReadObjectClient, error)
   534  	UpdateObject(context.Context, *storagepb.UpdateObjectRequest, ...gax.CallOption) (*storagepb.Object, error)
   535  	WriteObject(context.Context, ...gax.CallOption) (storagepb.Storage_WriteObjectClient, error)
   536  	BidiWriteObject(context.Context, ...gax.CallOption) (storagepb.Storage_BidiWriteObjectClient, error)
   537  	ListObjects(context.Context, *storagepb.ListObjectsRequest, ...gax.CallOption) *ObjectIterator
   538  	RewriteObject(context.Context, *storagepb.RewriteObjectRequest, ...gax.CallOption) (*storagepb.RewriteResponse, error)
   539  	StartResumableWrite(context.Context, *storagepb.StartResumableWriteRequest, ...gax.CallOption) (*storagepb.StartResumableWriteResponse, error)
   540  	QueryWriteStatus(context.Context, *storagepb.QueryWriteStatusRequest, ...gax.CallOption) (*storagepb.QueryWriteStatusResponse, error)
   541  	GetServiceAccount(context.Context, *storagepb.GetServiceAccountRequest, ...gax.CallOption) (*storagepb.ServiceAccount, error)
   542  	CreateHmacKey(context.Context, *storagepb.CreateHmacKeyRequest, ...gax.CallOption) (*storagepb.CreateHmacKeyResponse, error)
   543  	DeleteHmacKey(context.Context, *storagepb.DeleteHmacKeyRequest, ...gax.CallOption) error
   544  	GetHmacKey(context.Context, *storagepb.GetHmacKeyRequest, ...gax.CallOption) (*storagepb.HmacKeyMetadata, error)
   545  	ListHmacKeys(context.Context, *storagepb.ListHmacKeysRequest, ...gax.CallOption) *HmacKeyMetadataIterator
   546  	UpdateHmacKey(context.Context, *storagepb.UpdateHmacKeyRequest, ...gax.CallOption) (*storagepb.HmacKeyMetadata, error)
   547  }
   548  
   549  // Client is a client for interacting with Cloud Storage API.
   550  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   551  //
   552  // API Overview and Naming SyntaxThe Cloud Storage gRPC API allows applications to read and write data through
   553  // the abstractions of buckets and objects. For a description of these
   554  // abstractions please see https://cloud.google.com/storage/docs (at https://cloud.google.com/storage/docs).
   555  //
   556  // Resources are named as follows:
   557  //
   558  //	Projects are referred to as they are defined by the Resource Manager API,
   559  //	using strings like projects/123456 or projects/my-string-id.
   560  //
   561  //	Buckets are named using string names of the form:
   562  //	projects/{project}/buckets/{bucket}
   563  //	For globally unique buckets, _ may be substituted for the project.
   564  //
   565  //	Objects are uniquely identified by their name along with the name of the
   566  //	bucket they belong to, as separate strings in this API. For example:
   567  //
   568  //	ReadObjectRequest {
   569  //	  bucket: ‘projects/_/buckets/my-bucket’
   570  //	  object: ‘my-object’
   571  //	  }
   572  //	  Note that object names can contain / characters, which are treated as
   573  //	  any other character (no special directory semantics).
   574  type Client struct {
   575  	// The internal transport-dependent client.
   576  	internalClient internalClient
   577  
   578  	// The call options for this service.
   579  	CallOptions *CallOptions
   580  }
   581  
   582  // Wrapper methods routed to the internal client.
   583  
   584  // Close closes the connection to the API service. The user should invoke this when
   585  // the client is no longer required.
   586  func (c *Client) Close() error {
   587  	return c.internalClient.Close()
   588  }
   589  
   590  // setGoogleClientInfo sets the name and version of the application in
   591  // the `x-goog-api-client` header passed on each request. Intended for
   592  // use by Google-written clients.
   593  func (c *Client) setGoogleClientInfo(keyval ...string) {
   594  	c.internalClient.setGoogleClientInfo(keyval...)
   595  }
   596  
   597  // Connection returns a connection to the API service.
   598  //
   599  // Deprecated: Connections are now pooled so this method does not always
   600  // return the same resource.
   601  func (c *Client) Connection() *grpc.ClientConn {
   602  	return c.internalClient.Connection()
   603  }
   604  
   605  // DeleteBucket permanently deletes an empty bucket.
   606  func (c *Client) DeleteBucket(ctx context.Context, req *storagepb.DeleteBucketRequest, opts ...gax.CallOption) error {
   607  	return c.internalClient.DeleteBucket(ctx, req, opts...)
   608  }
   609  
   610  // GetBucket returns metadata for the specified bucket.
   611  func (c *Client) GetBucket(ctx context.Context, req *storagepb.GetBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) {
   612  	return c.internalClient.GetBucket(ctx, req, opts...)
   613  }
   614  
   615  // CreateBucket creates a new bucket.
   616  func (c *Client) CreateBucket(ctx context.Context, req *storagepb.CreateBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) {
   617  	return c.internalClient.CreateBucket(ctx, req, opts...)
   618  }
   619  
   620  // ListBuckets retrieves a list of buckets for a given project.
   621  func (c *Client) ListBuckets(ctx context.Context, req *storagepb.ListBucketsRequest, opts ...gax.CallOption) *BucketIterator {
   622  	return c.internalClient.ListBuckets(ctx, req, opts...)
   623  }
   624  
   625  // LockBucketRetentionPolicy locks retention policy on a bucket.
   626  func (c *Client) LockBucketRetentionPolicy(ctx context.Context, req *storagepb.LockBucketRetentionPolicyRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) {
   627  	return c.internalClient.LockBucketRetentionPolicy(ctx, req, opts...)
   628  }
   629  
   630  // GetIamPolicy gets the IAM policy for a specified bucket.
   631  // The resource field in the request should be
   632  // projects/_/buckets/{bucket}.
   633  func (c *Client) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   634  	return c.internalClient.GetIamPolicy(ctx, req, opts...)
   635  }
   636  
   637  // SetIamPolicy updates an IAM policy for the specified bucket.
   638  // The resource field in the request should be
   639  // projects/_/buckets/{bucket}.
   640  func (c *Client) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
   641  	return c.internalClient.SetIamPolicy(ctx, req, opts...)
   642  }
   643  
   644  // TestIamPermissions tests a set of permissions on the given bucket or object to see which, if
   645  // any, are held by the caller.
   646  // The resource field in the request should be
   647  // projects/_/buckets/{bucket} for a bucket or
   648  // projects/_/buckets/{bucket}/objects/{object} for an object.
   649  func (c *Client) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
   650  	return c.internalClient.TestIamPermissions(ctx, req, opts...)
   651  }
   652  
   653  // UpdateBucket updates a bucket. Equivalent to JSON API’s storage.buckets.patch method.
   654  func (c *Client) UpdateBucket(ctx context.Context, req *storagepb.UpdateBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) {
   655  	return c.internalClient.UpdateBucket(ctx, req, opts...)
   656  }
   657  
   658  // DeleteNotificationConfig permanently deletes a NotificationConfig.
   659  func (c *Client) DeleteNotificationConfig(ctx context.Context, req *storagepb.DeleteNotificationConfigRequest, opts ...gax.CallOption) error {
   660  	return c.internalClient.DeleteNotificationConfig(ctx, req, opts...)
   661  }
   662  
   663  // GetNotificationConfig view a NotificationConfig.
   664  func (c *Client) GetNotificationConfig(ctx context.Context, req *storagepb.GetNotificationConfigRequest, opts ...gax.CallOption) (*storagepb.NotificationConfig, error) {
   665  	return c.internalClient.GetNotificationConfig(ctx, req, opts...)
   666  }
   667  
   668  // CreateNotificationConfig creates a NotificationConfig for a given bucket.
   669  // These NotificationConfigs, when triggered, publish messages to the
   670  // specified Pub/Sub topics. See
   671  // https://cloud.google.com/storage/docs/pubsub-notifications (at https://cloud.google.com/storage/docs/pubsub-notifications).
   672  func (c *Client) CreateNotificationConfig(ctx context.Context, req *storagepb.CreateNotificationConfigRequest, opts ...gax.CallOption) (*storagepb.NotificationConfig, error) {
   673  	return c.internalClient.CreateNotificationConfig(ctx, req, opts...)
   674  }
   675  
   676  // ListNotificationConfigs retrieves a list of NotificationConfigs for a given bucket.
   677  func (c *Client) ListNotificationConfigs(ctx context.Context, req *storagepb.ListNotificationConfigsRequest, opts ...gax.CallOption) *NotificationConfigIterator {
   678  	return c.internalClient.ListNotificationConfigs(ctx, req, opts...)
   679  }
   680  
   681  // ComposeObject concatenates a list of existing objects into a new object in the same
   682  // bucket.
   683  func (c *Client) ComposeObject(ctx context.Context, req *storagepb.ComposeObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) {
   684  	return c.internalClient.ComposeObject(ctx, req, opts...)
   685  }
   686  
   687  // DeleteObject deletes an object and its metadata.
   688  //
   689  // Deletions are normally permanent when versioning is disabled or whenever
   690  // the generation parameter is used. However, if soft delete is enabled for
   691  // the bucket, deleted objects can be restored using RestoreObject until the
   692  // soft delete retention period has passed.
   693  func (c *Client) DeleteObject(ctx context.Context, req *storagepb.DeleteObjectRequest, opts ...gax.CallOption) error {
   694  	return c.internalClient.DeleteObject(ctx, req, opts...)
   695  }
   696  
   697  // RestoreObject restores a soft-deleted object.
   698  func (c *Client) RestoreObject(ctx context.Context, req *storagepb.RestoreObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) {
   699  	return c.internalClient.RestoreObject(ctx, req, opts...)
   700  }
   701  
   702  // CancelResumableWrite cancels an in-progress resumable upload.
   703  //
   704  // Any attempts to write to the resumable upload after cancelling the upload
   705  // will fail.
   706  //
   707  // The behavior for currently in progress write operations is not guaranteed -
   708  // they could either complete before the cancellation or fail if the
   709  // cancellation completes first.
   710  func (c *Client) CancelResumableWrite(ctx context.Context, req *storagepb.CancelResumableWriteRequest, opts ...gax.CallOption) (*storagepb.CancelResumableWriteResponse, error) {
   711  	return c.internalClient.CancelResumableWrite(ctx, req, opts...)
   712  }
   713  
   714  // GetObject retrieves an object’s metadata.
   715  func (c *Client) GetObject(ctx context.Context, req *storagepb.GetObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) {
   716  	return c.internalClient.GetObject(ctx, req, opts...)
   717  }
   718  
   719  // ReadObject reads an object’s data.
   720  func (c *Client) ReadObject(ctx context.Context, req *storagepb.ReadObjectRequest, opts ...gax.CallOption) (storagepb.Storage_ReadObjectClient, error) {
   721  	return c.internalClient.ReadObject(ctx, req, opts...)
   722  }
   723  
   724  // UpdateObject updates an object’s metadata.
   725  // Equivalent to JSON API’s storage.objects.patch.
   726  func (c *Client) UpdateObject(ctx context.Context, req *storagepb.UpdateObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) {
   727  	return c.internalClient.UpdateObject(ctx, req, opts...)
   728  }
   729  
   730  // WriteObject stores a new object and metadata.
   731  //
   732  // An object can be written either in a single message stream or in a
   733  // resumable sequence of message streams. To write using a single stream,
   734  // the client should include in the first message of the stream an
   735  // WriteObjectSpec describing the destination bucket, object, and any
   736  // preconditions. Additionally, the final message must set ‘finish_write’ to
   737  // true, or else it is an error.
   738  //
   739  // For a resumable write, the client should instead call
   740  // StartResumableWrite(), populating a WriteObjectSpec into that request.
   741  // They should then attach the returned upload_id to the first message of
   742  // each following call to WriteObject. If the stream is closed before
   743  // finishing the upload (either explicitly by the client or due to a network
   744  // error or an error response from the server), the client should do as
   745  // follows:
   746  //
   747  //	Check the result Status of the stream, to determine if writing can be
   748  //	resumed on this stream or must be restarted from scratch (by calling
   749  //	StartResumableWrite()). The resumable errors are DEADLINE_EXCEEDED,
   750  //	INTERNAL, and UNAVAILABLE. For each case, the client should use binary
   751  //	exponential backoff before retrying.  Additionally, writes can be
   752  //	resumed after RESOURCE_EXHAUSTED errors, but only after taking
   753  //	appropriate measures, which may include reducing aggregate send rate
   754  //	across clients and/or requesting a quota increase for your project.
   755  //
   756  //	If the call to WriteObject returns ABORTED, that indicates
   757  //	concurrent attempts to update the resumable write, caused either by
   758  //	multiple racing clients or by a single client where the previous
   759  //	request was timed out on the client side but nonetheless reached the
   760  //	server. In this case the client should take steps to prevent further
   761  //	concurrent writes (e.g., increase the timeouts, stop using more than
   762  //	one process to perform the upload, etc.), and then should follow the
   763  //	steps below for resuming the upload.
   764  //
   765  //	For resumable errors, the client should call QueryWriteStatus() and
   766  //	then continue writing from the returned persisted_size. This may be
   767  //	less than the amount of data the client previously sent. Note also that
   768  //	it is acceptable to send data starting at an offset earlier than the
   769  //	returned persisted_size; in this case, the service will skip data at
   770  //	offsets that were already persisted (without checking that it matches
   771  //	the previously written data), and write only the data starting from the
   772  //	persisted offset. Even though the data isn’t written, it may still
   773  //	incur a performance cost over resuming at the correct write offset.
   774  //	This behavior can make client-side handling simpler in some cases.
   775  //
   776  //	Clients must only send data that is a multiple of 256 KiB per message,
   777  //	unless the object is being finished with finish_write set to true.
   778  //
   779  // The service will not view the object as complete until the client has
   780  // sent a WriteObjectRequest with finish_write set to true. Sending any
   781  // requests on a stream after sending a request with finish_write set to
   782  // true will cause an error. The client should check the response it
   783  // receives to determine how much data the service was able to commit and
   784  // whether the service views the object as complete.
   785  //
   786  // Attempting to resume an already finalized object will result in an OK
   787  // status, with a WriteObjectResponse containing the finalized object’s
   788  // metadata.
   789  //
   790  // Alternatively, the BidiWriteObject operation may be used to write an
   791  // object with controls over flushing and the ability to fetch the ability to
   792  // determine the current persisted size.
   793  func (c *Client) WriteObject(ctx context.Context, opts ...gax.CallOption) (storagepb.Storage_WriteObjectClient, error) {
   794  	return c.internalClient.WriteObject(ctx, opts...)
   795  }
   796  
   797  // BidiWriteObject stores a new object and metadata.
   798  //
   799  // This is similar to the WriteObject call with the added support for
   800  // manual flushing of persisted state, and the ability to determine current
   801  // persisted size without closing the stream.
   802  //
   803  // The client may specify one or both of the state_lookup and flush fields
   804  // in each BidiWriteObjectRequest. If flush is specified, the data written
   805  // so far will be persisted to storage. If state_lookup is specified, the
   806  // service will respond with a BidiWriteObjectResponse that contains the
   807  // persisted size. If both flush and state_lookup are specified, the flush
   808  // will always occur before a state_lookup, so that both may be set in the
   809  // same request and the returned state will be the state of the object
   810  // post-flush. When the stream is closed, a BidiWriteObjectResponse will
   811  // always be sent to the client, regardless of the value of state_lookup.
   812  func (c *Client) BidiWriteObject(ctx context.Context, opts ...gax.CallOption) (storagepb.Storage_BidiWriteObjectClient, error) {
   813  	return c.internalClient.BidiWriteObject(ctx, opts...)
   814  }
   815  
   816  // ListObjects retrieves a list of objects matching the criteria.
   817  func (c *Client) ListObjects(ctx context.Context, req *storagepb.ListObjectsRequest, opts ...gax.CallOption) *ObjectIterator {
   818  	return c.internalClient.ListObjects(ctx, req, opts...)
   819  }
   820  
   821  // RewriteObject rewrites a source object to a destination object. Optionally overrides
   822  // metadata.
   823  func (c *Client) RewriteObject(ctx context.Context, req *storagepb.RewriteObjectRequest, opts ...gax.CallOption) (*storagepb.RewriteResponse, error) {
   824  	return c.internalClient.RewriteObject(ctx, req, opts...)
   825  }
   826  
   827  // StartResumableWrite starts a resumable write. How long the write operation remains valid, and
   828  // what happens when the write operation becomes invalid, are
   829  // service-dependent.
   830  func (c *Client) StartResumableWrite(ctx context.Context, req *storagepb.StartResumableWriteRequest, opts ...gax.CallOption) (*storagepb.StartResumableWriteResponse, error) {
   831  	return c.internalClient.StartResumableWrite(ctx, req, opts...)
   832  }
   833  
   834  // QueryWriteStatus determines the persisted_size for an object that is being written, which
   835  // can then be used as the write_offset for the next Write() call.
   836  //
   837  // If the object does not exist (i.e., the object has been deleted, or the
   838  // first Write() has not yet reached the service), this method returns the
   839  // error NOT_FOUND.
   840  //
   841  // The client may call QueryWriteStatus() at any time to determine how
   842  // much data has been processed for this object. This is useful if the
   843  // client is buffering data and needs to know which data can be safely
   844  // evicted. For any sequence of QueryWriteStatus() calls for a given
   845  // object name, the sequence of returned persisted_size values will be
   846  // non-decreasing.
   847  func (c *Client) QueryWriteStatus(ctx context.Context, req *storagepb.QueryWriteStatusRequest, opts ...gax.CallOption) (*storagepb.QueryWriteStatusResponse, error) {
   848  	return c.internalClient.QueryWriteStatus(ctx, req, opts...)
   849  }
   850  
   851  // GetServiceAccount retrieves the name of a project’s Google Cloud Storage service account.
   852  func (c *Client) GetServiceAccount(ctx context.Context, req *storagepb.GetServiceAccountRequest, opts ...gax.CallOption) (*storagepb.ServiceAccount, error) {
   853  	return c.internalClient.GetServiceAccount(ctx, req, opts...)
   854  }
   855  
   856  // CreateHmacKey creates a new HMAC key for the given service account.
   857  func (c *Client) CreateHmacKey(ctx context.Context, req *storagepb.CreateHmacKeyRequest, opts ...gax.CallOption) (*storagepb.CreateHmacKeyResponse, error) {
   858  	return c.internalClient.CreateHmacKey(ctx, req, opts...)
   859  }
   860  
   861  // DeleteHmacKey deletes a given HMAC key.  Key must be in an INACTIVE state.
   862  func (c *Client) DeleteHmacKey(ctx context.Context, req *storagepb.DeleteHmacKeyRequest, opts ...gax.CallOption) error {
   863  	return c.internalClient.DeleteHmacKey(ctx, req, opts...)
   864  }
   865  
   866  // GetHmacKey gets an existing HMAC key metadata for the given id.
   867  func (c *Client) GetHmacKey(ctx context.Context, req *storagepb.GetHmacKeyRequest, opts ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) {
   868  	return c.internalClient.GetHmacKey(ctx, req, opts...)
   869  }
   870  
   871  // ListHmacKeys lists HMAC keys under a given project with the additional filters provided.
   872  func (c *Client) ListHmacKeys(ctx context.Context, req *storagepb.ListHmacKeysRequest, opts ...gax.CallOption) *HmacKeyMetadataIterator {
   873  	return c.internalClient.ListHmacKeys(ctx, req, opts...)
   874  }
   875  
   876  // UpdateHmacKey updates a given HMAC key state between ACTIVE and INACTIVE.
   877  func (c *Client) UpdateHmacKey(ctx context.Context, req *storagepb.UpdateHmacKeyRequest, opts ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) {
   878  	return c.internalClient.UpdateHmacKey(ctx, req, opts...)
   879  }
   880  
   881  // gRPCClient is a client for interacting with Cloud Storage API over gRPC transport.
   882  //
   883  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   884  type gRPCClient struct {
   885  	// Connection pool of gRPC connections to the service.
   886  	connPool gtransport.ConnPool
   887  
   888  	// Points back to the CallOptions field of the containing Client
   889  	CallOptions **CallOptions
   890  
   891  	// The gRPC API client.
   892  	client storagepb.StorageClient
   893  
   894  	// The x-goog-* metadata to be sent with each request.
   895  	xGoogHeaders []string
   896  }
   897  
   898  // NewClient creates a new storage client based on gRPC.
   899  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   900  //
   901  // API Overview and Naming SyntaxThe Cloud Storage gRPC API allows applications to read and write data through
   902  // the abstractions of buckets and objects. For a description of these
   903  // abstractions please see https://cloud.google.com/storage/docs (at https://cloud.google.com/storage/docs).
   904  //
   905  // Resources are named as follows:
   906  //
   907  //	Projects are referred to as they are defined by the Resource Manager API,
   908  //	using strings like projects/123456 or projects/my-string-id.
   909  //
   910  //	Buckets are named using string names of the form:
   911  //	projects/{project}/buckets/{bucket}
   912  //	For globally unique buckets, _ may be substituted for the project.
   913  //
   914  //	Objects are uniquely identified by their name along with the name of the
   915  //	bucket they belong to, as separate strings in this API. For example:
   916  //
   917  //	ReadObjectRequest {
   918  //	  bucket: ‘projects/_/buckets/my-bucket’
   919  //	  object: ‘my-object’
   920  //	  }
   921  //	  Note that object names can contain / characters, which are treated as
   922  //	  any other character (no special directory semantics).
   923  func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
   924  	clientOpts := defaultGRPCClientOptions()
   925  	if newClientHook != nil {
   926  		hookOpts, err := newClientHook(ctx, clientHookParams{})
   927  		if err != nil {
   928  			return nil, err
   929  		}
   930  		clientOpts = append(clientOpts, hookOpts...)
   931  	}
   932  
   933  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   934  	if err != nil {
   935  		return nil, err
   936  	}
   937  	client := Client{CallOptions: defaultCallOptions()}
   938  
   939  	c := &gRPCClient{
   940  		connPool:    connPool,
   941  		client:      storagepb.NewStorageClient(connPool),
   942  		CallOptions: &client.CallOptions,
   943  	}
   944  	c.setGoogleClientInfo()
   945  
   946  	client.internalClient = c
   947  
   948  	return &client, nil
   949  }
   950  
   951  // Connection returns a connection to the API service.
   952  //
   953  // Deprecated: Connections are now pooled so this method does not always
   954  // return the same resource.
   955  func (c *gRPCClient) Connection() *grpc.ClientConn {
   956  	return c.connPool.Conn()
   957  }
   958  
   959  // setGoogleClientInfo sets the name and version of the application in
   960  // the `x-goog-api-client` header passed on each request. Intended for
   961  // use by Google-written clients.
   962  func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
   963  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   964  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   965  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   966  }
   967  
   968  // Close closes the connection to the API service. The user should invoke this when
   969  // the client is no longer required.
   970  func (c *gRPCClient) Close() error {
   971  	return c.connPool.Close()
   972  }
   973  
   974  func (c *gRPCClient) DeleteBucket(ctx context.Context, req *storagepb.DeleteBucketRequest, opts ...gax.CallOption) error {
   975  	routingHeaders := ""
   976  	routingHeadersMap := make(map[string]string)
   977  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetName()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetName())[1])) > 0 {
   978  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetName())[1])
   979  	}
   980  	for headerName, headerValue := range routingHeadersMap {
   981  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
   982  	}
   983  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
   984  	hds := []string{"x-goog-request-params", routingHeaders}
   985  
   986  	hds = append(c.xGoogHeaders, hds...)
   987  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   988  	opts = append((*c.CallOptions).DeleteBucket[0:len((*c.CallOptions).DeleteBucket):len((*c.CallOptions).DeleteBucket)], opts...)
   989  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   990  		var err error
   991  		_, err = c.client.DeleteBucket(ctx, req, settings.GRPC...)
   992  		return err
   993  	}, opts...)
   994  	return err
   995  }
   996  
   997  func (c *gRPCClient) GetBucket(ctx context.Context, req *storagepb.GetBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) {
   998  	routingHeaders := ""
   999  	routingHeadersMap := make(map[string]string)
  1000  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetName()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetName())[1])) > 0 {
  1001  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetName())[1])
  1002  	}
  1003  	for headerName, headerValue := range routingHeadersMap {
  1004  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1005  	}
  1006  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1007  	hds := []string{"x-goog-request-params", routingHeaders}
  1008  
  1009  	hds = append(c.xGoogHeaders, hds...)
  1010  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1011  	opts = append((*c.CallOptions).GetBucket[0:len((*c.CallOptions).GetBucket):len((*c.CallOptions).GetBucket)], opts...)
  1012  	var resp *storagepb.Bucket
  1013  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1014  		var err error
  1015  		resp, err = c.client.GetBucket(ctx, req, settings.GRPC...)
  1016  		return err
  1017  	}, opts...)
  1018  	if err != nil {
  1019  		return nil, err
  1020  	}
  1021  	return resp, nil
  1022  }
  1023  
  1024  func (c *gRPCClient) CreateBucket(ctx context.Context, req *storagepb.CreateBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) {
  1025  	routingHeaders := ""
  1026  	routingHeadersMap := make(map[string]string)
  1027  	if reg := regexp.MustCompile("(?P<project>.*)"); reg.MatchString(req.GetParent()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])) > 0 {
  1028  		routingHeadersMap["project"] = url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])
  1029  	}
  1030  	if reg := regexp.MustCompile("(?P<project>.*)"); reg.MatchString(req.GetBucket().GetProject()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetBucket().GetProject())[1])) > 0 {
  1031  		routingHeadersMap["project"] = url.QueryEscape(reg.FindStringSubmatch(req.GetBucket().GetProject())[1])
  1032  	}
  1033  	for headerName, headerValue := range routingHeadersMap {
  1034  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1035  	}
  1036  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1037  	hds := []string{"x-goog-request-params", routingHeaders}
  1038  
  1039  	hds = append(c.xGoogHeaders, hds...)
  1040  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1041  	opts = append((*c.CallOptions).CreateBucket[0:len((*c.CallOptions).CreateBucket):len((*c.CallOptions).CreateBucket)], opts...)
  1042  	var resp *storagepb.Bucket
  1043  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1044  		var err error
  1045  		resp, err = c.client.CreateBucket(ctx, req, settings.GRPC...)
  1046  		return err
  1047  	}, opts...)
  1048  	if err != nil {
  1049  		return nil, err
  1050  	}
  1051  	return resp, nil
  1052  }
  1053  
  1054  func (c *gRPCClient) ListBuckets(ctx context.Context, req *storagepb.ListBucketsRequest, opts ...gax.CallOption) *BucketIterator {
  1055  	routingHeaders := ""
  1056  	routingHeadersMap := make(map[string]string)
  1057  	if reg := regexp.MustCompile("(?P<project>.*)"); reg.MatchString(req.GetParent()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])) > 0 {
  1058  		routingHeadersMap["project"] = url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])
  1059  	}
  1060  	for headerName, headerValue := range routingHeadersMap {
  1061  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1062  	}
  1063  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1064  	hds := []string{"x-goog-request-params", routingHeaders}
  1065  
  1066  	hds = append(c.xGoogHeaders, hds...)
  1067  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1068  	opts = append((*c.CallOptions).ListBuckets[0:len((*c.CallOptions).ListBuckets):len((*c.CallOptions).ListBuckets)], opts...)
  1069  	it := &BucketIterator{}
  1070  	req = proto.Clone(req).(*storagepb.ListBucketsRequest)
  1071  	it.InternalFetch = func(pageSize int, pageToken string) ([]*storagepb.Bucket, string, error) {
  1072  		resp := &storagepb.ListBucketsResponse{}
  1073  		if pageToken != "" {
  1074  			req.PageToken = pageToken
  1075  		}
  1076  		if pageSize > math.MaxInt32 {
  1077  			req.PageSize = math.MaxInt32
  1078  		} else if pageSize != 0 {
  1079  			req.PageSize = int32(pageSize)
  1080  		}
  1081  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1082  			var err error
  1083  			resp, err = c.client.ListBuckets(ctx, req, settings.GRPC...)
  1084  			return err
  1085  		}, opts...)
  1086  		if err != nil {
  1087  			return nil, "", err
  1088  		}
  1089  
  1090  		it.Response = resp
  1091  		return resp.GetBuckets(), resp.GetNextPageToken(), nil
  1092  	}
  1093  	fetch := func(pageSize int, pageToken string) (string, error) {
  1094  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1095  		if err != nil {
  1096  			return "", err
  1097  		}
  1098  		it.items = append(it.items, items...)
  1099  		return nextPageToken, nil
  1100  	}
  1101  
  1102  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1103  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1104  	it.pageInfo.Token = req.GetPageToken()
  1105  
  1106  	return it
  1107  }
  1108  
  1109  func (c *gRPCClient) LockBucketRetentionPolicy(ctx context.Context, req *storagepb.LockBucketRetentionPolicyRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) {
  1110  	routingHeaders := ""
  1111  	routingHeadersMap := make(map[string]string)
  1112  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])) > 0 {
  1113  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])
  1114  	}
  1115  	for headerName, headerValue := range routingHeadersMap {
  1116  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1117  	}
  1118  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1119  	hds := []string{"x-goog-request-params", routingHeaders}
  1120  
  1121  	hds = append(c.xGoogHeaders, hds...)
  1122  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1123  	opts = append((*c.CallOptions).LockBucketRetentionPolicy[0:len((*c.CallOptions).LockBucketRetentionPolicy):len((*c.CallOptions).LockBucketRetentionPolicy)], opts...)
  1124  	var resp *storagepb.Bucket
  1125  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1126  		var err error
  1127  		resp, err = c.client.LockBucketRetentionPolicy(ctx, req, settings.GRPC...)
  1128  		return err
  1129  	}, opts...)
  1130  	if err != nil {
  1131  		return nil, err
  1132  	}
  1133  	return resp, nil
  1134  }
  1135  
  1136  func (c *gRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1137  	routingHeaders := ""
  1138  	routingHeadersMap := make(map[string]string)
  1139  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetResource()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetResource())[1])) > 0 {
  1140  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetResource())[1])
  1141  	}
  1142  	for headerName, headerValue := range routingHeadersMap {
  1143  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1144  	}
  1145  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1146  	hds := []string{"x-goog-request-params", routingHeaders}
  1147  
  1148  	hds = append(c.xGoogHeaders, hds...)
  1149  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1150  	opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
  1151  	var resp *iampb.Policy
  1152  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1153  		var err error
  1154  		resp, err = c.client.GetIamPolicy(ctx, req, settings.GRPC...)
  1155  		return err
  1156  	}, opts...)
  1157  	if err != nil {
  1158  		return nil, err
  1159  	}
  1160  	return resp, nil
  1161  }
  1162  
  1163  func (c *gRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  1164  	routingHeaders := ""
  1165  	routingHeadersMap := make(map[string]string)
  1166  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetResource()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetResource())[1])) > 0 {
  1167  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetResource())[1])
  1168  	}
  1169  	for headerName, headerValue := range routingHeadersMap {
  1170  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1171  	}
  1172  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1173  	hds := []string{"x-goog-request-params", routingHeaders}
  1174  
  1175  	hds = append(c.xGoogHeaders, hds...)
  1176  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1177  	opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
  1178  	var resp *iampb.Policy
  1179  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1180  		var err error
  1181  		resp, err = c.client.SetIamPolicy(ctx, req, settings.GRPC...)
  1182  		return err
  1183  	}, opts...)
  1184  	if err != nil {
  1185  		return nil, err
  1186  	}
  1187  	return resp, nil
  1188  }
  1189  
  1190  func (c *gRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  1191  	routingHeaders := ""
  1192  	routingHeadersMap := make(map[string]string)
  1193  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetResource()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetResource())[1])) > 0 {
  1194  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetResource())[1])
  1195  	}
  1196  	if reg := regexp.MustCompile("(?P<bucket>projects/[^/]+/buckets/[^/]+)/objects(?:/.*)?"); reg.MatchString(req.GetResource()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetResource())[1])) > 0 {
  1197  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetResource())[1])
  1198  	}
  1199  	for headerName, headerValue := range routingHeadersMap {
  1200  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1201  	}
  1202  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1203  	hds := []string{"x-goog-request-params", routingHeaders}
  1204  
  1205  	hds = append(c.xGoogHeaders, hds...)
  1206  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1207  	opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
  1208  	var resp *iampb.TestIamPermissionsResponse
  1209  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1210  		var err error
  1211  		resp, err = c.client.TestIamPermissions(ctx, req, settings.GRPC...)
  1212  		return err
  1213  	}, opts...)
  1214  	if err != nil {
  1215  		return nil, err
  1216  	}
  1217  	return resp, nil
  1218  }
  1219  
  1220  func (c *gRPCClient) UpdateBucket(ctx context.Context, req *storagepb.UpdateBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) {
  1221  	routingHeaders := ""
  1222  	routingHeadersMap := make(map[string]string)
  1223  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetBucket().GetName()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetBucket().GetName())[1])) > 0 {
  1224  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetBucket().GetName())[1])
  1225  	}
  1226  	for headerName, headerValue := range routingHeadersMap {
  1227  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1228  	}
  1229  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1230  	hds := []string{"x-goog-request-params", routingHeaders}
  1231  
  1232  	hds = append(c.xGoogHeaders, hds...)
  1233  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1234  	opts = append((*c.CallOptions).UpdateBucket[0:len((*c.CallOptions).UpdateBucket):len((*c.CallOptions).UpdateBucket)], opts...)
  1235  	var resp *storagepb.Bucket
  1236  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1237  		var err error
  1238  		resp, err = c.client.UpdateBucket(ctx, req, settings.GRPC...)
  1239  		return err
  1240  	}, opts...)
  1241  	if err != nil {
  1242  		return nil, err
  1243  	}
  1244  	return resp, nil
  1245  }
  1246  
  1247  func (c *gRPCClient) DeleteNotificationConfig(ctx context.Context, req *storagepb.DeleteNotificationConfigRequest, opts ...gax.CallOption) error {
  1248  	routingHeaders := ""
  1249  	routingHeadersMap := make(map[string]string)
  1250  	if reg := regexp.MustCompile("(?P<bucket>projects/[^/]+/buckets/[^/]+)(?:/.*)?"); reg.MatchString(req.GetName()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetName())[1])) > 0 {
  1251  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetName())[1])
  1252  	}
  1253  	for headerName, headerValue := range routingHeadersMap {
  1254  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1255  	}
  1256  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1257  	hds := []string{"x-goog-request-params", routingHeaders}
  1258  
  1259  	hds = append(c.xGoogHeaders, hds...)
  1260  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1261  	opts = append((*c.CallOptions).DeleteNotificationConfig[0:len((*c.CallOptions).DeleteNotificationConfig):len((*c.CallOptions).DeleteNotificationConfig)], opts...)
  1262  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1263  		var err error
  1264  		_, err = c.client.DeleteNotificationConfig(ctx, req, settings.GRPC...)
  1265  		return err
  1266  	}, opts...)
  1267  	return err
  1268  }
  1269  
  1270  func (c *gRPCClient) GetNotificationConfig(ctx context.Context, req *storagepb.GetNotificationConfigRequest, opts ...gax.CallOption) (*storagepb.NotificationConfig, error) {
  1271  	routingHeaders := ""
  1272  	routingHeadersMap := make(map[string]string)
  1273  	if reg := regexp.MustCompile("(?P<bucket>projects/[^/]+/buckets/[^/]+)(?:/.*)?"); reg.MatchString(req.GetName()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetName())[1])) > 0 {
  1274  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetName())[1])
  1275  	}
  1276  	for headerName, headerValue := range routingHeadersMap {
  1277  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1278  	}
  1279  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1280  	hds := []string{"x-goog-request-params", routingHeaders}
  1281  
  1282  	hds = append(c.xGoogHeaders, hds...)
  1283  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1284  	opts = append((*c.CallOptions).GetNotificationConfig[0:len((*c.CallOptions).GetNotificationConfig):len((*c.CallOptions).GetNotificationConfig)], opts...)
  1285  	var resp *storagepb.NotificationConfig
  1286  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1287  		var err error
  1288  		resp, err = c.client.GetNotificationConfig(ctx, req, settings.GRPC...)
  1289  		return err
  1290  	}, opts...)
  1291  	if err != nil {
  1292  		return nil, err
  1293  	}
  1294  	return resp, nil
  1295  }
  1296  
  1297  func (c *gRPCClient) CreateNotificationConfig(ctx context.Context, req *storagepb.CreateNotificationConfigRequest, opts ...gax.CallOption) (*storagepb.NotificationConfig, error) {
  1298  	routingHeaders := ""
  1299  	routingHeadersMap := make(map[string]string)
  1300  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetParent()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])) > 0 {
  1301  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])
  1302  	}
  1303  	for headerName, headerValue := range routingHeadersMap {
  1304  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1305  	}
  1306  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1307  	hds := []string{"x-goog-request-params", routingHeaders}
  1308  
  1309  	hds = append(c.xGoogHeaders, hds...)
  1310  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1311  	opts = append((*c.CallOptions).CreateNotificationConfig[0:len((*c.CallOptions).CreateNotificationConfig):len((*c.CallOptions).CreateNotificationConfig)], opts...)
  1312  	var resp *storagepb.NotificationConfig
  1313  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1314  		var err error
  1315  		resp, err = c.client.CreateNotificationConfig(ctx, req, settings.GRPC...)
  1316  		return err
  1317  	}, opts...)
  1318  	if err != nil {
  1319  		return nil, err
  1320  	}
  1321  	return resp, nil
  1322  }
  1323  
  1324  func (c *gRPCClient) ListNotificationConfigs(ctx context.Context, req *storagepb.ListNotificationConfigsRequest, opts ...gax.CallOption) *NotificationConfigIterator {
  1325  	routingHeaders := ""
  1326  	routingHeadersMap := make(map[string]string)
  1327  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetParent()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])) > 0 {
  1328  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])
  1329  	}
  1330  	for headerName, headerValue := range routingHeadersMap {
  1331  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1332  	}
  1333  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1334  	hds := []string{"x-goog-request-params", routingHeaders}
  1335  
  1336  	hds = append(c.xGoogHeaders, hds...)
  1337  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1338  	opts = append((*c.CallOptions).ListNotificationConfigs[0:len((*c.CallOptions).ListNotificationConfigs):len((*c.CallOptions).ListNotificationConfigs)], opts...)
  1339  	it := &NotificationConfigIterator{}
  1340  	req = proto.Clone(req).(*storagepb.ListNotificationConfigsRequest)
  1341  	it.InternalFetch = func(pageSize int, pageToken string) ([]*storagepb.NotificationConfig, string, error) {
  1342  		resp := &storagepb.ListNotificationConfigsResponse{}
  1343  		if pageToken != "" {
  1344  			req.PageToken = pageToken
  1345  		}
  1346  		if pageSize > math.MaxInt32 {
  1347  			req.PageSize = math.MaxInt32
  1348  		} else if pageSize != 0 {
  1349  			req.PageSize = int32(pageSize)
  1350  		}
  1351  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1352  			var err error
  1353  			resp, err = c.client.ListNotificationConfigs(ctx, req, settings.GRPC...)
  1354  			return err
  1355  		}, opts...)
  1356  		if err != nil {
  1357  			return nil, "", err
  1358  		}
  1359  
  1360  		it.Response = resp
  1361  		return resp.GetNotificationConfigs(), resp.GetNextPageToken(), nil
  1362  	}
  1363  	fetch := func(pageSize int, pageToken string) (string, error) {
  1364  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1365  		if err != nil {
  1366  			return "", err
  1367  		}
  1368  		it.items = append(it.items, items...)
  1369  		return nextPageToken, nil
  1370  	}
  1371  
  1372  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1373  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1374  	it.pageInfo.Token = req.GetPageToken()
  1375  
  1376  	return it
  1377  }
  1378  
  1379  func (c *gRPCClient) ComposeObject(ctx context.Context, req *storagepb.ComposeObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) {
  1380  	routingHeaders := ""
  1381  	routingHeadersMap := make(map[string]string)
  1382  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetDestination().GetBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetDestination().GetBucket())[1])) > 0 {
  1383  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetDestination().GetBucket())[1])
  1384  	}
  1385  	for headerName, headerValue := range routingHeadersMap {
  1386  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1387  	}
  1388  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1389  	hds := []string{"x-goog-request-params", routingHeaders}
  1390  
  1391  	hds = append(c.xGoogHeaders, hds...)
  1392  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1393  	opts = append((*c.CallOptions).ComposeObject[0:len((*c.CallOptions).ComposeObject):len((*c.CallOptions).ComposeObject)], opts...)
  1394  	var resp *storagepb.Object
  1395  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1396  		var err error
  1397  		resp, err = c.client.ComposeObject(ctx, req, settings.GRPC...)
  1398  		return err
  1399  	}, opts...)
  1400  	if err != nil {
  1401  		return nil, err
  1402  	}
  1403  	return resp, nil
  1404  }
  1405  
  1406  func (c *gRPCClient) DeleteObject(ctx context.Context, req *storagepb.DeleteObjectRequest, opts ...gax.CallOption) error {
  1407  	routingHeaders := ""
  1408  	routingHeadersMap := make(map[string]string)
  1409  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])) > 0 {
  1410  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])
  1411  	}
  1412  	for headerName, headerValue := range routingHeadersMap {
  1413  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1414  	}
  1415  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1416  	hds := []string{"x-goog-request-params", routingHeaders}
  1417  
  1418  	hds = append(c.xGoogHeaders, hds...)
  1419  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1420  	opts = append((*c.CallOptions).DeleteObject[0:len((*c.CallOptions).DeleteObject):len((*c.CallOptions).DeleteObject)], opts...)
  1421  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1422  		var err error
  1423  		_, err = c.client.DeleteObject(ctx, req, settings.GRPC...)
  1424  		return err
  1425  	}, opts...)
  1426  	return err
  1427  }
  1428  
  1429  func (c *gRPCClient) RestoreObject(ctx context.Context, req *storagepb.RestoreObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) {
  1430  	routingHeaders := ""
  1431  	routingHeadersMap := make(map[string]string)
  1432  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])) > 0 {
  1433  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])
  1434  	}
  1435  	for headerName, headerValue := range routingHeadersMap {
  1436  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1437  	}
  1438  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1439  	hds := []string{"x-goog-request-params", routingHeaders}
  1440  
  1441  	hds = append(c.xGoogHeaders, hds...)
  1442  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1443  	opts = append((*c.CallOptions).RestoreObject[0:len((*c.CallOptions).RestoreObject):len((*c.CallOptions).RestoreObject)], opts...)
  1444  	var resp *storagepb.Object
  1445  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1446  		var err error
  1447  		resp, err = c.client.RestoreObject(ctx, req, settings.GRPC...)
  1448  		return err
  1449  	}, opts...)
  1450  	if err != nil {
  1451  		return nil, err
  1452  	}
  1453  	return resp, nil
  1454  }
  1455  
  1456  func (c *gRPCClient) CancelResumableWrite(ctx context.Context, req *storagepb.CancelResumableWriteRequest, opts ...gax.CallOption) (*storagepb.CancelResumableWriteResponse, error) {
  1457  	routingHeaders := ""
  1458  	routingHeadersMap := make(map[string]string)
  1459  	if reg := regexp.MustCompile("(?P<bucket>projects/[^/]+/buckets/[^/]+)(?:/.*)?"); reg.MatchString(req.GetUploadId()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetUploadId())[1])) > 0 {
  1460  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetUploadId())[1])
  1461  	}
  1462  	for headerName, headerValue := range routingHeadersMap {
  1463  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1464  	}
  1465  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1466  	hds := []string{"x-goog-request-params", routingHeaders}
  1467  
  1468  	hds = append(c.xGoogHeaders, hds...)
  1469  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1470  	opts = append((*c.CallOptions).CancelResumableWrite[0:len((*c.CallOptions).CancelResumableWrite):len((*c.CallOptions).CancelResumableWrite)], opts...)
  1471  	var resp *storagepb.CancelResumableWriteResponse
  1472  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1473  		var err error
  1474  		resp, err = c.client.CancelResumableWrite(ctx, req, settings.GRPC...)
  1475  		return err
  1476  	}, opts...)
  1477  	if err != nil {
  1478  		return nil, err
  1479  	}
  1480  	return resp, nil
  1481  }
  1482  
  1483  func (c *gRPCClient) GetObject(ctx context.Context, req *storagepb.GetObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) {
  1484  	routingHeaders := ""
  1485  	routingHeadersMap := make(map[string]string)
  1486  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])) > 0 {
  1487  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])
  1488  	}
  1489  	for headerName, headerValue := range routingHeadersMap {
  1490  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1491  	}
  1492  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1493  	hds := []string{"x-goog-request-params", routingHeaders}
  1494  
  1495  	hds = append(c.xGoogHeaders, hds...)
  1496  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1497  	opts = append((*c.CallOptions).GetObject[0:len((*c.CallOptions).GetObject):len((*c.CallOptions).GetObject)], opts...)
  1498  	var resp *storagepb.Object
  1499  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1500  		var err error
  1501  		resp, err = c.client.GetObject(ctx, req, settings.GRPC...)
  1502  		return err
  1503  	}, opts...)
  1504  	if err != nil {
  1505  		return nil, err
  1506  	}
  1507  	return resp, nil
  1508  }
  1509  
  1510  func (c *gRPCClient) ReadObject(ctx context.Context, req *storagepb.ReadObjectRequest, opts ...gax.CallOption) (storagepb.Storage_ReadObjectClient, error) {
  1511  	routingHeaders := ""
  1512  	routingHeadersMap := make(map[string]string)
  1513  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])) > 0 {
  1514  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetBucket())[1])
  1515  	}
  1516  	for headerName, headerValue := range routingHeadersMap {
  1517  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1518  	}
  1519  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1520  	hds := []string{"x-goog-request-params", routingHeaders}
  1521  
  1522  	hds = append(c.xGoogHeaders, hds...)
  1523  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1524  	opts = append((*c.CallOptions).ReadObject[0:len((*c.CallOptions).ReadObject):len((*c.CallOptions).ReadObject)], opts...)
  1525  	var resp storagepb.Storage_ReadObjectClient
  1526  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1527  		var err error
  1528  		resp, err = c.client.ReadObject(ctx, req, settings.GRPC...)
  1529  		return err
  1530  	}, opts...)
  1531  	if err != nil {
  1532  		return nil, err
  1533  	}
  1534  	return resp, nil
  1535  }
  1536  
  1537  func (c *gRPCClient) UpdateObject(ctx context.Context, req *storagepb.UpdateObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) {
  1538  	routingHeaders := ""
  1539  	routingHeadersMap := make(map[string]string)
  1540  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetObject().GetBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetObject().GetBucket())[1])) > 0 {
  1541  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetObject().GetBucket())[1])
  1542  	}
  1543  	for headerName, headerValue := range routingHeadersMap {
  1544  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1545  	}
  1546  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1547  	hds := []string{"x-goog-request-params", routingHeaders}
  1548  
  1549  	hds = append(c.xGoogHeaders, hds...)
  1550  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1551  	opts = append((*c.CallOptions).UpdateObject[0:len((*c.CallOptions).UpdateObject):len((*c.CallOptions).UpdateObject)], opts...)
  1552  	var resp *storagepb.Object
  1553  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1554  		var err error
  1555  		resp, err = c.client.UpdateObject(ctx, req, settings.GRPC...)
  1556  		return err
  1557  	}, opts...)
  1558  	if err != nil {
  1559  		return nil, err
  1560  	}
  1561  	return resp, nil
  1562  }
  1563  
  1564  func (c *gRPCClient) WriteObject(ctx context.Context, opts ...gax.CallOption) (storagepb.Storage_WriteObjectClient, error) {
  1565  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
  1566  	var resp storagepb.Storage_WriteObjectClient
  1567  	opts = append((*c.CallOptions).WriteObject[0:len((*c.CallOptions).WriteObject):len((*c.CallOptions).WriteObject)], opts...)
  1568  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1569  		var err error
  1570  		resp, err = c.client.WriteObject(ctx, settings.GRPC...)
  1571  		return err
  1572  	}, opts...)
  1573  	if err != nil {
  1574  		return nil, err
  1575  	}
  1576  	return resp, nil
  1577  }
  1578  
  1579  func (c *gRPCClient) BidiWriteObject(ctx context.Context, opts ...gax.CallOption) (storagepb.Storage_BidiWriteObjectClient, error) {
  1580  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
  1581  	var resp storagepb.Storage_BidiWriteObjectClient
  1582  	opts = append((*c.CallOptions).BidiWriteObject[0:len((*c.CallOptions).BidiWriteObject):len((*c.CallOptions).BidiWriteObject)], opts...)
  1583  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1584  		var err error
  1585  		resp, err = c.client.BidiWriteObject(ctx, settings.GRPC...)
  1586  		return err
  1587  	}, opts...)
  1588  	if err != nil {
  1589  		return nil, err
  1590  	}
  1591  	return resp, nil
  1592  }
  1593  
  1594  func (c *gRPCClient) ListObjects(ctx context.Context, req *storagepb.ListObjectsRequest, opts ...gax.CallOption) *ObjectIterator {
  1595  	routingHeaders := ""
  1596  	routingHeadersMap := make(map[string]string)
  1597  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetParent()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])) > 0 {
  1598  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetParent())[1])
  1599  	}
  1600  	for headerName, headerValue := range routingHeadersMap {
  1601  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1602  	}
  1603  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1604  	hds := []string{"x-goog-request-params", routingHeaders}
  1605  
  1606  	hds = append(c.xGoogHeaders, hds...)
  1607  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1608  	opts = append((*c.CallOptions).ListObjects[0:len((*c.CallOptions).ListObjects):len((*c.CallOptions).ListObjects)], opts...)
  1609  	it := &ObjectIterator{}
  1610  	req = proto.Clone(req).(*storagepb.ListObjectsRequest)
  1611  	it.InternalFetch = func(pageSize int, pageToken string) ([]*storagepb.Object, string, error) {
  1612  		resp := &storagepb.ListObjectsResponse{}
  1613  		if pageToken != "" {
  1614  			req.PageToken = pageToken
  1615  		}
  1616  		if pageSize > math.MaxInt32 {
  1617  			req.PageSize = math.MaxInt32
  1618  		} else if pageSize != 0 {
  1619  			req.PageSize = int32(pageSize)
  1620  		}
  1621  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1622  			var err error
  1623  			resp, err = c.client.ListObjects(ctx, req, settings.GRPC...)
  1624  			return err
  1625  		}, opts...)
  1626  		if err != nil {
  1627  			return nil, "", err
  1628  		}
  1629  
  1630  		it.Response = resp
  1631  		return resp.GetObjects(), resp.GetNextPageToken(), nil
  1632  	}
  1633  	fetch := func(pageSize int, pageToken string) (string, error) {
  1634  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1635  		if err != nil {
  1636  			return "", err
  1637  		}
  1638  		it.items = append(it.items, items...)
  1639  		return nextPageToken, nil
  1640  	}
  1641  
  1642  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1643  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1644  	it.pageInfo.Token = req.GetPageToken()
  1645  
  1646  	return it
  1647  }
  1648  
  1649  func (c *gRPCClient) RewriteObject(ctx context.Context, req *storagepb.RewriteObjectRequest, opts ...gax.CallOption) (*storagepb.RewriteResponse, error) {
  1650  	routingHeaders := ""
  1651  	routingHeadersMap := make(map[string]string)
  1652  	if reg := regexp.MustCompile("(.*)"); reg.MatchString(req.GetSourceBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetSourceBucket())[1])) > 0 {
  1653  		routingHeadersMap["source_bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetSourceBucket())[1])
  1654  	}
  1655  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetDestinationBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetDestinationBucket())[1])) > 0 {
  1656  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetDestinationBucket())[1])
  1657  	}
  1658  	for headerName, headerValue := range routingHeadersMap {
  1659  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1660  	}
  1661  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1662  	hds := []string{"x-goog-request-params", routingHeaders}
  1663  
  1664  	hds = append(c.xGoogHeaders, hds...)
  1665  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1666  	opts = append((*c.CallOptions).RewriteObject[0:len((*c.CallOptions).RewriteObject):len((*c.CallOptions).RewriteObject)], opts...)
  1667  	var resp *storagepb.RewriteResponse
  1668  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1669  		var err error
  1670  		resp, err = c.client.RewriteObject(ctx, req, settings.GRPC...)
  1671  		return err
  1672  	}, opts...)
  1673  	if err != nil {
  1674  		return nil, err
  1675  	}
  1676  	return resp, nil
  1677  }
  1678  
  1679  func (c *gRPCClient) StartResumableWrite(ctx context.Context, req *storagepb.StartResumableWriteRequest, opts ...gax.CallOption) (*storagepb.StartResumableWriteResponse, error) {
  1680  	routingHeaders := ""
  1681  	routingHeadersMap := make(map[string]string)
  1682  	if reg := regexp.MustCompile("(?P<bucket>.*)"); reg.MatchString(req.GetWriteObjectSpec().GetResource().GetBucket()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetWriteObjectSpec().GetResource().GetBucket())[1])) > 0 {
  1683  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetWriteObjectSpec().GetResource().GetBucket())[1])
  1684  	}
  1685  	for headerName, headerValue := range routingHeadersMap {
  1686  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1687  	}
  1688  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1689  	hds := []string{"x-goog-request-params", routingHeaders}
  1690  
  1691  	hds = append(c.xGoogHeaders, hds...)
  1692  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1693  	opts = append((*c.CallOptions).StartResumableWrite[0:len((*c.CallOptions).StartResumableWrite):len((*c.CallOptions).StartResumableWrite)], opts...)
  1694  	var resp *storagepb.StartResumableWriteResponse
  1695  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1696  		var err error
  1697  		resp, err = c.client.StartResumableWrite(ctx, req, settings.GRPC...)
  1698  		return err
  1699  	}, opts...)
  1700  	if err != nil {
  1701  		return nil, err
  1702  	}
  1703  	return resp, nil
  1704  }
  1705  
  1706  func (c *gRPCClient) QueryWriteStatus(ctx context.Context, req *storagepb.QueryWriteStatusRequest, opts ...gax.CallOption) (*storagepb.QueryWriteStatusResponse, error) {
  1707  	routingHeaders := ""
  1708  	routingHeadersMap := make(map[string]string)
  1709  	if reg := regexp.MustCompile("(?P<bucket>projects/[^/]+/buckets/[^/]+)(?:/.*)?"); reg.MatchString(req.GetUploadId()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetUploadId())[1])) > 0 {
  1710  		routingHeadersMap["bucket"] = url.QueryEscape(reg.FindStringSubmatch(req.GetUploadId())[1])
  1711  	}
  1712  	for headerName, headerValue := range routingHeadersMap {
  1713  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1714  	}
  1715  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1716  	hds := []string{"x-goog-request-params", routingHeaders}
  1717  
  1718  	hds = append(c.xGoogHeaders, hds...)
  1719  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1720  	opts = append((*c.CallOptions).QueryWriteStatus[0:len((*c.CallOptions).QueryWriteStatus):len((*c.CallOptions).QueryWriteStatus)], opts...)
  1721  	var resp *storagepb.QueryWriteStatusResponse
  1722  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1723  		var err error
  1724  		resp, err = c.client.QueryWriteStatus(ctx, req, settings.GRPC...)
  1725  		return err
  1726  	}, opts...)
  1727  	if err != nil {
  1728  		return nil, err
  1729  	}
  1730  	return resp, nil
  1731  }
  1732  
  1733  func (c *gRPCClient) GetServiceAccount(ctx context.Context, req *storagepb.GetServiceAccountRequest, opts ...gax.CallOption) (*storagepb.ServiceAccount, error) {
  1734  	routingHeaders := ""
  1735  	routingHeadersMap := make(map[string]string)
  1736  	if reg := regexp.MustCompile("(.*)"); reg.MatchString(req.GetProject()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])) > 0 {
  1737  		routingHeadersMap["project"] = url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])
  1738  	}
  1739  	for headerName, headerValue := range routingHeadersMap {
  1740  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1741  	}
  1742  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1743  	hds := []string{"x-goog-request-params", routingHeaders}
  1744  
  1745  	hds = append(c.xGoogHeaders, hds...)
  1746  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1747  	opts = append((*c.CallOptions).GetServiceAccount[0:len((*c.CallOptions).GetServiceAccount):len((*c.CallOptions).GetServiceAccount)], opts...)
  1748  	var resp *storagepb.ServiceAccount
  1749  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1750  		var err error
  1751  		resp, err = c.client.GetServiceAccount(ctx, req, settings.GRPC...)
  1752  		return err
  1753  	}, opts...)
  1754  	if err != nil {
  1755  		return nil, err
  1756  	}
  1757  	return resp, nil
  1758  }
  1759  
  1760  func (c *gRPCClient) CreateHmacKey(ctx context.Context, req *storagepb.CreateHmacKeyRequest, opts ...gax.CallOption) (*storagepb.CreateHmacKeyResponse, error) {
  1761  	routingHeaders := ""
  1762  	routingHeadersMap := make(map[string]string)
  1763  	if reg := regexp.MustCompile("(.*)"); reg.MatchString(req.GetProject()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])) > 0 {
  1764  		routingHeadersMap["project"] = url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])
  1765  	}
  1766  	for headerName, headerValue := range routingHeadersMap {
  1767  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1768  	}
  1769  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1770  	hds := []string{"x-goog-request-params", routingHeaders}
  1771  
  1772  	hds = append(c.xGoogHeaders, hds...)
  1773  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1774  	opts = append((*c.CallOptions).CreateHmacKey[0:len((*c.CallOptions).CreateHmacKey):len((*c.CallOptions).CreateHmacKey)], opts...)
  1775  	var resp *storagepb.CreateHmacKeyResponse
  1776  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1777  		var err error
  1778  		resp, err = c.client.CreateHmacKey(ctx, req, settings.GRPC...)
  1779  		return err
  1780  	}, opts...)
  1781  	if err != nil {
  1782  		return nil, err
  1783  	}
  1784  	return resp, nil
  1785  }
  1786  
  1787  func (c *gRPCClient) DeleteHmacKey(ctx context.Context, req *storagepb.DeleteHmacKeyRequest, opts ...gax.CallOption) error {
  1788  	routingHeaders := ""
  1789  	routingHeadersMap := make(map[string]string)
  1790  	if reg := regexp.MustCompile("(.*)"); reg.MatchString(req.GetProject()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])) > 0 {
  1791  		routingHeadersMap["project"] = url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])
  1792  	}
  1793  	for headerName, headerValue := range routingHeadersMap {
  1794  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1795  	}
  1796  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1797  	hds := []string{"x-goog-request-params", routingHeaders}
  1798  
  1799  	hds = append(c.xGoogHeaders, hds...)
  1800  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1801  	opts = append((*c.CallOptions).DeleteHmacKey[0:len((*c.CallOptions).DeleteHmacKey):len((*c.CallOptions).DeleteHmacKey)], opts...)
  1802  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1803  		var err error
  1804  		_, err = c.client.DeleteHmacKey(ctx, req, settings.GRPC...)
  1805  		return err
  1806  	}, opts...)
  1807  	return err
  1808  }
  1809  
  1810  func (c *gRPCClient) GetHmacKey(ctx context.Context, req *storagepb.GetHmacKeyRequest, opts ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) {
  1811  	routingHeaders := ""
  1812  	routingHeadersMap := make(map[string]string)
  1813  	if reg := regexp.MustCompile("(.*)"); reg.MatchString(req.GetProject()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])) > 0 {
  1814  		routingHeadersMap["project"] = url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])
  1815  	}
  1816  	for headerName, headerValue := range routingHeadersMap {
  1817  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1818  	}
  1819  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1820  	hds := []string{"x-goog-request-params", routingHeaders}
  1821  
  1822  	hds = append(c.xGoogHeaders, hds...)
  1823  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1824  	opts = append((*c.CallOptions).GetHmacKey[0:len((*c.CallOptions).GetHmacKey):len((*c.CallOptions).GetHmacKey)], opts...)
  1825  	var resp *storagepb.HmacKeyMetadata
  1826  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1827  		var err error
  1828  		resp, err = c.client.GetHmacKey(ctx, req, settings.GRPC...)
  1829  		return err
  1830  	}, opts...)
  1831  	if err != nil {
  1832  		return nil, err
  1833  	}
  1834  	return resp, nil
  1835  }
  1836  
  1837  func (c *gRPCClient) ListHmacKeys(ctx context.Context, req *storagepb.ListHmacKeysRequest, opts ...gax.CallOption) *HmacKeyMetadataIterator {
  1838  	routingHeaders := ""
  1839  	routingHeadersMap := make(map[string]string)
  1840  	if reg := regexp.MustCompile("(.*)"); reg.MatchString(req.GetProject()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])) > 0 {
  1841  		routingHeadersMap["project"] = url.QueryEscape(reg.FindStringSubmatch(req.GetProject())[1])
  1842  	}
  1843  	for headerName, headerValue := range routingHeadersMap {
  1844  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1845  	}
  1846  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1847  	hds := []string{"x-goog-request-params", routingHeaders}
  1848  
  1849  	hds = append(c.xGoogHeaders, hds...)
  1850  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1851  	opts = append((*c.CallOptions).ListHmacKeys[0:len((*c.CallOptions).ListHmacKeys):len((*c.CallOptions).ListHmacKeys)], opts...)
  1852  	it := &HmacKeyMetadataIterator{}
  1853  	req = proto.Clone(req).(*storagepb.ListHmacKeysRequest)
  1854  	it.InternalFetch = func(pageSize int, pageToken string) ([]*storagepb.HmacKeyMetadata, string, error) {
  1855  		resp := &storagepb.ListHmacKeysResponse{}
  1856  		if pageToken != "" {
  1857  			req.PageToken = pageToken
  1858  		}
  1859  		if pageSize > math.MaxInt32 {
  1860  			req.PageSize = math.MaxInt32
  1861  		} else if pageSize != 0 {
  1862  			req.PageSize = int32(pageSize)
  1863  		}
  1864  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1865  			var err error
  1866  			resp, err = c.client.ListHmacKeys(ctx, req, settings.GRPC...)
  1867  			return err
  1868  		}, opts...)
  1869  		if err != nil {
  1870  			return nil, "", err
  1871  		}
  1872  
  1873  		it.Response = resp
  1874  		return resp.GetHmacKeys(), resp.GetNextPageToken(), nil
  1875  	}
  1876  	fetch := func(pageSize int, pageToken string) (string, error) {
  1877  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  1878  		if err != nil {
  1879  			return "", err
  1880  		}
  1881  		it.items = append(it.items, items...)
  1882  		return nextPageToken, nil
  1883  	}
  1884  
  1885  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  1886  	it.pageInfo.MaxSize = int(req.GetPageSize())
  1887  	it.pageInfo.Token = req.GetPageToken()
  1888  
  1889  	return it
  1890  }
  1891  
  1892  func (c *gRPCClient) UpdateHmacKey(ctx context.Context, req *storagepb.UpdateHmacKeyRequest, opts ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) {
  1893  	routingHeaders := ""
  1894  	routingHeadersMap := make(map[string]string)
  1895  	if reg := regexp.MustCompile("(?P<project>.*)"); reg.MatchString(req.GetHmacKey().GetProject()) && len(url.QueryEscape(reg.FindStringSubmatch(req.GetHmacKey().GetProject())[1])) > 0 {
  1896  		routingHeadersMap["project"] = url.QueryEscape(reg.FindStringSubmatch(req.GetHmacKey().GetProject())[1])
  1897  	}
  1898  	for headerName, headerValue := range routingHeadersMap {
  1899  		routingHeaders = fmt.Sprintf("%s%s=%s&", routingHeaders, headerName, headerValue)
  1900  	}
  1901  	routingHeaders = strings.TrimSuffix(routingHeaders, "&")
  1902  	hds := []string{"x-goog-request-params", routingHeaders}
  1903  
  1904  	hds = append(c.xGoogHeaders, hds...)
  1905  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  1906  	opts = append((*c.CallOptions).UpdateHmacKey[0:len((*c.CallOptions).UpdateHmacKey):len((*c.CallOptions).UpdateHmacKey)], opts...)
  1907  	var resp *storagepb.HmacKeyMetadata
  1908  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  1909  		var err error
  1910  		resp, err = c.client.UpdateHmacKey(ctx, req, settings.GRPC...)
  1911  		return err
  1912  	}, opts...)
  1913  	if err != nil {
  1914  		return nil, err
  1915  	}
  1916  	return resp, nil
  1917  }
  1918  

View as plain text