{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TupleSections #-}
module Aws.Iam.Internal
( iamAction
, iamAction'
, markedIter
, markedIterResponse
, (<>)
) where
import Aws.Core
import Aws.Iam.Core
import Control.Applicative
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Trans.Resource (MonadThrow)
import Data.ByteString (ByteString)
import Data.Maybe
import Data.Monoid ((<>))
import Prelude
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Text.XML.Cursor (($//))
import qualified Text.XML.Cursor as Cu
iamAction
:: ByteString
-> [(ByteString, Text)]
-> IamConfiguration qt
-> SignatureData
-> SignedQuery
iamAction action = iamSignQuery
. (:) ("Action", action)
. map (second Text.encodeUtf8)
iamAction'
:: ByteString
-> [Maybe (ByteString, Text)]
-> IamConfiguration qt
-> SignatureData
-> SignedQuery
iamAction' action = iamAction action . catMaybes
markedIter :: Maybe Text -> Maybe Integer -> [Maybe (ByteString, Text)]
markedIter marker maxItems
= [ ("Marker" ,) <$> marker
, ("MaxItems",) . encodeInteger <$> maxItems
]
where
encodeInteger = Text.pack . show
markedIterResponse
:: MonadThrow m
=> Cu.Cursor
-> m (Bool, Maybe Text)
markedIterResponse cursor = do
isTruncated <- (Text.toCaseFold "true" ==) `liftM` attr "IsTruncated"
marker <- if isTruncated
then Just `liftM` attr "Marker"
else return Nothing
return (isTruncated, marker)
where
attr name = force ("Missing " ++ Text.unpack name) $
cursor $// elContent name