Skip to content

Commit

Permalink
unspecified endpoint will go to aws
Browse files Browse the repository at this point in the history
  • Loading branch information
benmcclelland committed Dec 14, 2021
1 parent b391b92 commit bee8a52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {
flag.StringVar(&awsID, "access", "", "access key, or specify in AWS_ACCESS_KEY_ID env")
flag.StringVar(&awsSecret, "secret", "", "secret key, or specify in AWS_SECRET_ACCESS_KEY env")
flag.StringVar(&awsRegion, "region", "us-east-1", "bucket region")
flag.StringVar(&endpoint, "endpoint", "", "s3 server endpoint")
flag.StringVar(&endpoint, "endpoint", "", "s3 server endpoint, default aws")
flag.StringVar(&bucket, "bucket", "", "s3 bucket")
flag.StringVar(&prefix, "prefix", "", "object name prefix")
flag.BoolVar(&checksumDisable, "disablechecksum", false, "disable server checksums")
Expand Down
34 changes: 15 additions & 19 deletions s3io/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,24 @@ func (c *S3Conf) config() aws.Config {
}
client := &http.Client{Transport: tr}

if c.checksumDisable {
cfg, err := config.LoadDefaultConfig(
context.TODO(),
config.WithRegion(c.awsRegion),
config.WithCredentialsProvider(creds),
config.WithEndpointResolver(c),
config.WithHTTPClient(client),
config.WithAPIOptions([]func(*middleware.Stack) error{v4.SwapComputePayloadSHA256ForUnsignedPayloadMiddleware}),
)
if err != nil {
log.Fatalln("error:", err)
}

return cfg
}
cfg, err := config.LoadDefaultConfig(
context.TODO(),
opts := []func(*config.LoadOptions) error{
config.WithRegion(c.awsRegion),
config.WithCredentialsProvider(creds),
config.WithEndpointResolver(c),
config.WithHTTPClient(client),
)
}

if c.endpoint != "" && c.endpoint != "aws" {
opts = append(opts,
config.WithEndpointResolver(c))
}

if c.checksumDisable {
opts = append(opts,
config.WithAPIOptions([]func(*middleware.Stack) error{v4.SwapComputePayloadSHA256ForUnsignedPayloadMiddleware}))
}

cfg, err := config.LoadDefaultConfig(
context.TODO(), opts...)
if err != nil {
log.Fatalln("error:", err)
}
Expand Down

0 comments on commit bee8a52

Please sign in to comment.