WIP converting S3 special remote from hS3 to aws library
Currently, initremote works, but not the other operations. They should be fairly easy to add from this base. Also, https://github.com/aristidb/aws/issues/119 blocks internet archive support. Note that since http-conduit is used, this also adds https support to S3. Although git-annex encrypts everything anyway, so that may not be extremely useful. It is not enabled by default, because existing S3 special remotes have port=80 in their config. Setting port=443 will enable it. This commit was sponsored by Daniel Brockman.
This commit is contained in:
parent
7712e70885
commit
6fcca2f13e
5 changed files with 165 additions and 64 deletions
|
@ -1,6 +1,6 @@
|
|||
{- Amazon Web Services common infrastructure.
|
||||
-
|
||||
- Copyright 2011,2012 Joey Hess <joey@kitenet.net>
|
||||
- Copyright 2011-2014 Joey Hess <joey@kitenet.net>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
@ -12,8 +12,14 @@ module Remote.Helper.AWS where
|
|||
import Common.Annex
|
||||
import Creds
|
||||
|
||||
import qualified Aws
|
||||
import qualified Aws.S3 as S3
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.ByteString as B
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Encoding (encodeUtf8)
|
||||
import Data.Text (Text)
|
||||
import Data.IORef
|
||||
|
||||
creds :: UUID -> CredPairStorage
|
||||
creds u = CredPairStorage
|
||||
|
@ -22,6 +28,13 @@ creds u = CredPairStorage
|
|||
, credPairRemoteKey = Just "s3creds"
|
||||
}
|
||||
|
||||
genCredentials :: CredPair -> IO Aws.Credentials
|
||||
genCredentials (keyid, secret) = Aws.Credentials
|
||||
<$> pure (encodeUtf8 (T.pack keyid))
|
||||
<*> pure (encodeUtf8 (T.pack secret))
|
||||
<*> newIORef []
|
||||
<*> pure Nothing
|
||||
|
||||
data Service = S3 | Glacier
|
||||
deriving (Eq)
|
||||
|
||||
|
@ -33,9 +46,10 @@ regionMap = M.fromList . regionInfo
|
|||
defaultRegion :: Service -> Region
|
||||
defaultRegion = snd . Prelude.head . regionInfo
|
||||
|
||||
{- S3 and Glacier use different names for some regions. Ie, "us-east-1"
|
||||
- cannot be used with S3, while "US" cannot be used with Glacier. Dunno why.
|
||||
- Also, Glacier is not yet available in all regions. -}
|
||||
data ServiceRegion = BothRegion Region | S3Region Region | GlacierRegion Region
|
||||
|
||||
{- The "US" and "EU" names are used as location constraints when creating a
|
||||
- S3 bucket. -}
|
||||
regionInfo :: Service -> [(Text, Region)]
|
||||
regionInfo service = map (\(t, r) -> (t, fromServiceRegion r)) $
|
||||
filter (matchingService . snd) $
|
||||
|
@ -60,4 +74,14 @@ regionInfo service = map (\(t, r) -> (t, fromServiceRegion r)) $
|
|||
matchingService (S3Region _) = service == S3
|
||||
matchingService (GlacierRegion _) = service == Glacier
|
||||
|
||||
data ServiceRegion = BothRegion Region | S3Region Region | GlacierRegion Region
|
||||
s3HostName :: Region -> B.ByteString
|
||||
s3HostName "US" = "s3.amazonaws.com"
|
||||
s3HostName "EU" = "s3-eu-west-1.amazonaws.com"
|
||||
s3HostName r = encodeUtf8 $ T.concat ["s3-", r, ".amazonaws.com"]
|
||||
|
||||
s3DefaultHost :: String
|
||||
s3DefaultHost = "s3.amazonaws.com"
|
||||
|
||||
mkLocationConstraint :: Region -> S3.LocationConstraint
|
||||
mkLocationConstraint "US" = S3.locationUsClassic
|
||||
mkLocationConstraint r = r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue