From 6f3897ce2cbd22f41f5dd4f3ba9db71ac58fcede Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 1 Jul 2016 11:30:09 +0100 Subject: [PATCH] b2: implement --b2-test-mode to set `X-Bz-Test-Mode` header #420 --- b2/b2.go | 8 ++++++++ docs/content/b2.md | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/b2/b2.go b/b2/b2.go index 801aa2492..b4457c42c 100644 --- a/b2/b2.go +++ b/b2/b2.go @@ -39,6 +39,7 @@ const ( maxSleep = 2 * time.Second decayConstant = 2 // bigger for slower decay, exponential maxParts = 10000 + testModeHeader = "X-Bz-Test-Mode" ) // Globals @@ -49,6 +50,7 @@ var ( errorAuthTokenExpired = errors.New("b2 auth token expired") errorUploadTokenExpired = errors.New("b2 upload token expired") errorUploadPartTokenExpired = errors.New("b2 upload part token expired") + b2TestMode = pflag.StringP("b2-test-mode", "", "", "A flag string for X-Bz-Test-Mode header.") ) // Register with Fs @@ -224,6 +226,12 @@ func NewFs(name, root string) (fs.Fs, error) { pacer: pacer.New().SetMinSleep(minSleep).SetMaxSleep(maxSleep).SetDecayConstant(decayConstant), uploadTokens: make(chan struct{}, fs.Config.Transfers), } + // Set the test flag if required + if *b2TestMode != "" { + testMode := strings.TrimSpace(*b2TestMode) + f.srv.SetHeader(testModeHeader, testMode) + fs.Debug(f, "Setting test header \"%s: %s\"", testModeHeader, testMode) + } // Fill up the upload tokens for i := 0; i < fs.Config.Transfers; i++ { f.returnUploadToken() diff --git a/docs/content/b2.md b/docs/content/b2.md index 870712f1b..e08ac4898 100644 --- a/docs/content/b2.md +++ b/docs/content/b2.md @@ -151,8 +151,17 @@ Cutoff for switching to chunked upload (default 4.657GiB == `--b2-chunk-size`. The default value is the largest file which can be uploaded without chunks. -### API ### +#### --b2-test-mode=FLAG #### -Here are [some notes I made on the backblaze -API](https://gist.github.com/ncw/166dabf352b399f1cc1c) while -integrating it with rclone. +This is for debugging purposes only. + +Setting FLAG to one of the strings below will cause b2 to return +specific errors for debugging purposes. + + * `fail_some_uploads` + * `expire_some_account_authorization_tokens` + * `force_cap_exceeded` + +These will be set in the `X-Bz-Test-Mode` header which is documented +in the [b2 integrations +checklist](https://www.backblaze.com/b2/docs/integration_checklist.html).