Browse Source

cloud drive: add list buckets

pull/2321/head
Chris Lu 3 years ago
parent
commit
83cd0fc739
  1. 15
      weed/remote_storage/azure/azure_storage_client.go
  2. 4
      weed/remote_storage/gcs/gcs_storage_client.go
  3. 5
      weed/remote_storage/hdfs/hdfs_storage_client.go
  4. 7
      weed/remote_storage/remote_storage.go
  5. 14
      weed/remote_storage/s3/s3_storage_client.go

15
weed/remote_storage/azure/azure_storage_client.go

@ -205,6 +205,7 @@ func (az *azureRemoteStorageClient) UpdateFileMetadata(loc *remote_pb.RemoteStor
return
}
func (az *azureRemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocation) (err error) {
key := loc.Path[1:]
containerURL := az.serviceURL.NewContainerURL(loc.Bucket)
@ -214,3 +215,17 @@ func (az *azureRemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocat
}
return
}
func (az *azureRemoteStorageClient) ListBuckets() (buckets []*remote_storage.Bucket, err error) {
resp, err := az.ListBuckets()
if err != nil {
return nil, fmt.Errorf("list buckets: %v", err)
}
for _, b := range resp {
buckets = append(buckets, &remote_storage.Bucket{
Name: b.Name,
CreatedAt: b.CreatedAt,
})
}
return
}

4
weed/remote_storage/gcs/gcs_storage_client.go

@ -184,3 +184,7 @@ func (gcs *gcsRemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocati
}
return
}
func (gcs *gcsRemoteStorageClient) ListBuckets() (buckets []*remote_storage.Bucket, err error) {
return
}

5
weed/remote_storage/hdfs/hdfs_storage_client.go

@ -170,9 +170,14 @@ func (c *hdfsRemoteStorageClient) UpdateFileMetadata(loc *remote_pb.RemoteStorag
}
return nil
}
func (c *hdfsRemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocation) (err error) {
if err = c.client.Remove(loc.Path); err != nil {
return fmt.Errorf("hdfs delete %s: %v", loc.Path, err)
}
return
}
func (c *hdfsRemoteStorageClient) ListBuckets() (buckets []*remote_storage.Bucket, err error) {
return
}

7
weed/remote_storage/remote_storage.go

@ -8,6 +8,7 @@ import (
"io"
"strings"
"sync"
"time"
)
func ParseLocationName(remote string) (locationName string) {
@ -65,6 +66,11 @@ func FormatLocation(loc *remote_pb.RemoteStorageLocation) string {
type VisitFunc func(dir string, name string, isDirectory bool, remoteEntry *filer_pb.RemoteEntry) error
type Bucket struct {
Name string
CreatedAt time.Time
}
type RemoteStorageClient interface {
Traverse(loc *remote_pb.RemoteStorageLocation, visitFn VisitFunc) error
ReadFile(loc *remote_pb.RemoteStorageLocation, offset int64, size int64) (data []byte, err error)
@ -73,6 +79,7 @@ type RemoteStorageClient interface {
WriteFile(loc *remote_pb.RemoteStorageLocation, entry *filer_pb.Entry, reader io.Reader) (remoteEntry *filer_pb.RemoteEntry, err error)
UpdateFileMetadata(loc *remote_pb.RemoteStorageLocation, oldEntry *filer_pb.Entry, newEntry *filer_pb.Entry) (err error)
DeleteFile(loc *remote_pb.RemoteStorageLocation) (err error)
ListBuckets() ([]*Bucket, error)
}
type RemoteStorageClientMaker interface {

14
weed/remote_storage/s3/s3_storage_client.go

@ -234,3 +234,17 @@ func (s *s3RemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocation)
})
return
}
func (s *s3RemoteStorageClient) ListBuckets() (buckets []*remote_storage.Bucket, err error) {
resp, err := s.conn.ListBuckets(&s3.ListBucketsInput{})
if err != nil {
return nil, fmt.Errorf("list buckets: %v", err)
}
for _, b := range resp.Buckets {
buckets = append(buckets, &remote_storage.Bucket{
Name: *b.Name,
CreatedAt: *b.CreationDate,
})
}
return
}
Loading…
Cancel
Save