Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an interface for Azure blob storage #35

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
# map to Azurite data objects to the build directory
- ./localdata/reportstream:/localdata
ports:
- "9090:9090" # default api endpoint port
- "9999:9090" # default api endpoint port
platform: linux/amd64
depends_on:
sftp-Azurite:
Expand All @@ -29,9 +29,9 @@ services:
# map to Azurite data objects to the build directory
- ./localdata/azurite:/data
ports:
- "11000:10000"
- "11001:10001"
- "11002:10002"
- "12000:10000"
- "12001:10001"
- "12002:10002"
networks:
- sftp

Expand Down
10 changes: 5 additions & 5 deletions src/azure/blob.go → src/azure/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import (
"io"
)

type BlobHandler struct {
type StorageHandler struct {
blobClient *azblob.Client
}

func NewBlobHandler(conn string) (BlobHandler, error) {
func NewBlobHandler(conn string) (StorageHandler, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be NewStorageHandler.

blobClient, err := azblob.NewClientFromConnectionString(conn, nil)
if err != nil {
return BlobHandler{}, err
return StorageHandler{}, err
}

return BlobHandler{blobClient: blobClient}, nil
return StorageHandler{blobClient: blobClient}, nil
}

// TODO - container should eventually be managed by Terraform

func (receiver BlobHandler) FetchFile(blobPath string) ([]byte, error) {
func (receiver StorageHandler) FetchFile(blobPath string) ([]byte, error) {
// TODO - read containerName from env vars
containerName := "sftp"

Expand Down
14 changes: 14 additions & 0 deletions src/cmd/blob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

// The BlobHandler interface is about interacting with file data,
// e.g. in Azure Blob Storage or a local filesystem
type BlobHandler interface {
FetchFile(blobPath string) ([]byte, error)
}

/**
Future things to implement:
put file
move file
delete file
*/
4 changes: 0 additions & 4 deletions src/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func setupLogging() {
}
}

type BlobHandler interface {
FetchFile(blobPath string) ([]byte, error)
}

func readAzureFile(blobHandler BlobHandler, filePath string) ([]byte, error) {
content, err := blobHandler.FetchFile(filePath)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/sender.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package main

// The MessageSender interface is about delivering data to external services.
// Currently, we send messages to ReportStream or to a mock service for testing.
type MessageSender interface {
SendMessage(message []byte) (string, error)
}
Loading