2
0
Эх сурвалжийг харах

add name method for storage (#3308)

Ishaan Mittal 8 сар өмнө
parent
commit
b18e6531de

+ 4 - 0
core/pkg/storage/clusterstorage.go

@@ -164,6 +164,10 @@ func (c *ClusterStorage) check() error {
 	return nil
 }
 
+func (c *ClusterStorage) Name() string {
+	return fmt.Sprintf("%s:%d", c.host, c.port)
+}
+
 func (c *ClusterStorage) StorageType() StorageType {
 	return StorageTypeCluster
 }

+ 4 - 0
core/pkg/storage/filestorage.go

@@ -22,6 +22,10 @@ func NewFileStorage(baseDir string) Storage {
 	return &FileStorage{baseDir}
 }
 
+func (fs *FileStorage) Name() string {
+	return fs.baseDir
+}
+
 // StorageType returns a string identifier for the type of storage used by the implementation.
 func (fs *FileStorage) StorageType() StorageType {
 	return StorageTypeFile

+ 4 - 0
core/pkg/storage/memorystorage.go

@@ -25,6 +25,10 @@ func NewMemoryStorage() *MemoryStorage {
 	}
 }
 
+func (ms *MemoryStorage) Name() string {
+	return "memory"
+}
+
 // StorageType returns a string identifier for the type of storage used by the implementation.
 func (ms *MemoryStorage) StorageType() StorageType {
 	return StorageTypeMemory

+ 4 - 0
core/pkg/storage/prefixedbucketstorage.go

@@ -43,6 +43,10 @@ func withPrefix(prefix, name string) string {
 	return prefix + DirDelim + name
 }
 
+func (pbs *PrefixedBucketStorage) Name() string {
+	return pbs.storage.Name()
+}
+
 func (pbs *PrefixedBucketStorage) StorageType() StorageType {
 	return pbs.storage.StorageType()
 }

+ 7 - 0
core/pkg/storage/storage.go

@@ -24,6 +24,7 @@ type StorageInfo struct {
 
 // Storage provides an API for storing binary data
 type Storage interface {
+	Name() string
 	// StorageType returns a string identifier for the type of storage used by the implementation.
 	StorageType() StorageType
 
@@ -72,6 +73,12 @@ func Validate(storage Storage) error {
 		return errors.Wrap(err, "Failed to check if path exists")
 	}
 
+	// attempt to list a path
+	_, err = storage.List(testPath)
+	if err != nil {
+		return errors.Wrap(err, "Failed to list path")
+	}
+
 	// attempt to write a path
 	err = storage.Write(testPath, []byte(testContent))
 	if err != nil {