Skip to content

Commit

Permalink
Use resource timeouts for storage object operations. (#5286) (GoogleC…
Browse files Browse the repository at this point in the history
…loudPlatform#795)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Oct 6, 2021
1 parent 20190b3 commit fc61aa8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,30 @@ func (c *Config) NewStorageClient(userAgent string) *storage.Service {
return clientStorage
}

// For object uploads, we need to override the specific timeout because they are long, synchronous operations.
func (c *Config) NewStorageClientWithTimeoutOverride(userAgent string, timeout time.Duration) *storage.Service {
storageClientBasePath := c.StorageBasePath
log.Printf("[INFO] Instantiating Google Storage client for path %s", storageClientBasePath)
// Copy the existing HTTP client (which has no unexported fields [as of Oct 2021 at least], so this is safe).
// We have to do this because otherwise we will accidentally change the timeout for all other
// synchronous operations, which would not be desirable.
httpClient := &http.Client{
Transport: c.client.Transport,
CheckRedirect: c.client.CheckRedirect,
Jar: c.client.Jar,
Timeout: timeout,
}
clientStorage, err := storage.NewService(c.context, option.WithHTTPClient(httpClient))
if err != nil {
log.Printf("[WARN] Error creating client storage: %s", err)
return nil
}
clientStorage.UserAgent = userAgent
clientStorage.BasePath = storageClientBasePath

return clientStorage
}

func (c *Config) NewSqlAdminClient(userAgent string) *sqladmin.Service {
sqlClientBasePath := removeBasePathVersion(removeBasePathVersion(c.SQLBasePath))
log.Printf("[INFO] Instantiating Google SqlAdmin client for path %s", sqlClientBasePath)
Expand Down

0 comments on commit fc61aa8

Please sign in to comment.