2012-11-20 20:43:58 +00:00
|
|
|
{- Amazon Web Services common infrastructure.
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2011-2014 Joey Hess <id@joeyh.name>
|
2012-11-20 20:43:58 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-11-20 20:43:58 +00:00
|
|
|
-}
|
|
|
|
|
2014-12-19 20:53:25 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE TupleSections #-}
|
2012-12-01 18:11:37 +00:00
|
|
|
|
2012-11-20 20:43:58 +00:00
|
|
|
module Remote.Helper.AWS where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2012-11-20 20:43:58 +00:00
|
|
|
import Creds
|
2020-01-10 18:10:20 +00:00
|
|
|
import Types.ProposedAccepted
|
2020-01-15 14:57:45 +00:00
|
|
|
import Types.RemoteConfig
|
2012-11-20 20:43:58 +00:00
|
|
|
|
2012-12-01 18:11:37 +00:00
|
|
|
import qualified Data.Map as M
|
2014-08-08 22:54:04 +00:00
|
|
|
import qualified Data.ByteString as B
|
|
|
|
import qualified Data.Text as T
|
|
|
|
import Data.Text.Encoding (encodeUtf8)
|
2012-12-01 18:11:37 +00:00
|
|
|
import Data.Text (Text)
|
|
|
|
|
2012-11-20 20:43:58 +00:00
|
|
|
creds :: UUID -> CredPairStorage
|
|
|
|
creds u = CredPairStorage
|
|
|
|
{ credPairFile = fromUUID u
|
|
|
|
, credPairEnvironment = ("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY")
|
2020-01-15 14:57:45 +00:00
|
|
|
, credPairRemoteField = s3credsField
|
2012-11-20 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:57:45 +00:00
|
|
|
s3credsField :: RemoteConfigField
|
|
|
|
s3credsField = Accepted "s3creds"
|
|
|
|
|
2012-12-01 18:11:37 +00:00
|
|
|
data Service = S3 | Glacier
|
|
|
|
deriving (Eq)
|
|
|
|
|
|
|
|
type Region = Text
|
|
|
|
|
|
|
|
regionMap :: Service -> M.Map Text Region
|
|
|
|
regionMap = M.fromList . regionInfo
|
|
|
|
|
|
|
|
defaultRegion :: Service -> Region
|
2024-09-26 22:43:59 +00:00
|
|
|
defaultRegion = snd . fromMaybe (error "internal") . headMaybe . regionInfo
|
2012-12-01 18:11:37 +00:00
|
|
|
|
2014-08-08 22:54:04 +00:00
|
|
|
data ServiceRegion = BothRegion Region | S3Region Region | GlacierRegion Region
|
|
|
|
|
|
|
|
{- The "US" and "EU" names are used as location constraints when creating a
|
|
|
|
- S3 bucket. -}
|
2012-12-01 18:11:37 +00:00
|
|
|
regionInfo :: Service -> [(Text, Region)]
|
|
|
|
regionInfo service = map (\(t, r) -> (t, fromServiceRegion r)) $
|
|
|
|
filter (matchingService . snd) $
|
|
|
|
concatMap (\(t, l) -> map (t,) l) regions
|
|
|
|
where
|
|
|
|
regions =
|
|
|
|
[ ("US East (N. Virginia)", [S3Region "US", GlacierRegion "us-east-1"])
|
|
|
|
, ("US West (Oregon)", [BothRegion "us-west-2"])
|
|
|
|
, ("US West (N. California)", [BothRegion "us-west-1"])
|
|
|
|
, ("EU (Ireland)", [S3Region "EU", GlacierRegion "eu-west-1"])
|
|
|
|
, ("Asia Pacific (Singapore)", [S3Region "ap-southeast-1"])
|
|
|
|
, ("Asia Pacific (Tokyo)", [BothRegion "ap-northeast-1"])
|
|
|
|
, ("Asia Pacific (Sydney)", [S3Region "ap-southeast-2"])
|
|
|
|
, ("South America (São Paulo)", [S3Region "sa-east-1"])
|
2023-01-31 18:42:26 +00:00
|
|
|
-- These need signature V4 to be used, and currently v2 is
|
|
|
|
-- the default, so to add these would need other changes.
|
2016-11-07 15:49:34 +00:00
|
|
|
-- , ("EU (Frankfurt)", [BothRegion "eu-central-1"])
|
|
|
|
-- , ("Asia Pacific (Seoul)", [S3Region "ap-northeast-2"])
|
|
|
|
-- , ("Asia Pacific (Mumbai)", [S3Region "ap-south-1"])
|
|
|
|
-- , ("US East (Ohio)", [S3Region "us-east-2"])
|
2012-12-01 18:11:37 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
fromServiceRegion (BothRegion s) = s
|
|
|
|
fromServiceRegion (S3Region s) = s
|
|
|
|
fromServiceRegion (GlacierRegion s) = s
|
|
|
|
|
|
|
|
matchingService (BothRegion _) = True
|
|
|
|
matchingService (S3Region _) = service == S3
|
|
|
|
matchingService (GlacierRegion _) = service == Glacier
|
|
|
|
|
2014-08-08 22:54:04 +00:00
|
|
|
s3HostName :: Region -> B.ByteString
|
|
|
|
s3HostName "US" = "s3.amazonaws.com"
|
|
|
|
s3HostName "EU" = "s3-eu-west-1.amazonaws.com"
|
2016-11-07 15:49:34 +00:00
|
|
|
s3HostName "cn-north-1" = "s3.cn-north-1.amazonaws.com.cn"
|
2014-08-08 22:54:04 +00:00
|
|
|
s3HostName r = encodeUtf8 $ T.concat ["s3-", r, ".amazonaws.com"]
|
|
|
|
|
|
|
|
s3DefaultHost :: String
|
|
|
|
s3DefaultHost = "s3.amazonaws.com"
|