Skip to content

Commit

Permalink
blob/gcsblob: Allow providing options for storage.NewClient
Browse files Browse the repository at this point in the history
  • Loading branch information
vangent committed Oct 5, 2024
1 parent e5b1bc6 commit aaf03ae
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions blob/gcsblob/gcsblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ type Options struct {
// MakeSignBytes is a factory for functions that are being used in place of an empty SignBytes.
// If your implementation of 'SignBytes' needs a request context, set this instead.
MakeSignBytes func(requestCtx context.Context) SignBytesFunc

// ClientOptions are passed when constructing the storage.Client.
ClientOptions []option.ClientOption
}

// clear clears all the fields of o.
Expand All @@ -306,6 +309,7 @@ func openBucket(ctx context.Context, client *gcp.HTTPClient, bucketName string,
return nil, errors.New("gcsblob.OpenBucket: bucketName is required")
}

// We wrap the provided http.Client to add a Go CDK User-Agent.
clientOpts := []option.ClientOption{option.WithHTTPClient(useragent.HTTPClient(&client.Client, "blob"))}
if host := os.Getenv("STORAGE_EMULATOR_HOST"); host != "" {
clientOpts = []option.ClientOption{
Expand All @@ -314,15 +318,14 @@ func openBucket(ctx context.Context, client *gcp.HTTPClient, bucketName string,
option.WithHTTPClient(http.DefaultClient),
}
}

// We wrap the provided http.Client to add a Go CDK User-Agent.
if opts == nil {
opts = &Options{}
}
clientOpts = append(clientOpts, opts.ClientOptions...)
c, err := storage.NewClient(ctx, clientOpts...)
if err != nil {
return nil, err
}
if opts == nil {
opts = &Options{}
}
return &bucket{name: bucketName, client: c, opts: opts}, nil
}

Expand Down

0 comments on commit aaf03ae

Please sign in to comment.