File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package request
33import (
44 "context"
55 "errors"
6+ "fmt"
67 "io"
78 "net/url"
89 "strings"
@@ -31,10 +32,20 @@ func NewS3FromUrl(ustr string) (*S3, error) {
3132 if err != nil {
3233 return nil , err
3334 }
35+ bucket := strings .TrimPrefix (u .Host , "s3://" )
36+
37+ // Is bucket in the form <bucket>.s3.<region>.amazonaws.com?
38+ bucketRegion := ""
39+ if a := strings .Split (bucket , "." ); len (a ) == 5 && a [1 ] == "s3" {
40+ bucket = a [0 ]
41+ bucketRegion = a [2 ]
42+ }
3443 s := S3 {
35- Bucket : trimSlash (strings . TrimPrefix ( u . Host , "s3://" ) ),
44+ Bucket : trimSlash (bucket ),
3645 KeyPrefix : trimSlash (u .Path ),
3746 }
47+ s .secret .AWSRegion = bucketRegion
48+ fmt .Printf ("s: %#v\n " , s )
3849 return & s , nil
3950}
4051
Original file line number Diff line number Diff line change @@ -19,3 +19,8 @@ func TestS3(t *testing.T) {
1919 }
2020 testBucket (t , ctx , b )
2121}
22+
23+ func TestAsd (t * testing.T ) {
24+ s , _ := NewS3FromUrl ("s3://asd.s3.us-west-2.amazonaws.com/asd123" )
25+ _ = s
26+ }
You can’t perform that action at this time.
0 commit comments