From c9745cd47ef828cb475c7cd94b5950744d4afbd6 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 25 Nov 2018 18:51:48 +0100 Subject: [PATCH 1/3] gs: Respect bandwidth limiting In 0dfdc11ed909f3ec8f8c0f0fdcbc342ed4602608, accidentally we dropped using the provided http.RoundTripper, this commits adds it back. Closes #1989 --- internal/backend/gs/gs.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/backend/gs/gs.go b/internal/backend/gs/gs.go index c68efe01d..feea05d07 100644 --- a/internal/backend/gs/gs.go +++ b/internal/backend/gs/gs.go @@ -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" @@ -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 } @@ -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") } From 56af0ce370ab1e67dba56cc96a78b619b85490d8 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 25 Nov 2018 19:07:42 +0100 Subject: [PATCH 2/3] Add entry to changelog --- changelog/unreleased/issue-1989 | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog/unreleased/issue-1989 diff --git a/changelog/unreleased/issue-1989 b/changelog/unreleased/issue-1989 new file mode 100644 index 000000000..34c2543a0 --- /dev/null +++ b/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 From 6f5c3e57f6ff876d7a0da8f4deec47b2dbaf6e55 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 25 Nov 2018 19:22:57 +0100 Subject: [PATCH 3/3] Update vendor/modules.txt --- vendor/modules.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/modules.txt b/vendor/modules.txt index aa1154aa9..c40aecd70 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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