Skip to content

Commit

Permalink
add endpoint support to s3 storage (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha authored Feb 22, 2021
1 parent f7c2224 commit ea7f7a3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ source:
region: "region"
accessKey: "randomAccessKey"
secretKey: "superSecret"
endpoint: "custom-endpoint.com"
pathPrefix: "/prefixPath/to/folder"

port: 3000
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type S3Bucket struct {
AccessKey string
// Secret key that should be used to access the bucket
SecretKey string
// Endpoint overrides the default generated endpoint for bucket client
Endpoint string
}

// GoogleCloudStorage contains the configuration values for GoogleCloudStorage source
Expand Down Expand Up @@ -73,6 +75,7 @@ func (s *Source) readValue() {
Region: v.GetString("source.bucket.region"),
AccessKey: v.GetString("source.bucket.accessKey"),
SecretKey: v.GetString("source.bucket.secretKey"),
Endpoint: v.GetString("source.bucket.endpoint"),
}
} else if regex.CloudfrontMatcher.MatchString(s.Kind) {
s.Value = Cloudfront{
Expand Down
1 change: 1 addition & 0 deletions pkg/service/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func NewS3Storage(b config.S3Bucket, hc base.HystrixCommand) *s3.Storage {
s3.WithBucketRegion(b.Region),
s3.WithAccessKey(b.AccessKey),
s3.WithSecretKey(b.SecretKey),
s3.WithEndpoint(b.Endpoint),
s3.WithHystrixCommand(hc),
)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/storage/aws/s3/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ func WithSecretKey(secretKey string) Option {
}
}

// WithEndpoint sets the bucket endpoint
func WithEndpoint(endpoint string) Option {
return func(s *Storage) {
s.endpoint = endpoint
}
}

// WithHystrixCommand sets the bucket hystrixCmd
func WithHystrixCommand(hytrixCmd storage.HystrixCommand) Option {
return func(s *Storage) {
Expand Down
10 changes: 7 additions & 3 deletions pkg/storage/aws/s3/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Storage struct {
bucketRegion string
accessKey string
secretKey string
endpoint string
service s3iface.S3API
hystrixCmd storage.HystrixCommand
downloader s3manageriface.DownloaderAPI
Expand Down Expand Up @@ -118,9 +119,12 @@ func NewStorage(opts ...Option) *Storage {
for _, opt := range opts {
opt(&s)
}
cfg := aws.NewConfig().WithRegion(s.bucketRegion).WithCredentials(
credentials.NewStaticCredentials(s.accessKey, s.secretKey, ""),
)
cfg := aws.NewConfig().
WithRegion(s.bucketRegion).
WithEndpoint(s.endpoint).
WithCredentials(
credentials.NewStaticCredentials(s.accessKey, s.secretKey, ""),
)
ssn, _ := session.NewSession(cfg)
s.service = s3.New(ssn)
s.downloader = s3manager.NewDownloaderWithClient(s.service)
Expand Down

0 comments on commit ea7f7a3

Please sign in to comment.