packages feed

aws-simple (empty) → 0.1.0.0

raw patch · 7 files changed

+246/−0 lines, 7 filesdep +amazonkadep +amazonka-coredep +amazonka-s3setup-changed

Dependencies added: amazonka, amazonka-core, amazonka-s3, amazonka-sqs, base, blaze-builder, bytestring, conduit, lens, mtl, resourcet, text

Files

+ LICENSE view
@@ -0,0 +1,7 @@+Copyright (c) 2016 Alexander Thiemann++Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,5 @@+# aws-simple++[![CircleCI](https://circleci.com/gh/agrafix/aws-simple.svg?style=svg)](https://circleci.com/gh/agrafix/aws-simple)++Dead simple Haskell bindings to commonly used AWS Services, based and compatible with `amazonka`
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ aws-simple.cabal view
@@ -0,0 +1,44 @@+-- This file has been generated from package.yaml by hpack version 0.14.0.+--+-- see: https://github.com/sol/hpack++name:           aws-simple+version:        0.1.0.0+synopsis:       Dead simple bindings to commonly used AWS Services+description:    Please see README.md+category:       Web+homepage:       https://github.com/agrafix/aws-simple#readme+author:         Alexander Thiemann+maintainer:     mail@athiemann.net+copyright:      2016 Alexander Thiemann <mail@athiemann.net>+license:        MIT+license-file:   LICENSE+build-type:     Simple+cabal-version:  >= 1.10++extra-source-files:+    package.yaml+    README.md+    stack.yaml++library+  hs-source-dirs:+      src+  build-depends:+      base >= 4.7 && < 5+    , text+    , bytestring+    , mtl+    , resourcet+    , lens+    , conduit+    , amazonka+    , amazonka-core+    , amazonka-s3+    , amazonka-sqs+    , blaze-builder+  exposed-modules:+      Network.AWS.Simple+  other-modules:+      Paths_aws_simple+  default-language: Haskell2010
+ package.yaml view
@@ -0,0 +1,33 @@+name:                aws-simple+version:             0.1.0.0+synopsis:            Dead simple bindings to commonly used AWS Services+description:         Please see README.md+homepage:            https://github.com/agrafix/aws-simple#readme+license:             MIT+author:              Alexander Thiemann+maintainer:          mail@athiemann.net+copyright:           2016 Alexander Thiemann <mail@athiemann.net>+category:            Web+extra-source-files:+  - README.md+  - package.yaml+  - stack.yaml++dependencies:+  - base >= 4.7 && < 5+  - text+  - bytestring+  - mtl+  - resourcet+  - lens+  - conduit+  - amazonka+  - amazonka-core+  - amazonka-s3+  - amazonka-sqs+  - blaze-builder++library:+  source-dirs: src+  exposed-modules:+    - Network.AWS.Simple
+ src/Network/AWS/Simple.hs view
@@ -0,0 +1,152 @@+{-# LANGUAGE OverloadedStrings #-}+module Network.AWS.Simple+       ( connectAWS, AWSHandle+         -- * Logging+       , AWS.LogLevel (..), LogFun+         -- * S3+       , AWSFileReadability(..)+       , s3Upload, s3Download, s3Delete, s3CopyInBucket+         -- * SQS+       , sqsGetQueue, AWSQueue+       , sqsSendMessage+       , sqsGetMessage, GetMessageCfg(..), SqsMessage(..), MessageHandle+       , sqsAckMessage+       )+where++import Control.Lens+import Control.Monad+import Control.Monad.Trans+import Control.Monad.Trans.Resource+import Data.Conduit+import Data.Int+import Data.Maybe+import Data.Monoid+import qualified Blaze.ByteString.Builder as BSB+import qualified Data.ByteString as BS+import qualified Data.Text as T+import qualified Network.AWS as AWS+import qualified Network.AWS.Data.Body as AWS+import qualified Network.AWS.S3 as S3+import qualified Network.AWS.SQS as SQS++data AWSHandle =+    AWSHandle+    { a_cfg :: !AWS.Env+    }++type LogFun = AWS.LogLevel -> BS.ByteString -> IO ()++connectAWS :: LogFun -> IO AWSHandle+connectAWS logF =+    AWSHandle <$> hdl+    where+        hdl =+            do x <- AWS.newEnv AWS.Frankfurt AWS.Discover+               pure (x & AWS.envLogger .~ mkLogFun logF)++mkLogFun :: LogFun -> AWS.Logger+mkLogFun f ll logBuilder=+    f ll (BSB.toByteString logBuilder)++runAWS :: AWSHandle -> AWS.AWS a -> IO a+runAWS aws action =+    runResourceT $ AWS.runAWS (a_cfg aws) action++data AWSFileReadability+    = AWSFilePublicRead+    | AWSFilePrivate+    deriving (Show, Eq, Enum, Bounded)++s3Upload ::+    AWSHandle+    -> AWSFileReadability+    -> T.Text+    -> T.Text+    -> Int64+    -> Source (ResourceT IO) BS.ByteString -> IO ()+s3Upload hdl readability bucket objName size fileSource =+    runAWS hdl $+    do contentHash <- lift $ fileSource $$ AWS.sinkSHA256+       let body = AWS.HashedStream contentHash (fromIntegral size) fileSource+           po = S3.putObject (S3.BucketName bucket) (S3.ObjectKey objName) (AWS.Hashed body)+           poACL =+               case readability of+                 AWSFilePrivate -> po+                 AWSFilePublicRead -> po & S3.poACL .~ (Just S3.OPublicRead)+       _ <- AWS.send poACL+       pure ()++s3Download ::+    AWSHandle -> T.Text -> T.Text+    -> (ResumableSource (ResourceT IO) BS.ByteString -> ResourceT IO a)+    -> IO a+s3Download hdl bucket objName handleOutput =+    runAWS hdl $+    do rs <- AWS.send (S3.getObject (S3.BucketName bucket) (S3.ObjectKey objName))+       lift $ handleOutput $ AWS._streamBody $ view S3.gorsBody rs++s3Delete :: AWSHandle -> T.Text -> T.Text -> IO ()+s3Delete hdl bucket objName =+    runAWS hdl $+    void $ AWS.send (S3.deleteObject (S3.BucketName bucket) (S3.ObjectKey objName))++s3CopyInBucket :: AWSHandle -> T.Text -> T.Text -> T.Text -> IO ()+s3CopyInBucket hdl bucket objName newName =+    runAWS hdl $+    void $ AWS.send $+    S3.copyObject (S3.BucketName bucket) (bucket <> "/" <> objName) (S3.ObjectKey newName)++newtype AWSQueue =+    AWSQueue { _unAWSQueue :: T.Text } -- queue url+++sqsGetQueue :: AWSHandle -> T.Text -> IO AWSQueue+sqsGetQueue hdl name =+    runAWS hdl $+    AWSQueue <$> view SQS.gqursQueueURL <$> AWS.send (SQS.getQueueURL name)+++sqsSendMessage :: AWSHandle -> AWSQueue -> T.Text -> IO ()+sqsSendMessage hdl (AWSQueue q) payload =+    runAWS hdl $+    void $ AWS.send (SQS.sendMessage q payload)++data GetMessageCfg+   = GetMessageCfg+   { gmc_ackTimeout :: !Int+   , gmc_messages :: !Int -- ^ maximum is 10+   , gmc_waitTime :: !Int+   }++data SqsMessage+   = SqsMessage+   { sm_handle :: !MessageHandle+   , sm_payload :: !T.Text+   }++-- | Amazon SQS receipt handle id+newtype MessageHandle =+    MessageHandle { _unMessageHandle :: T.Text }++wrapMessage :: SQS.Message -> Maybe SqsMessage+wrapMessage msg =+    do hdl <- MessageHandle <$> msg ^. SQS.mReceiptHandle+       body <- msg ^. SQS.mBody+       pure $ SqsMessage hdl body++sqsGetMessage :: AWSHandle -> AWSQueue -> GetMessageCfg -> IO [SqsMessage]+sqsGetMessage hdl (AWSQueue q) gmc =+    runAWS hdl $+    do ms <-+           AWS.send $+           SQS.receiveMessage q+           & SQS.rmWaitTimeSeconds ?~ gmc_waitTime gmc+           & SQS.rmVisibilityTimeout ?~ gmc_ackTimeout gmc+           & SQS.rmMaxNumberOfMessages ?~ gmc_messages gmc+       return (mapMaybe wrapMessage $ ms ^. SQS.rmrsMessages)++sqsAckMessage :: AWSHandle -> AWSQueue -> MessageHandle -> IO ()+sqsAckMessage hdl (AWSQueue q) (MessageHandle rh) =+    runAWS hdl $+    void $ AWS.send (SQS.deleteMessage q rh)
+ stack.yaml view
@@ -0,0 +1,3 @@+resolver: lts-7.9+packages:+  - .