b2: implement --b2-test-mode to set X-Bz-Test-Mode
header #420
This commit is contained in:
parent
ea5878f590
commit
6f3897ce2c
2 changed files with 21 additions and 4 deletions
8
b2/b2.go
8
b2/b2.go
|
@ -39,6 +39,7 @@ const (
|
||||||
maxSleep = 2 * time.Second
|
maxSleep = 2 * time.Second
|
||||||
decayConstant = 2 // bigger for slower decay, exponential
|
decayConstant = 2 // bigger for slower decay, exponential
|
||||||
maxParts = 10000
|
maxParts = 10000
|
||||||
|
testModeHeader = "X-Bz-Test-Mode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
|
@ -49,6 +50,7 @@ var (
|
||||||
errorAuthTokenExpired = errors.New("b2 auth token expired")
|
errorAuthTokenExpired = errors.New("b2 auth token expired")
|
||||||
errorUploadTokenExpired = errors.New("b2 upload token expired")
|
errorUploadTokenExpired = errors.New("b2 upload token expired")
|
||||||
errorUploadPartTokenExpired = errors.New("b2 upload part 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
|
// Register with Fs
|
||||||
|
@ -224,6 +226,12 @@ func NewFs(name, root string) (fs.Fs, error) {
|
||||||
pacer: pacer.New().SetMinSleep(minSleep).SetMaxSleep(maxSleep).SetDecayConstant(decayConstant),
|
pacer: pacer.New().SetMinSleep(minSleep).SetMaxSleep(maxSleep).SetDecayConstant(decayConstant),
|
||||||
uploadTokens: make(chan struct{}, fs.Config.Transfers),
|
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
|
// Fill up the upload tokens
|
||||||
for i := 0; i < fs.Config.Transfers; i++ {
|
for i := 0; i < fs.Config.Transfers; i++ {
|
||||||
f.returnUploadToken()
|
f.returnUploadToken()
|
||||||
|
|
|
@ -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
|
`--b2-chunk-size`. The default value is the largest file which can be
|
||||||
uploaded without chunks.
|
uploaded without chunks.
|
||||||
|
|
||||||
### API ###
|
#### --b2-test-mode=FLAG ####
|
||||||
|
|
||||||
Here are [some notes I made on the backblaze
|
This is for debugging purposes only.
|
||||||
API](https://gist.github.com/ncw/166dabf352b399f1cc1c) while
|
|
||||||
integrating it with rclone.
|
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).
|
||||||
|
|
Loading…
Add table
Reference in a new issue