@@ -295,7 +295,14 @@ type Options struct {
295295 // If your implementation of 'SignBytes' needs a request context, set this instead.
296296 MakeSignBytes func (requestCtx context.Context ) SignBytesFunc
297297
298+ // Client provides a *storage.Client to use, instead of constructing one based on
299+ // the HTTPClient. When set, you must pass nil as the gcp.HTTPClient to OpenBucket.
300+ //
301+ // For example, this can be used to create a Bucket backed by a gRPC client.
302+ Client * storage.Client
303+
298304 // ClientOptions are passed when constructing the storage.Client.
305+ // Ignored if Client is set.
299306 ClientOptions []option.ClientOption
300307}
301308
@@ -312,12 +319,21 @@ type SignBytesFunc func([]byte) ([]byte, error)
312319
313320// openBucket returns a GCS Bucket that communicates using the given HTTP client.
314321func openBucket (ctx context.Context , client * gcp.HTTPClient , bucketName string , opts * Options ) (* bucket , error ) {
315- if client == nil {
316- return nil , errors . New ( "gcsblob.OpenBucket: client is required" )
322+ if opts == nil {
323+ opts = & Options {}
317324 }
318325 if bucketName == "" {
319326 return nil , errors .New ("gcsblob.OpenBucket: bucketName is required" )
320327 }
328+ if opts .Client != nil {
329+ if client != nil {
330+ return nil , errors .New ("gcsblob.OpenBucket: client must be nil when providing Options.Client" )
331+ }
332+ return & bucket {name : bucketName , client : opts .Client , opts : opts }, nil
333+ }
334+ if client == nil {
335+ return nil , errors .New ("gcsblob.OpenBucket: client is required" )
336+ }
321337
322338 // We wrap the provided http.Client to add a Go CDK User-Agent.
323339 clientOpts := []option.ClientOption {option .WithHTTPClient (useragent .HTTPClient (& client .Client , "blob" ))}
@@ -328,9 +344,6 @@ func openBucket(ctx context.Context, client *gcp.HTTPClient, bucketName string,
328344 option .WithHTTPClient (http .DefaultClient ),
329345 }
330346 }
331- if opts == nil {
332- opts = & Options {}
333- }
334347 clientOpts = append (clientOpts , opts .ClientOptions ... )
335348 c , err := storage .NewClient (ctx , clientOpts ... )
336349 if err != nil {
0 commit comments