Skip to content

Commit

Permalink
Merge pull request #284 from joeyh/master
Browse files Browse the repository at this point in the history
support custom S3 regions
  • Loading branch information
principlesoftware-dev committed Feb 6, 2023
2 parents ee45747 + 13ae451 commit bff2bf6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 8 additions & 2 deletions Aws/S3/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ data S3Configuration qt
= S3Configuration
{ s3Protocol :: Protocol
, s3Endpoint :: B.ByteString
, s3Region :: Maybe B.ByteString
, s3RequestStyle :: RequestStyle
, s3Port :: Int
, s3ServerSideEncryption :: Maybe ServerSideEncryption
Expand Down Expand Up @@ -117,6 +118,7 @@ s3 protocol endpoint uri
= S3Configuration
{ s3Protocol = protocol
, s3Endpoint = endpoint
, s3Region = Nothing
, s3RequestStyle = BucketStyle
, s3Port = defaultPort protocol
, s3ServerSideEncryption = Nothing
Expand All @@ -130,6 +132,7 @@ s3v4 protocol endpoint uri payload
= S3Configuration
{ s3Protocol = protocol
, s3Endpoint = endpoint
, s3Region = Nothing
, s3RequestStyle = BucketStyle
, s3Port = defaultPort protocol
, s3ServerSideEncryption = Nothing
Expand Down Expand Up @@ -373,7 +376,7 @@ s3SignQuery sq@S3Query{..} sc@S3Configuration{ s3SignVersion = S3SignV4 signpayl
)
where
allQueries = s3QSubresources ++ s3QQuery
region = s3ExtractRegion s3Endpoint
region = fromMaybe (s3ExtractRegion s3Endpoint) s3Region
auth = authorizationV4 sd HmacSHA256 region "s3" signedHeaders stringToSign
sig = signatureV4 sd HmacSHA256 region "s3" stringToSign
cred = credentialV4 sd region "s3"
Expand Down Expand Up @@ -410,7 +413,10 @@ s3RenderQuery qm = mconcat . qmf . intersperse (B8.singleton '&') . map renderIt
renderItem (k, Just v) = s3UriEncode True k Sem.<> "=" Sem.<> s3UriEncode True v
renderItem (k, Nothing) = s3UriEncode True k Sem.<> "="

-- | see: <http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region>
-- | Extract a S3 region from the S3 endpoint. AWS encodes the region names
-- in the hostnames of endpoints in a way that makes this possible,
-- see: <http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region>
-- For other S3 implementations, may instead need to specify s3Region.
s3ExtractRegion :: B.ByteString -> B.ByteString
s3ExtractRegion "s3.amazonaws.com" = "us-east-1"
s3ExtractRegion "s3-external-1.amazonaws.com" = "us-east-1"
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
0.24 series
-----------

NOTES: 0.24 brings technically breaking changes, which should not affect
most users. I recommend using smart constructors and {} matching syntax
whenever possible when interacting with aws types.

- 0.24
- Added s3Region constructor to S3Configuration, to support custom
S3 regions.

0.23 series
-----------

Expand All @@ -6,7 +17,7 @@ most users. I recommend using smart constructors and {} matching syntax
whenever possible when interacting with aws types.

- 0.23
- Support anonymous access of S3 buckets.a
- Support anonymous access of S3 buckets.
- [breaking change] added isAnonymousCredentials to Credentials.
- Support bytestring 0.11

Expand Down
4 changes: 2 additions & 2 deletions aws.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: aws
Version: 0.23
Version: 0.24
Synopsis: Amazon Web Services (AWS) for Haskell
Description: Bindings for Amazon Web Services (AWS), with the aim of supporting all AWS services. To see a high level overview of the library, see the README at <https://github.com/aristidb/aws/blob/master/README.md>.
Homepage: http://github.com/aristidb/aws
Expand All @@ -19,7 +19,7 @@ Cabal-version: >=1.10
Source-repository this
type: git
location: https://github.com/aristidb/aws.git
tag: 0.23
tag: 0.24

Source-repository head
type: git
Expand Down

0 comments on commit bff2bf6

Please sign in to comment.