aristidb / aws

Amazon Web Services for Haskell
BSD 3-Clause "New" or "Revised" License
238 stars 107 forks source link

unable to specify a region for S3 servers not in AWS #283

Closed joeyh closed 1 year ago

joeyh commented 1 year ago

https://garagehq.deuxfleurs.fr/ is a S3 implementation that requires queries to have a region such as "garage". When running that server on example.com, it is not possible to use this library to send such a query.

The problem is that s3SignQuery has

region = s3ExtractRegion s3Endpoint

And s3Endpoint has to be a hostname, because it's also used to get the host:

    (host, path) = case s3RequestStyle of
        PathStyle   -> ([Just s3Endpoint] ...

So, s3Endpoint has to be "example.com", but then s3ExtractRegion will also use "example.com", there is no way to get region = "garage".

An example of this bug affecting a git-annex user: https://git-annex.branchable.com/bugs/S3_remote_errors_with_garage_endpoint/

joeyh commented 1 year ago

Fixing this seems to need an additional field in S3Configuration

s3Region :: Maybe ByteString

And then:

region = fromMaybe (s3ExtractRegion s3Endpoint) s3Region
joeyh commented 1 year ago

Apparently it's common for other S3 libraries/utilities to support an environment variable AWS_DEFAULT_REGION for this. I don't think that aws necessarily needs to support that environment variable, but that shows that it's common enough to need to set the region to something custom that other libraries support it.