Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gs: Respect bandwidth limiting #2100

Merged
merged 3 commits into from Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/issue-1989
@@ -0,0 +1,7 @@
Bugfix: Google Cloud Storage: Respect bandwidth limit

The GCS backend did not respect the bandwidth limit configured, a previous
commit accidentally removed support for it.

https://github.com/restic/restic/issues/1989
https://github.com/restic/restic/pull/2100
16 changes: 13 additions & 3 deletions internal/backend/gs/gs.go
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/restic"

"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/googleapi"
storage "google.golang.org/api/storage/v1"
Expand All @@ -40,8 +41,17 @@ type Backend struct {
// Ensure that *Backend implements restic.Backend.
var _ restic.Backend = &Backend{}

func getStorageService() (*storage.Service, error) {
client, err := google.DefaultClient(context.TODO(), storage.DevstorageReadWriteScope)
func getStorageService(rt http.RoundTripper) (*storage.Service, error) {
// create a new HTTP client
httpClient := &http.Client{
Transport: rt,
}

// create a now context with the HTTP client stored at the oauth2.HTTPClient key
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, httpClient)

// use this context
client, err := google.DefaultClient(ctx, storage.DevstorageReadWriteScope)
if err != nil {
return nil, err
}
Expand All @@ -59,7 +69,7 @@ const defaultListMaxItems = 1000
func open(cfg Config, rt http.RoundTripper) (*Backend, error) {
debug.Log("open, config %#v", cfg)

service, err := getStorageService()
service, err := getStorageService(rt)
if err != nil {
return nil, errors.Wrap(err, "getStorageService")
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Expand Up @@ -109,8 +109,8 @@ golang.org/x/net/http/httpguts
golang.org/x/net/http2/hpack
golang.org/x/net/idna
# golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
golang.org/x/oauth2/google
golang.org/x/oauth2
golang.org/x/oauth2/google
golang.org/x/oauth2/internal
golang.org/x/oauth2/jws
golang.org/x/oauth2/jwt
Expand Down