Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

b2: Fix listing root buckets with unrestricted API key

DianaNites847734d421d2
diff --git a/backend/b2/b2.go b/backend/b2/b2.go
index a21d63dac..22c5e079a 100644
--- a/backend/b2/b2.go
+++ b/backend/b2/b2.go
@@ -1081,21 +1081,10 @@ type listBucketFn func(*api.Bucket) error
func (f *Fs) listBucketsToFn(ctx context.Context, bucketName string, fn listBucketFn) error {
responses := make([]api.ListBucketsResponse, len(f.info.APIs.Storage.Allowed.Buckets))[:0]
- for i := range f.info.APIs.Storage.Allowed.Buckets {
- b := &f.info.APIs.Storage.Allowed.Buckets[i]
- // Empty names indicate a bucket that no longer exists, this is non-fatal
- // for multi-bucket API keys.
- if b.Name == "" {
- continue
- }
- // When requesting a specific bucket skip over non-matching names
- if bucketName != "" && b.Name != bucketName {
- continue
- }
-
+ call := func(id string) error {
var account = api.ListBucketsRequest{
AccountID: f.info.AccountID,
- BucketID: b.ID,
+ BucketID: id,
}
if bucketName != "" && account.BucketID == "" {
account.BucketName = f.opt.Enc.FromStandardName(bucketName)
@@ -1114,6 +1103,32 @@ func (f *Fs) listBucketsToFn(ctx context.Context, bucketName string, fn listBuck
return err
}
responses = append(responses, response)
+ return nil
+ }
+
+ for i := range f.info.APIs.Storage.Allowed.Buckets {
+ b := &f.info.APIs.Storage.Allowed.Buckets[i]
+ // Empty names indicate a bucket that no longer exists, this is non-fatal
+ // for multi-bucket API keys.
+ if b.Name == "" {
+ continue
+ }
+ // When requesting a specific bucket skip over non-matching names
+ if bucketName != "" && b.Name != bucketName {
+ continue
+ }
+
+ err := call(b.ID)
+ if err != nil {
+ return err
+ }
+ }
+
+ if len(f.info.APIs.Storage.Allowed.Buckets) == 0 {
+ err := call("")
+ if err != nil {
+ return err
+ }
}
f.bucketIDMutex.Lock()