cloud drive: add list buckets

This commit is contained in:
Chris Lu 2021-09-03 20:42:02 -07:00
parent fbfc90fd1e
commit 83cd0fc739
5 changed files with 45 additions and 0 deletions

View file

@ -205,6 +205,7 @@ func (az *azureRemoteStorageClient) UpdateFileMetadata(loc *remote_pb.RemoteStor
return return
} }
func (az *azureRemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocation) (err error) { func (az *azureRemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocation) (err error) {
key := loc.Path[1:] key := loc.Path[1:]
containerURL := az.serviceURL.NewContainerURL(loc.Bucket) containerURL := az.serviceURL.NewContainerURL(loc.Bucket)
@ -214,3 +215,17 @@ func (az *azureRemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocat
} }
return 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
}

View file

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

View file

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

View file

@ -8,6 +8,7 @@ import (
"io" "io"
"strings" "strings"
"sync" "sync"
"time"
) )
func ParseLocationName(remote string) (locationName string) { 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 VisitFunc func(dir string, name string, isDirectory bool, remoteEntry *filer_pb.RemoteEntry) error
type Bucket struct {
Name string
CreatedAt time.Time
}
type RemoteStorageClient interface { type RemoteStorageClient interface {
Traverse(loc *remote_pb.RemoteStorageLocation, visitFn VisitFunc) error Traverse(loc *remote_pb.RemoteStorageLocation, visitFn VisitFunc) error
ReadFile(loc *remote_pb.RemoteStorageLocation, offset int64, size int64) (data []byte, err 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) 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) UpdateFileMetadata(loc *remote_pb.RemoteStorageLocation, oldEntry *filer_pb.Entry, newEntry *filer_pb.Entry) (err error)
DeleteFile(loc *remote_pb.RemoteStorageLocation) (err error) DeleteFile(loc *remote_pb.RemoteStorageLocation) (err error)
ListBuckets() ([]*Bucket, error)
} }
type RemoteStorageClientMaker interface { type RemoteStorageClientMaker interface {

View file

@ -234,3 +234,17 @@ func (s *s3RemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocation)
}) })
return 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
}