-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from UNIwise/feature/MP2381/MP-2385-S3-storage
Feature/mp2381/mp 2385 s3 storage
- Loading branch information
Showing
11 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ SERVER_PORT=9000 | |
|
||
LOG_LEVEL: debug | ||
LOG_FORMAT: text | ||
|
||
AWS_REGION=eu-west-1 | ||
AWS_BUCKET_NAME=my-bucket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:generate mockgen --source=repository.go -destination=repository_mock.go -package=storage | ||
package storage | ||
|
||
type Storage interface { | ||
// TODO: Add methods to implement | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package storage | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type S3StorageConfig struct { | ||
Region string `mapstructure:"region" validate:"required"` | ||
Bucket string `mapstructure:"bucket" validate:"required"` | ||
} | ||
|
||
type S3ClientImpl struct { | ||
config S3StorageConfig | ||
client *s3.Client | ||
} | ||
|
||
func NewS3Client(ctx context.Context, conf S3StorageConfig) (*S3ClientImpl, error) { | ||
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(conf.Region)) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to load configuration") | ||
} | ||
|
||
client := s3.NewFromConfig(cfg) | ||
|
||
return &S3ClientImpl{ | ||
config: conf, | ||
client: client, | ||
}, nil | ||
} | ||
|
||
//TODO: Add methods to implement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package storage | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewS3Client(t *testing.T) { | ||
t.Parallel() | ||
|
||
client, err := NewS3Client(context.Background(), S3StorageConfig{}) | ||
|
||
assert.NoError(t, err) | ||
assert.NotNil(t, client.client) | ||
assert.NotNil(t, client.config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package storage | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
) | ||
|
||
type ServiceImpl struct { | ||
storage Storage | ||
} | ||
|
||
type Service interface { | ||
ListObjectsV2(ctx context.Context) (*s3.ListObjectsV2Output, error) | ||
} | ||
|
||
func NewService(ctx context.Context, storage Storage) *ServiceImpl { | ||
return &ServiceImpl{ | ||
storage: storage, | ||
} | ||
} | ||
|
||
// TODO: Add methods to implement |