diff --git a/weed/remote_storage/azure/azure_storage_client.go b/weed/remote_storage/azure/azure_storage_client.go index 3982750f3..bf10b9770 100644 --- a/weed/remote_storage/azure/azure_storage_client.go +++ b/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 +} diff --git a/weed/remote_storage/gcs/gcs_storage_client.go b/weed/remote_storage/gcs/gcs_storage_client.go index 997bf2c20..79f56f28a 100644 --- a/weed/remote_storage/gcs/gcs_storage_client.go +++ b/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 +} diff --git a/weed/remote_storage/hdfs/hdfs_storage_client.go b/weed/remote_storage/hdfs/hdfs_storage_client.go index 5b4ce0b29..1e96dec9b 100644 --- a/weed/remote_storage/hdfs/hdfs_storage_client.go +++ b/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 +} diff --git a/weed/remote_storage/remote_storage.go b/weed/remote_storage/remote_storage.go index 3f76452cc..de325a61e 100644 --- a/weed/remote_storage/remote_storage.go +++ b/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 { diff --git a/weed/remote_storage/s3/s3_storage_client.go b/weed/remote_storage/s3/s3_storage_client.go index ec1c6d7bd..ec28defb3 100644 --- a/weed/remote_storage/s3/s3_storage_client.go +++ b/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 +}