Skip to content

Commit

Permalink
feat(storage): add StorageClientInterface (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsalles authored Nov 12, 2021
1 parent d19a7a7 commit 09ca79c
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions pkg/common/clients/storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ type StorageClient struct {
configuration StorageClientConfiguration
}

// StorageClientInterface defines storage client interface
type StorageClientInterface interface {
CreateDirectory(relativePath string) error
RemoveDirectory(relativePath string) error
CheckIfExists(relativePath string) bool
}

// NewStorageClient returns an initialized struct with the required dependencies injected
func NewStorageClient(logger *logrus.Logger, configuration StorageClientConfiguration) StorageClient {
return StorageClient{
Expand All @@ -21,9 +28,9 @@ func NewStorageClient(logger *logrus.Logger, configuration StorageClientConfigur
}
}

// CreateWorkspace attempts to create a directory to hold requirements.txt
func (sc StorageClient) CreateWorkspace(obj, relativePath string) error {
fullPath := fmt.Sprintf("%s/%s/%s", sc.configuration.BasePath, obj, relativePath)
// CreateDirectory attempts to create a directory to hold requirements.txt
func (sc *StorageClient) CreateDirectory(relativePath string) error {
fullPath := fmt.Sprintf("%s/%s", sc.configuration.BasePath, relativePath)

sc.logger.Info("Attempting to create directory ", fullPath)

Expand All @@ -34,9 +41,16 @@ func (sc StorageClient) CreateWorkspace(obj, relativePath string) error {
return nil
}

// RemoveDirectory attempts to remove the directory that holds requirements.txt
func (sc *StorageClient) RemoveDirectory(relativePath string) error {
fullPath := fmt.Sprintf("%s/%s", sc.configuration.BasePath, relativePath)
sc.logger.Info("Attempting to remove ", fullPath)
return os.RemoveAll(fullPath)
}

// CheckIfExists attempts to check if the directory exists
func (sc *StorageClient) CheckIfExists(obj, relativePath string) bool {
fullPath := fmt.Sprintf("%s/%s/%s", sc.configuration.BasePath, obj, relativePath)
func (sc *StorageClient) CheckIfExists(relativePath string) bool {
fullPath := fmt.Sprintf("%s/%s", sc.configuration.BasePath, relativePath)

_, err := os.Stat(fullPath)
if err != nil && os.IsNotExist(err) {
Expand All @@ -45,10 +59,3 @@ func (sc *StorageClient) CheckIfExists(obj, relativePath string) bool {

return true
}

// RemoveDirectory attempts to remove the directory that holds requirements.txt
func (sc StorageClient) RemoveDirectory(obj, relativePath string) error {
fullPath := fmt.Sprintf("%s/%s/%s", sc.configuration.BasePath, obj, relativePath)
sc.logger.Info("Attempting to remove ", fullPath)
return os.RemoveAll(fullPath)
}

0 comments on commit 09ca79c

Please sign in to comment.