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 11, 2020
1 parent c86b87c commit aa4898a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ func main() {
var secretKey string = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
var region []string = []string{"eu-*"}
var ctx = context.Background()
// customEndpoint, set true to indicate that we are not using aws services but custom endpoint like min.io.
// It will skip running function like ec2.DescribeRegions or sts.GetCallerIdentityWithContext.
var customEndpoint bool = false

// 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
22 changes: 15 additions & 7 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,35 @@ import (
// The connections are not all established while instancing, but the various sessions are, this way connections are only
// made for services that are called, otherwise only the sessions remain.
//
// By setting customEndpoint to true indicate we are not using aws services but custom endpoint like min.io.
// Function getting datas from aws like ec2.DescribeRegionsWithContext will be skipped.
//
// An error is returned if any of the needed AWS request for creating the reader returns an AWS error, in such case it
// will have any of the common error codes (see below) or EmptyStaticCreds code or a go standard error in case that no
// regions are matched with the ones available, at the time, in AWS.
// See:
// * 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

// if customEndpoint true do not use aws services.
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 aa4898a

Please sign in to comment.