b2: implement --b2-test-mode to set X-Bz-Test-Mode header #420

This commit is contained in:
Nick Craig-Wood 2016-07-01 11:30:09 +01:00
parent ea5878f590
commit 6f3897ce2c
2 changed files with 21 additions and 4 deletions

View File

@ -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()

View File

@ -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).