Skip to content

Commit

Permalink
connector: customendpoint bool for NewAWSReader
Browse files Browse the repository at this point in the history
Workaround to use min.io or other compatible service as s3 backend
Set customEndpoint = true  to indicate that we are not using
aws services.
  • Loading branch information
talset committed May 6, 2020
1 parent c86b87c commit c6bbcb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
var ctx = context.Background()

// Create a reader
c, err := raws.NewAWSReader(ctx, accessKey, secretKey, region, config)
c, err := raws.NewAWSReader(ctx, accessKey, secretKey, region, config, customEndpoint)
if err != nil {
fmt.Printf("Error while getting NewConnector: %s\n", err.Error())
return
Expand Down
19 changes: 12 additions & 7 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,25 @@ import (
// * https://docs.aws.amazon.com/AWSEC2/latest/APIReference/errors-overview.html#CommonErrors
// * https://docs.aws.amazon.com/STS/latest/APIReference/CommonErrors.html
func NewAWSReader(
ctx context.Context, accessKey string, secretKey string, regions []string, config *aws.Config,
) (AWSReader, error) {
ctx context.Context, accessKey string, secretKey string, regions []string, config *aws.Config, customEndpoint bool) (AWSReader, error) {
var c = connector{}

creds, ec2s, sts, err := configureAWS(accessKey, secretKey)
if err != nil {
return nil, err
}
c.creds = creds
if err := c.setAccountID(ctx, sts); err != nil {
return nil, err
}
if err := c.setRegions(ctx, ec2s, regions); err != nil {
return nil, err

// customEndpoint Set true to indicate that we are not using aws services but custom endpoint like min.io.
if customEndpoint {
c.regions = regions
} else {
if err := c.setAccountID(ctx, sts); err != nil {
return nil, err
}
if err := c.setRegions(ctx, ec2s, regions); err != nil {
return nil, err
}
}
c.setServices(config)
return &c, nil
Expand Down

0 comments on commit c6bbcb1

Please sign in to comment.