mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
b2: Fix listing root buckets with unrestricted API key
Fixes previous pull request #8978 An oversight meant that unrestricted API keys never called b2_list_buckets, meaning the root remote could not be listed. The call is now made in the event there are no allowed buckets, indicating an unrestricted API key Fixes #9007
This commit is contained in:
committed by
Nick Craig-Wood
parent
f7b255d4ec
commit
847734d421
@@ -1081,21 +1081,10 @@ type listBucketFn func(*api.Bucket) error
|
|||||||
func (f *Fs) listBucketsToFn(ctx context.Context, bucketName string, fn listBucketFn) 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]
|
responses := make([]api.ListBucketsResponse, len(f.info.APIs.Storage.Allowed.Buckets))[:0]
|
||||||
|
|
||||||
for i := range f.info.APIs.Storage.Allowed.Buckets {
|
call := func(id string) error {
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
var account = api.ListBucketsRequest{
|
var account = api.ListBucketsRequest{
|
||||||
AccountID: f.info.AccountID,
|
AccountID: f.info.AccountID,
|
||||||
BucketID: b.ID,
|
BucketID: id,
|
||||||
}
|
}
|
||||||
if bucketName != "" && account.BucketID == "" {
|
if bucketName != "" && account.BucketID == "" {
|
||||||
account.BucketName = f.opt.Enc.FromStandardName(bucketName)
|
account.BucketName = f.opt.Enc.FromStandardName(bucketName)
|
||||||
@@ -1114,6 +1103,32 @@ func (f *Fs) listBucketsToFn(ctx context.Context, bucketName string, fn listBuck
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
responses = append(responses, response)
|
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()
|
f.bucketIDMutex.Lock()
|
||||||
|
|||||||
Reference in New Issue
Block a user