module Network.AWS.Machines.AWS (
module Machine,
module Lawless,
AWSProcessT,
AWSSourceT,
RequestMod,
M,
withAWS,
awsSource,
pagedSource,
liftAWS,
liftIO,
MonadIO,
MonadAWS,
MonadBaseControl,
AWST',
Env,
ResourceT,
MonadCatch
) where
import Lawless hiding (
fold,
argument,
mapping,
filtered,
dropping,
droppingWhile,
taking,
takingWhile,
cycled,
iterated,
repeated,
replicated,
(<~),
(<>)
)
import Network.AWS hiding (send, within)
import Control.Monad.Trans.AWS
import Control.Monad.IO.Class
import Control.Monad.Trans.Control
import Control.Monad.Catch
import Text
import Control.Monad.Trans.Resource
import Machine
default (Text)
type M m = (MonadBaseControl IO m, MonadAWS (AWST' Env (ResourceT m)))
type AWSMachineT m k b = M m ⇒ MachineT (AWST' Env (ResourceT m)) k b
type AWSProcessT m a b = AWSMachineT m (Is a) b
type AWSSourceT m b = ∀ k. AWSMachineT m k b
type GetResponse f a c =
(AWSRequest a, Foldable f) ⇒ Getting (f c) (Rs a) (f c)
type RequestMod a = a → a
withAWS ∷ (MonadCatch m, MonadIO m, M m) ⇒
Credentials → Logger → Region → AWSProcessT m a b → m [b]
withAWS creds lgr reg f = do
env <- set envLogger lgr <$> newEnv creds
runResourceT $ runAWST env
$ within reg
$ runT f
awsSource ∷
(AWSRequest a, Foldable f) ⇒
GetResponse f a c
→ [RequestMod a]
→ a
→ AWSSourceT m c
awsSource i ms r =
let
r0 = modRequest ms r
unf _ rs = Just (rs ^. i, Nothing)
nr = \case
Nothing → return Nothing
Just q → liftAWS $ send q >>= return ∘ unf q
in
unfoldT nr (Just r0) >~> asParts
pagedSource ∷
(Foldable f, AWSPager a) ⇒
GetResponse f a c
→ [RequestMod a]
→ a
→ AWSSourceT m c
pagedSource i ms r =
let
unf rq rs = Just (rs ^. i, page rq rs)
nr mr =
case mr of
Nothing → return Nothing
Just q → liftAWS $ send q >>= return ∘ unf q
r0 = modRequest ms r
in
unfoldT nr (Just r0) >~> asParts
modRequest ∷
[RequestMod a] → a → a
modRequest [] rq = rq
modRequest (m:ms) rq = modRequest ms $ m rq