{-# LANGUAGE CPP #-}
module Aws.Sqs.Core where

import           Aws.Core
import           Aws.S3.Core                    (LocationConstraint, locationUsClassic, locationUsWest, locationUsWest2, locationApSouthEast, locationApSouthEast2, locationApNorthEast, locationEu, locationEuWest2)
import qualified Blaze.ByteString.Builder       as Blaze
import qualified Blaze.ByteString.Builder.Char8 as Blaze8
import qualified Control.Exception              as C
import           Control.Monad
import           Control.Monad.IO.Class
import           Control.Monad.Trans.Resource   (MonadThrow, throwM)
import qualified Data.ByteString                as B
import qualified Data.ByteString.Char8          as BC
import qualified Data.Conduit
import           Data.Conduit                   ((.|))
import           Data.IORef
import           Data.List
import           Data.Maybe
import           Data.Monoid
import qualified Data.Semigroup                 as Sem
import           Data.Ord
import qualified Data.Text                      as T
import qualified Data.Text.Encoding             as T
import qualified Data.Text.Encoding             as TE
import           Data.Time
import           Data.Typeable
import           Prelude
import qualified Network.HTTP.Conduit           as HTTP
import qualified Network.HTTP.Types             as HTTP
#if !MIN_VERSION_time(1,5,0)
import           System.Locale
#endif
import qualified Text.XML                       as XML
import           Text.XML.Cursor                (($/))
import qualified Text.XML.Cursor                as Cu

type ErrorCode = T.Text

data SqsError
    = SqsError {
        SqsError -> Status
sqsStatusCode :: HTTP.Status
      , SqsError -> ErrorCode
sqsErrorCode :: ErrorCode
      , SqsError -> ErrorCode
sqsErrorType :: T.Text
      , SqsError -> ErrorCode
sqsErrorMessage :: T.Text
      , SqsError -> Maybe ErrorCode
sqsErrorDetail :: Maybe T.Text
      , SqsError -> Maybe SqsMetadata
sqsErrorMetadata :: Maybe SqsMetadata
      }
    | SqsXmlError { 
        SqsError -> ErrorCode
sqsXmlErrorMessage :: T.Text
      , SqsError -> Maybe SqsMetadata
sqsXmlErrorMetadata :: Maybe SqsMetadata
      }
    deriving (Int -> SqsError -> ShowS
[SqsError] -> ShowS
SqsError -> String
(Int -> SqsError -> ShowS)
-> (SqsError -> String) -> ([SqsError] -> ShowS) -> Show SqsError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqsError] -> ShowS
$cshowList :: [SqsError] -> ShowS
show :: SqsError -> String
$cshow :: SqsError -> String
showsPrec :: Int -> SqsError -> ShowS
$cshowsPrec :: Int -> SqsError -> ShowS
Show, Typeable)

instance C.Exception SqsError

data SqsMetadata
    = SqsMetadata {
        SqsMetadata -> Maybe ErrorCode
sqsMAmzId2 :: Maybe T.Text
      , SqsMetadata -> Maybe ErrorCode
sqsMRequestId :: Maybe T.Text
      }
    deriving (Int -> SqsMetadata -> ShowS
[SqsMetadata] -> ShowS
SqsMetadata -> String
(Int -> SqsMetadata -> ShowS)
-> (SqsMetadata -> String)
-> ([SqsMetadata] -> ShowS)
-> Show SqsMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqsMetadata] -> ShowS
$cshowList :: [SqsMetadata] -> ShowS
show :: SqsMetadata -> String
$cshow :: SqsMetadata -> String
showsPrec :: Int -> SqsMetadata -> ShowS
$cshowsPrec :: Int -> SqsMetadata -> ShowS
Show)

instance Loggable SqsMetadata where
    toLogText :: SqsMetadata -> ErrorCode
toLogText (SqsMetadata Maybe ErrorCode
id2 Maybe ErrorCode
rid) = ErrorCode
"SQS: request ID=" ErrorCode -> ErrorCode -> ErrorCode
forall a. Monoid a => a -> a -> a
`mappend`
                                      ErrorCode -> Maybe ErrorCode -> ErrorCode
forall a. a -> Maybe a -> a
fromMaybe ErrorCode
"<none>" Maybe ErrorCode
rid ErrorCode -> ErrorCode -> ErrorCode
forall a. Monoid a => a -> a -> a
`mappend`
                                      ErrorCode
", x-amz-id-2=" ErrorCode -> ErrorCode -> ErrorCode
forall a. Monoid a => a -> a -> a
`mappend`
                                      ErrorCode -> Maybe ErrorCode -> ErrorCode
forall a. a -> Maybe a -> a
fromMaybe ErrorCode
"<none>" Maybe ErrorCode
id2

instance Sem.Semigroup SqsMetadata where
    SqsMetadata Maybe ErrorCode
a1 Maybe ErrorCode
r1 <> :: SqsMetadata -> SqsMetadata -> SqsMetadata
<> SqsMetadata Maybe ErrorCode
a2 Maybe ErrorCode
r2 = Maybe ErrorCode -> Maybe ErrorCode -> SqsMetadata
SqsMetadata (Maybe ErrorCode
a1 Maybe ErrorCode -> Maybe ErrorCode -> Maybe ErrorCode
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Maybe ErrorCode
a2) (Maybe ErrorCode
r1 Maybe ErrorCode -> Maybe ErrorCode -> Maybe ErrorCode
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Maybe ErrorCode
r2)

instance Monoid SqsMetadata where
    mempty :: SqsMetadata
mempty = Maybe ErrorCode -> Maybe ErrorCode -> SqsMetadata
SqsMetadata Maybe ErrorCode
forall a. Maybe a
Nothing Maybe ErrorCode
forall a. Maybe a
Nothing
    mappend :: SqsMetadata -> SqsMetadata -> SqsMetadata
mappend = SqsMetadata -> SqsMetadata -> SqsMetadata
forall a. Semigroup a => a -> a -> a
(Sem.<>)

data SqsAuthorization 
    = SqsAuthorizationHeader 
    | SqsAuthorizationQuery
    deriving (Int -> SqsAuthorization -> ShowS
[SqsAuthorization] -> ShowS
SqsAuthorization -> String
(Int -> SqsAuthorization -> ShowS)
-> (SqsAuthorization -> String)
-> ([SqsAuthorization] -> ShowS)
-> Show SqsAuthorization
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqsAuthorization] -> ShowS
$cshowList :: [SqsAuthorization] -> ShowS
show :: SqsAuthorization -> String
$cshow :: SqsAuthorization -> String
showsPrec :: Int -> SqsAuthorization -> ShowS
$cshowsPrec :: Int -> SqsAuthorization -> ShowS
Show)

data Endpoint
    = Endpoint {
        Endpoint -> ByteString
endpointHost :: B.ByteString
      , Endpoint -> ErrorCode
endpointDefaultLocationConstraint :: LocationConstraint
      , Endpoint -> [ErrorCode]
endpointAllowedLocationConstraints :: [LocationConstraint]
      }
    deriving (Int -> Endpoint -> ShowS
[Endpoint] -> ShowS
Endpoint -> String
(Int -> Endpoint -> ShowS)
-> (Endpoint -> String) -> ([Endpoint] -> ShowS) -> Show Endpoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Endpoint] -> ShowS
$cshowList :: [Endpoint] -> ShowS
show :: Endpoint -> String
$cshow :: Endpoint -> String
showsPrec :: Int -> Endpoint -> ShowS
$cshowsPrec :: Int -> Endpoint -> ShowS
Show)

data SqsConfiguration qt
    = SqsConfiguration {
        SqsConfiguration qt -> Protocol
sqsProtocol :: Protocol
      , SqsConfiguration qt -> Endpoint
sqsEndpoint :: Endpoint
      , SqsConfiguration qt -> Int
sqsPort :: Int
      , SqsConfiguration qt -> Bool
sqsUseUri :: Bool
      , SqsConfiguration qt -> NominalDiffTime
sqsDefaultExpiry :: NominalDiffTime
      }
    deriving (Int -> SqsConfiguration qt -> ShowS
[SqsConfiguration qt] -> ShowS
SqsConfiguration qt -> String
(Int -> SqsConfiguration qt -> ShowS)
-> (SqsConfiguration qt -> String)
-> ([SqsConfiguration qt] -> ShowS)
-> Show (SqsConfiguration qt)
forall qt. Int -> SqsConfiguration qt -> ShowS
forall qt. [SqsConfiguration qt] -> ShowS
forall qt. SqsConfiguration qt -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqsConfiguration qt] -> ShowS
$cshowList :: forall qt. [SqsConfiguration qt] -> ShowS
show :: SqsConfiguration qt -> String
$cshow :: forall qt. SqsConfiguration qt -> String
showsPrec :: Int -> SqsConfiguration qt -> ShowS
$cshowsPrec :: forall qt. Int -> SqsConfiguration qt -> ShowS
Show)

instance DefaultServiceConfiguration (SqsConfiguration NormalQuery) where
    defServiceConfig :: SqsConfiguration NormalQuery
defServiceConfig = Protocol -> Endpoint -> Bool -> SqsConfiguration NormalQuery
forall qt. Protocol -> Endpoint -> Bool -> SqsConfiguration qt
sqs Protocol
HTTPS Endpoint
sqsEndpointUsClassic Bool
False
    debugServiceConfig :: SqsConfiguration NormalQuery
debugServiceConfig = Protocol -> Endpoint -> Bool -> SqsConfiguration NormalQuery
forall qt. Protocol -> Endpoint -> Bool -> SqsConfiguration qt
sqs Protocol
HTTP Endpoint
sqsEndpointUsClassic Bool
False

instance DefaultServiceConfiguration (SqsConfiguration UriOnlyQuery) where
    defServiceConfig :: SqsConfiguration UriOnlyQuery
defServiceConfig = Protocol -> Endpoint -> Bool -> SqsConfiguration UriOnlyQuery
forall qt. Protocol -> Endpoint -> Bool -> SqsConfiguration qt
sqs Protocol
HTTPS Endpoint
sqsEndpointUsClassic Bool
True
    debugServiceConfig :: SqsConfiguration UriOnlyQuery
debugServiceConfig = Protocol -> Endpoint -> Bool -> SqsConfiguration UriOnlyQuery
forall qt. Protocol -> Endpoint -> Bool -> SqsConfiguration qt
sqs Protocol
HTTP Endpoint
sqsEndpointUsClassic Bool
True
  
sqsEndpointUsClassic :: Endpoint
sqsEndpointUsClassic :: Endpoint
sqsEndpointUsClassic 
    = Endpoint :: ByteString -> ErrorCode -> [ErrorCode] -> Endpoint
Endpoint { 
        endpointHost :: ByteString
endpointHost = ByteString
"queue.amazonaws.com"
      , endpointDefaultLocationConstraint :: ErrorCode
endpointDefaultLocationConstraint = ErrorCode
locationUsClassic
      , endpointAllowedLocationConstraints :: [ErrorCode]
endpointAllowedLocationConstraints = [ErrorCode
locationUsClassic
                                             , ErrorCode
locationUsWest
                                             , ErrorCode
locationEu
                                             , ErrorCode
locationApSouthEast
                                             , ErrorCode
locationApNorthEast]
      }

sqsEndpointUsWest :: Endpoint
sqsEndpointUsWest :: Endpoint
sqsEndpointUsWest
    = Endpoint :: ByteString -> ErrorCode -> [ErrorCode] -> Endpoint
Endpoint {
        endpointHost :: ByteString
endpointHost = ByteString
"us-west-1.queue.amazonaws.com"
      , endpointDefaultLocationConstraint :: ErrorCode
endpointDefaultLocationConstraint = ErrorCode
locationUsWest
      , endpointAllowedLocationConstraints :: [ErrorCode]
endpointAllowedLocationConstraints = [ErrorCode
locationUsWest]
      }

sqsEndpointUsWest2 :: Endpoint
sqsEndpointUsWest2 :: Endpoint
sqsEndpointUsWest2
    = Endpoint :: ByteString -> ErrorCode -> [ErrorCode] -> Endpoint
Endpoint {
        endpointHost :: ByteString
endpointHost = ByteString
"us-west-2.queue.amazonaws.com"
      , endpointDefaultLocationConstraint :: ErrorCode
endpointDefaultLocationConstraint = ErrorCode
locationUsWest2
      , endpointAllowedLocationConstraints :: [ErrorCode]
endpointAllowedLocationConstraints = [ErrorCode
locationUsWest2]
      }

sqsEndpointEu :: Endpoint
sqsEndpointEu :: Endpoint
sqsEndpointEu
    = Endpoint :: ByteString -> ErrorCode -> [ErrorCode] -> Endpoint
Endpoint {
        endpointHost :: ByteString
endpointHost = ByteString
"eu-west-1.queue.amazonaws.com"
      , endpointDefaultLocationConstraint :: ErrorCode
endpointDefaultLocationConstraint = ErrorCode
locationEu
      , endpointAllowedLocationConstraints :: [ErrorCode]
endpointAllowedLocationConstraints = [ErrorCode
locationEu]
      }

sqsEndpointEuWest2 :: Endpoint
sqsEndpointEuWest2 :: Endpoint
sqsEndpointEuWest2
    = Endpoint :: ByteString -> ErrorCode -> [ErrorCode] -> Endpoint
Endpoint {
        endpointHost :: ByteString
endpointHost = ByteString
"eu-west-2.queue.amazonaws.com"
      , endpointDefaultLocationConstraint :: ErrorCode
endpointDefaultLocationConstraint = ErrorCode
locationEuWest2
      , endpointAllowedLocationConstraints :: [ErrorCode]
endpointAllowedLocationConstraints = [ErrorCode
locationEuWest2]
      }

sqsEndpointApSouthEast :: Endpoint
sqsEndpointApSouthEast :: Endpoint
sqsEndpointApSouthEast
    = Endpoint :: ByteString -> ErrorCode -> [ErrorCode] -> Endpoint
Endpoint {
        endpointHost :: ByteString
endpointHost = ByteString
"ap-southeast-1.queue.amazonaws.com"
      , endpointDefaultLocationConstraint :: ErrorCode
endpointDefaultLocationConstraint = ErrorCode
locationApSouthEast
      , endpointAllowedLocationConstraints :: [ErrorCode]
endpointAllowedLocationConstraints = [ErrorCode
locationApSouthEast]
      }

sqsEndpointApSouthEast2 :: Endpoint
sqsEndpointApSouthEast2 :: Endpoint
sqsEndpointApSouthEast2
    = Endpoint :: ByteString -> ErrorCode -> [ErrorCode] -> Endpoint
Endpoint {
        endpointHost :: ByteString
endpointHost = ByteString
"sqs.ap-southeast-2.amazonaws.com"
      , endpointDefaultLocationConstraint :: ErrorCode
endpointDefaultLocationConstraint = ErrorCode
locationApSouthEast2
      , endpointAllowedLocationConstraints :: [ErrorCode]
endpointAllowedLocationConstraints = [ErrorCode
locationApSouthEast2]
      }

sqsEndpointApNorthEast :: Endpoint
sqsEndpointApNorthEast :: Endpoint
sqsEndpointApNorthEast
    = Endpoint :: ByteString -> ErrorCode -> [ErrorCode] -> Endpoint
Endpoint {
        endpointHost :: ByteString
endpointHost = ByteString
"sqs.ap-northeast-1.amazonaws.com"
      , endpointDefaultLocationConstraint :: ErrorCode
endpointDefaultLocationConstraint = ErrorCode
locationApNorthEast
      , endpointAllowedLocationConstraints :: [ErrorCode]
endpointAllowedLocationConstraints = [ErrorCode
locationApNorthEast]
      }

sqs :: Protocol -> Endpoint -> Bool -> SqsConfiguration qt
sqs :: Protocol -> Endpoint -> Bool -> SqsConfiguration qt
sqs Protocol
protocol Endpoint
endpoint Bool
uri 
    = SqsConfiguration :: forall qt.
Protocol
-> Endpoint
-> Int
-> Bool
-> NominalDiffTime
-> SqsConfiguration qt
SqsConfiguration { 
        sqsProtocol :: Protocol
sqsProtocol = Protocol
protocol
      , sqsEndpoint :: Endpoint
sqsEndpoint = Endpoint
endpoint
      , sqsPort :: Int
sqsPort = Protocol -> Int
defaultPort Protocol
protocol
      , sqsUseUri :: Bool
sqsUseUri = Bool
uri
      , sqsDefaultExpiry :: NominalDiffTime
sqsDefaultExpiry = NominalDiffTime
15NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall a. Num a => a -> a -> a
*NominalDiffTime
60
      }

data SqsQuery = SqsQuery{
  SqsQuery -> Maybe QueueName
sqsQueueName :: Maybe QueueName,
  SqsQuery -> Query
sqsQuery :: HTTP.Query
}

sqsSignQuery :: SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery :: SqsQuery -> SqsConfiguration qt -> SignatureData -> SignedQuery
sqsSignQuery SqsQuery{Query
Maybe QueueName
sqsQuery :: Query
sqsQueueName :: Maybe QueueName
sqsQuery :: SqsQuery -> Query
sqsQueueName :: SqsQuery -> Maybe QueueName
..} SqsConfiguration{Bool
Int
NominalDiffTime
Protocol
Endpoint
sqsDefaultExpiry :: NominalDiffTime
sqsUseUri :: Bool
sqsPort :: Int
sqsEndpoint :: Endpoint
sqsProtocol :: Protocol
sqsDefaultExpiry :: forall qt. SqsConfiguration qt -> NominalDiffTime
sqsUseUri :: forall qt. SqsConfiguration qt -> Bool
sqsPort :: forall qt. SqsConfiguration qt -> Int
sqsEndpoint :: forall qt. SqsConfiguration qt -> Endpoint
sqsProtocol :: forall qt. SqsConfiguration qt -> Protocol
..} SignatureData{UTCTime
AbsoluteTimeInfo
Credentials
signatureCredentials :: SignatureData -> Credentials
signatureTime :: SignatureData -> UTCTime
signatureTimeInfo :: SignatureData -> AbsoluteTimeInfo
signatureCredentials :: Credentials
signatureTime :: UTCTime
signatureTimeInfo :: AbsoluteTimeInfo
..}
    = SignedQuery :: Method
-> Protocol
-> ByteString
-> Int
-> ByteString
-> Query
-> Maybe UTCTime
-> Maybe (IO ByteString)
-> Maybe ByteString
-> Maybe (Digest MD5)
-> RequestHeaders
-> RequestHeaders
-> Maybe RequestBody
-> ByteString
-> SignedQuery
SignedQuery {
        sqMethod :: Method
sqMethod = Method
method
      , sqProtocol :: Protocol
sqProtocol = Protocol
sqsProtocol
      , sqHost :: ByteString
sqHost = Endpoint -> ByteString
endpointHost Endpoint
sqsEndpoint
      , sqPort :: Int
sqPort = Int
sqsPort
      , sqPath :: ByteString
sqPath = ByteString
path
      , sqQuery :: Query
sqQuery = Query
signedQuery
      , sqDate :: Maybe UTCTime
sqDate = UTCTime -> Maybe UTCTime
forall a. a -> Maybe a
Just UTCTime
signatureTime
      , sqAuthorization :: Maybe (IO ByteString)
sqAuthorization = Maybe (IO ByteString)
forall a. Maybe a
Nothing 
      , sqBody :: Maybe RequestBody
sqBody = Maybe RequestBody
forall a. Maybe a
Nothing
      , sqStringToSign :: ByteString
sqStringToSign = ByteString
stringToSign
      , sqContentType :: Maybe ByteString
sqContentType = Maybe ByteString
forall a. Maybe a
Nothing
      , sqContentMd5 :: Maybe (Digest MD5)
sqContentMd5 = Maybe (Digest MD5)
forall a. Maybe a
Nothing
      , sqAmzHeaders :: RequestHeaders
sqAmzHeaders = []
      , sqOtherHeaders :: RequestHeaders
sqOtherHeaders = []
      }
    where
      method :: Method
method = Method
PostQuery
      path :: ByteString
path = case Maybe QueueName
sqsQueueName of
                Just QueueName
x -> ErrorCode -> ByteString
TE.encodeUtf8 (ErrorCode -> ByteString) -> ErrorCode -> ByteString
forall a b. (a -> b) -> a -> b
$ QueueName -> ErrorCode
printQueueName QueueName
x
                Maybe QueueName
Nothing -> ByteString
"/"
      expandedQuery :: Query
expandedQuery = ((ByteString, Maybe ByteString)
 -> (ByteString, Maybe ByteString) -> Ordering)
-> Query -> Query
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((ByteString, Maybe ByteString) -> ByteString)
-> (ByteString, Maybe ByteString)
-> (ByteString, Maybe ByteString)
-> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing (ByteString, Maybe ByteString) -> ByteString
forall a b. (a, b) -> a
fst) 
                       ( Query
sqsQuery Query -> Query -> Query
forall a. [a] -> [a] -> [a]
++ [ (ByteString
"AWSAccessKeyId", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just(Credentials -> ByteString
accessKeyID Credentials
signatureCredentials)), 
                       (ByteString
"Expires", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just(String -> ByteString
BC.pack String
expiresString)), 
                       (ByteString
"SignatureMethod", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just(ByteString
"HmacSHA256")), (ByteString
"SignatureVersion",ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just(ByteString
"2")), (ByteString
"Version",ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just(ByteString
"2012-11-05"))] Query -> Query -> Query
forall a. [a] -> [a] -> [a]
++
                       Query -> (ByteString -> Query) -> Maybe ByteString -> Query
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
tok -> [(ByteString
"SecurityToken", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
tok)]) (Credentials -> Maybe ByteString
iamToken Credentials
signatureCredentials))

      expires :: AbsoluteTimeInfo
expires = UTCTime -> AbsoluteTimeInfo
AbsoluteExpires (UTCTime -> AbsoluteTimeInfo) -> UTCTime -> AbsoluteTimeInfo
forall a b. (a -> b) -> a -> b
$ NominalDiffTime
sqsDefaultExpiry NominalDiffTime -> UTCTime -> UTCTime
`addUTCTime` UTCTime
signatureTime

      expiresString :: String
expiresString = TimeLocale -> String -> UTCTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
"%FT%TZ" (AbsoluteTimeInfo -> UTCTime
fromAbsoluteTimeInfo AbsoluteTimeInfo
expires)

      sig :: ByteString
sig = Credentials -> AuthorizationHash -> ByteString -> ByteString
signature Credentials
signatureCredentials AuthorizationHash
HmacSHA256 ByteString
stringToSign
      stringToSign :: ByteString
stringToSign = Builder -> ByteString
Blaze.toByteString (Builder -> ByteString)
-> ([[Builder]] -> Builder) -> [[Builder]] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ([Builder] -> Builder)
-> ([[Builder]] -> [Builder]) -> [[Builder]] -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> [Builder] -> [Builder]
forall a. a -> [a] -> [a]
intersperse (Char -> Builder
Blaze8.fromChar Char
'\n') ([Builder] -> [Builder])
-> ([[Builder]] -> [Builder]) -> [[Builder]] -> [Builder]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Builder]] -> [Builder]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat  ([[Builder]] -> ByteString) -> [[Builder]] -> ByteString
forall a b. (a -> b) -> a -> b
$
                       [[ByteString -> Builder
Blaze.copyByteString (ByteString -> Builder) -> ByteString -> Builder
forall a b. (a -> b) -> a -> b
$ Method -> ByteString
httpMethod Method
method]
                       , [ByteString -> Builder
Blaze.copyByteString (ByteString -> Builder) -> ByteString -> Builder
forall a b. (a -> b) -> a -> b
$ Endpoint -> ByteString
endpointHost Endpoint
sqsEndpoint]
                       , [ByteString -> Builder
Blaze.copyByteString ByteString
path]
                       , [ByteString -> Builder
Blaze.copyByteString (ByteString -> Builder) -> ByteString -> Builder
forall a b. (a -> b) -> a -> b
$ Bool -> Query -> ByteString
HTTP.renderQuery Bool
False Query
expandedQuery ]]

      signedQuery :: Query
signedQuery = Query
expandedQuery Query -> Query -> Query
forall a. [a] -> [a] -> [a]
++ (SimpleQuery -> Query
HTTP.simpleQueryToQuery (SimpleQuery -> Query) -> SimpleQuery -> Query
forall a b. (a -> b) -> a -> b
$ SimpleQuery
makeAuthQuery)

      makeAuthQuery :: SimpleQuery
makeAuthQuery = [(ByteString
"Signature", ByteString
sig)]

sqsResponseConsumer :: HTTPResponseConsumer a
                    -> IORef SqsMetadata
                    -> HTTPResponseConsumer a
sqsResponseConsumer :: HTTPResponseConsumer a
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsResponseConsumer HTTPResponseConsumer a
inner IORef SqsMetadata
metadata Response (ConduitM () ByteString (ResourceT IO) ())
resp = do
      let headerString :: HeaderName -> Maybe ErrorCode
headerString = (ByteString -> ErrorCode) -> Maybe ByteString -> Maybe ErrorCode
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ErrorCode
T.decodeUtf8 (Maybe ByteString -> Maybe ErrorCode)
-> (HeaderName -> Maybe ByteString)
-> HeaderName
-> Maybe ErrorCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (HeaderName -> RequestHeaders -> Maybe ByteString)
-> RequestHeaders -> HeaderName -> Maybe ByteString
forall a b c. (a -> b -> c) -> b -> a -> c
flip HeaderName -> RequestHeaders -> Maybe ByteString
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup (Response (ConduitM () ByteString (ResourceT IO) ())
-> RequestHeaders
forall body. Response body -> RequestHeaders
HTTP.responseHeaders Response (ConduitM () ByteString (ResourceT IO) ())
resp)
      let amzId2 :: Maybe ErrorCode
amzId2 = HeaderName -> Maybe ErrorCode
headerString HeaderName
"x-amz-id-2"
      let requestId :: Maybe ErrorCode
requestId = HeaderName -> Maybe ErrorCode
headerString HeaderName
"x-amz-request-id"

      let m :: SqsMetadata
m = SqsMetadata :: Maybe ErrorCode -> Maybe ErrorCode -> SqsMetadata
SqsMetadata { sqsMAmzId2 :: Maybe ErrorCode
sqsMAmzId2 = Maybe ErrorCode
amzId2, sqsMRequestId :: Maybe ErrorCode
sqsMRequestId = Maybe ErrorCode
requestId }
      IO () -> ResourceT IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ResourceT IO ()) -> IO () -> ResourceT IO ()
forall a b. (a -> b) -> a -> b
$ IORef SqsMetadata -> SqsMetadata -> IO ()
forall m. Monoid m => IORef m -> m -> IO ()
tellMetadataRef IORef SqsMetadata
metadata SqsMetadata
m

      if Response (ConduitM () ByteString (ResourceT IO) ()) -> Status
forall body. Response body -> Status
HTTP.responseStatus Response (ConduitM () ByteString (ResourceT IO) ())
resp Status -> Status -> Bool
forall a. Ord a => a -> a -> Bool
>= Status
HTTP.status400
        then HTTPResponseConsumer a
forall a. HTTPResponseConsumer a
sqsErrorResponseConsumer Response (ConduitM () ByteString (ResourceT IO) ())
resp
        else HTTPResponseConsumer a
inner Response (ConduitM () ByteString (ResourceT IO) ())
resp

sqsXmlResponseConsumer :: (Cu.Cursor -> Response SqsMetadata a)
                       -> IORef SqsMetadata
                       -> HTTPResponseConsumer a
sqsXmlResponseConsumer :: (Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsXmlResponseConsumer Cursor -> Response SqsMetadata a
parse IORef SqsMetadata
metadataRef = HTTPResponseConsumer a
-> IORef SqsMetadata -> HTTPResponseConsumer a
forall a.
HTTPResponseConsumer a
-> IORef SqsMetadata -> HTTPResponseConsumer a
sqsResponseConsumer ((Cursor -> Response SqsMetadata a)
-> IORef SqsMetadata -> HTTPResponseConsumer a
forall m a.
Monoid m =>
(Cursor -> Response m a) -> IORef m -> HTTPResponseConsumer a
xmlCursorConsumer Cursor -> Response SqsMetadata a
parse IORef SqsMetadata
metadataRef) IORef SqsMetadata
metadataRef

sqsErrorResponseConsumer :: HTTPResponseConsumer a
sqsErrorResponseConsumer :: HTTPResponseConsumer a
sqsErrorResponseConsumer Response (ConduitM () ByteString (ResourceT IO) ())
resp
    = do Document
doc <- ConduitT () Void (ResourceT IO) Document -> ResourceT IO Document
forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
Data.Conduit.runConduit (ConduitT () Void (ResourceT IO) Document -> ResourceT IO Document)
-> ConduitT () Void (ResourceT IO) Document
-> ResourceT IO Document
forall a b. (a -> b) -> a -> b
$ Response (ConduitM () ByteString (ResourceT IO) ())
-> ConduitM () ByteString (ResourceT IO) ()
forall body. Response body -> body
HTTP.responseBody Response (ConduitM () ByteString (ResourceT IO) ())
resp ConduitM () ByteString (ResourceT IO) ()
-> ConduitM ByteString Void (ResourceT IO) Document
-> ConduitT () Void (ResourceT IO) Document
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
.| ParseSettings -> ConduitM ByteString Void (ResourceT IO) Document
forall (m :: * -> *) o.
MonadThrow m =>
ParseSettings -> ConduitT ByteString o m Document
XML.sinkDoc ParseSettings
forall a. Default a => a
XML.def
         let cursor :: Cursor
cursor = Document -> Cursor
Cu.fromDocument Document
doc
         IO a -> ResourceT IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> ResourceT IO a) -> IO a -> ResourceT IO a
forall a b. (a -> b) -> a -> b
$ case Cursor -> Either SomeException SqsError
parseError Cursor
cursor of
           Right SqsError
err     -> SqsError -> IO a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM SqsError
err
           Left SomeException
otherErr -> SomeException -> IO a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM SomeException
otherErr
    where
      parseError :: Cu.Cursor -> Either C.SomeException SqsError
      parseError :: Cursor -> Either SomeException SqsError
parseError Cursor
root = do Cursor
cursor <- String -> [Cursor] -> Either SomeException Cursor
forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
force String
"Missing Error" ([Cursor] -> Either SomeException Cursor)
-> [Cursor] -> Either SomeException Cursor
forall a b. (a -> b) -> a -> b
$ Cursor
root Cursor -> (Cursor -> [Cursor]) -> [Cursor]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ ErrorCode -> Cursor -> [Cursor]
Cu.laxElement ErrorCode
"Error"
                           ErrorCode
code <- String -> [ErrorCode] -> Either SomeException ErrorCode
forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
force String
"Missing error Code" ([ErrorCode] -> Either SomeException ErrorCode)
-> [ErrorCode] -> Either SomeException ErrorCode
forall a b. (a -> b) -> a -> b
$ Cursor
cursor Cursor -> (Cursor -> [ErrorCode]) -> [ErrorCode]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ ErrorCode -> Cursor -> [ErrorCode]
elContent ErrorCode
"Code"
                           ErrorCode
message <- String -> [ErrorCode] -> Either SomeException ErrorCode
forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
force String
"Missing error Message" ([ErrorCode] -> Either SomeException ErrorCode)
-> [ErrorCode] -> Either SomeException ErrorCode
forall a b. (a -> b) -> a -> b
$ Cursor
cursor Cursor -> (Cursor -> [ErrorCode]) -> [ErrorCode]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ ErrorCode -> Cursor -> [ErrorCode]
elContent ErrorCode
"Message"
                           ErrorCode
errorType <- String -> [ErrorCode] -> Either SomeException ErrorCode
forall (m :: * -> *) a. MonadThrow m => String -> [a] -> m a
force String
"Missing error Type" ([ErrorCode] -> Either SomeException ErrorCode)
-> [ErrorCode] -> Either SomeException ErrorCode
forall a b. (a -> b) -> a -> b
$ Cursor
cursor Cursor -> (Cursor -> [ErrorCode]) -> [ErrorCode]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ ErrorCode -> Cursor -> [ErrorCode]
elContent ErrorCode
"Type"
                           let detail :: Maybe ErrorCode
detail = [ErrorCode] -> Maybe ErrorCode
forall a. [a] -> Maybe a
listToMaybe ([ErrorCode] -> Maybe ErrorCode) -> [ErrorCode] -> Maybe ErrorCode
forall a b. (a -> b) -> a -> b
$ Cursor
cursor Cursor -> (Cursor -> [ErrorCode]) -> [ErrorCode]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ ErrorCode -> Cursor -> [ErrorCode]
elContent ErrorCode
"Detail"

                           SqsError -> Either SomeException SqsError
forall (m :: * -> *) a. Monad m => a -> m a
return SqsError :: Status
-> ErrorCode
-> ErrorCode
-> ErrorCode
-> Maybe ErrorCode
-> Maybe SqsMetadata
-> SqsError
SqsError {
                                        sqsStatusCode :: Status
sqsStatusCode = Response (ConduitM () ByteString (ResourceT IO) ()) -> Status
forall body. Response body -> Status
HTTP.responseStatus Response (ConduitM () ByteString (ResourceT IO) ())
resp
                                      , sqsErrorCode :: ErrorCode
sqsErrorCode = ErrorCode
code
                                      , sqsErrorMessage :: ErrorCode
sqsErrorMessage = ErrorCode
message
                                      , sqsErrorType :: ErrorCode
sqsErrorType = ErrorCode
errorType
                                      , sqsErrorDetail :: Maybe ErrorCode
sqsErrorDetail = Maybe ErrorCode
detail
                                      , sqsErrorMetadata :: Maybe SqsMetadata
sqsErrorMetadata = Maybe SqsMetadata
forall a. Maybe a
Nothing
                                      }

data QueueName = QueueName{
  QueueName -> ErrorCode
qName :: T.Text,
  QueueName -> ErrorCode
qAccountNumber :: T.Text
} deriving(Int -> QueueName -> ShowS
[QueueName] -> ShowS
QueueName -> String
(Int -> QueueName -> ShowS)
-> (QueueName -> String)
-> ([QueueName] -> ShowS)
-> Show QueueName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueueName] -> ShowS
$cshowList :: [QueueName] -> ShowS
show :: QueueName -> String
$cshow :: QueueName -> String
showsPrec :: Int -> QueueName -> ShowS
$cshowsPrec :: Int -> QueueName -> ShowS
Show, ReadPrec [QueueName]
ReadPrec QueueName
Int -> ReadS QueueName
ReadS [QueueName]
(Int -> ReadS QueueName)
-> ReadS [QueueName]
-> ReadPrec QueueName
-> ReadPrec [QueueName]
-> Read QueueName
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueueName]
$creadListPrec :: ReadPrec [QueueName]
readPrec :: ReadPrec QueueName
$creadPrec :: ReadPrec QueueName
readList :: ReadS [QueueName]
$creadList :: ReadS [QueueName]
readsPrec :: Int -> ReadS QueueName
$creadsPrec :: Int -> ReadS QueueName
Read, QueueName -> QueueName -> Bool
(QueueName -> QueueName -> Bool)
-> (QueueName -> QueueName -> Bool) -> Eq QueueName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueueName -> QueueName -> Bool
$c/= :: QueueName -> QueueName -> Bool
== :: QueueName -> QueueName -> Bool
$c== :: QueueName -> QueueName -> Bool
Eq, Eq QueueName
Eq QueueName
-> (QueueName -> QueueName -> Ordering)
-> (QueueName -> QueueName -> Bool)
-> (QueueName -> QueueName -> Bool)
-> (QueueName -> QueueName -> Bool)
-> (QueueName -> QueueName -> Bool)
-> (QueueName -> QueueName -> QueueName)
-> (QueueName -> QueueName -> QueueName)
-> Ord QueueName
QueueName -> QueueName -> Bool
QueueName -> QueueName -> Ordering
QueueName -> QueueName -> QueueName
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: QueueName -> QueueName -> QueueName
$cmin :: QueueName -> QueueName -> QueueName
max :: QueueName -> QueueName -> QueueName
$cmax :: QueueName -> QueueName -> QueueName
>= :: QueueName -> QueueName -> Bool
$c>= :: QueueName -> QueueName -> Bool
> :: QueueName -> QueueName -> Bool
$c> :: QueueName -> QueueName -> Bool
<= :: QueueName -> QueueName -> Bool
$c<= :: QueueName -> QueueName -> Bool
< :: QueueName -> QueueName -> Bool
$c< :: QueueName -> QueueName -> Bool
compare :: QueueName -> QueueName -> Ordering
$ccompare :: QueueName -> QueueName -> Ordering
$cp1Ord :: Eq QueueName
Ord)

printQueueName :: QueueName -> T.Text
printQueueName :: QueueName -> ErrorCode
printQueueName QueueName
queue = [ErrorCode] -> ErrorCode
T.concat [ErrorCode
"/", (QueueName -> ErrorCode
qAccountNumber QueueName
queue), ErrorCode
"/", (QueueName -> ErrorCode
qName QueueName
queue), ErrorCode
"/"]

data QueueAttribute
    = QueueAll
    | ApproximateNumberOfMessages
    | ApproximateNumberOfMessagesNotVisible
    | VisibilityTimeout
    | CreatedTimestamp
    | LastModifiedTimestamp
    | Policy
    | MaximumMessageSize
    | MessageRetentionPeriod
    | QueueArn
    deriving(Int -> QueueAttribute -> ShowS
[QueueAttribute] -> ShowS
QueueAttribute -> String
(Int -> QueueAttribute -> ShowS)
-> (QueueAttribute -> String)
-> ([QueueAttribute] -> ShowS)
-> Show QueueAttribute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueueAttribute] -> ShowS
$cshowList :: [QueueAttribute] -> ShowS
show :: QueueAttribute -> String
$cshow :: QueueAttribute -> String
showsPrec :: Int -> QueueAttribute -> ShowS
$cshowsPrec :: Int -> QueueAttribute -> ShowS
Show, Int -> QueueAttribute
QueueAttribute -> Int
QueueAttribute -> [QueueAttribute]
QueueAttribute -> QueueAttribute
QueueAttribute -> QueueAttribute -> [QueueAttribute]
QueueAttribute
-> QueueAttribute -> QueueAttribute -> [QueueAttribute]
(QueueAttribute -> QueueAttribute)
-> (QueueAttribute -> QueueAttribute)
-> (Int -> QueueAttribute)
-> (QueueAttribute -> Int)
-> (QueueAttribute -> [QueueAttribute])
-> (QueueAttribute -> QueueAttribute -> [QueueAttribute])
-> (QueueAttribute -> QueueAttribute -> [QueueAttribute])
-> (QueueAttribute
    -> QueueAttribute -> QueueAttribute -> [QueueAttribute])
-> Enum QueueAttribute
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: QueueAttribute
-> QueueAttribute -> QueueAttribute -> [QueueAttribute]
$cenumFromThenTo :: QueueAttribute
-> QueueAttribute -> QueueAttribute -> [QueueAttribute]
enumFromTo :: QueueAttribute -> QueueAttribute -> [QueueAttribute]
$cenumFromTo :: QueueAttribute -> QueueAttribute -> [QueueAttribute]
enumFromThen :: QueueAttribute -> QueueAttribute -> [QueueAttribute]
$cenumFromThen :: QueueAttribute -> QueueAttribute -> [QueueAttribute]
enumFrom :: QueueAttribute -> [QueueAttribute]
$cenumFrom :: QueueAttribute -> [QueueAttribute]
fromEnum :: QueueAttribute -> Int
$cfromEnum :: QueueAttribute -> Int
toEnum :: Int -> QueueAttribute
$ctoEnum :: Int -> QueueAttribute
pred :: QueueAttribute -> QueueAttribute
$cpred :: QueueAttribute -> QueueAttribute
succ :: QueueAttribute -> QueueAttribute
$csucc :: QueueAttribute -> QueueAttribute
Enum, QueueAttribute -> QueueAttribute -> Bool
(QueueAttribute -> QueueAttribute -> Bool)
-> (QueueAttribute -> QueueAttribute -> Bool) -> Eq QueueAttribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueueAttribute -> QueueAttribute -> Bool
$c/= :: QueueAttribute -> QueueAttribute -> Bool
== :: QueueAttribute -> QueueAttribute -> Bool
$c== :: QueueAttribute -> QueueAttribute -> Bool
Eq)

data MessageAttribute
    = MessageAll
    -- ^ all values
    | SenderId
    -- ^ the AWS account number (or the IP address, if anonymous access is
    -- allowed) of the sender
    | SentTimestamp
    -- ^ the time when the message was sent (epoch time in milliseconds)
    | ApproximateReceiveCount
    -- ^ the number of times a message has been received but not deleted
    | ApproximateFirstReceiveTimestamp
    -- ^ the time when the message was first received (epoch time in
    -- milliseconds)
    deriving(Int -> MessageAttribute -> ShowS
[MessageAttribute] -> ShowS
MessageAttribute -> String
(Int -> MessageAttribute -> ShowS)
-> (MessageAttribute -> String)
-> ([MessageAttribute] -> ShowS)
-> Show MessageAttribute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MessageAttribute] -> ShowS
$cshowList :: [MessageAttribute] -> ShowS
show :: MessageAttribute -> String
$cshow :: MessageAttribute -> String
showsPrec :: Int -> MessageAttribute -> ShowS
$cshowsPrec :: Int -> MessageAttribute -> ShowS
Show,ReadPrec [MessageAttribute]
ReadPrec MessageAttribute
Int -> ReadS MessageAttribute
ReadS [MessageAttribute]
(Int -> ReadS MessageAttribute)
-> ReadS [MessageAttribute]
-> ReadPrec MessageAttribute
-> ReadPrec [MessageAttribute]
-> Read MessageAttribute
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MessageAttribute]
$creadListPrec :: ReadPrec [MessageAttribute]
readPrec :: ReadPrec MessageAttribute
$creadPrec :: ReadPrec MessageAttribute
readList :: ReadS [MessageAttribute]
$creadList :: ReadS [MessageAttribute]
readsPrec :: Int -> ReadS MessageAttribute
$creadsPrec :: Int -> ReadS MessageAttribute
Read,MessageAttribute -> MessageAttribute -> Bool
(MessageAttribute -> MessageAttribute -> Bool)
-> (MessageAttribute -> MessageAttribute -> Bool)
-> Eq MessageAttribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MessageAttribute -> MessageAttribute -> Bool
$c/= :: MessageAttribute -> MessageAttribute -> Bool
== :: MessageAttribute -> MessageAttribute -> Bool
$c== :: MessageAttribute -> MessageAttribute -> Bool
Eq,Eq MessageAttribute
Eq MessageAttribute
-> (MessageAttribute -> MessageAttribute -> Ordering)
-> (MessageAttribute -> MessageAttribute -> Bool)
-> (MessageAttribute -> MessageAttribute -> Bool)
-> (MessageAttribute -> MessageAttribute -> Bool)
-> (MessageAttribute -> MessageAttribute -> Bool)
-> (MessageAttribute -> MessageAttribute -> MessageAttribute)
-> (MessageAttribute -> MessageAttribute -> MessageAttribute)
-> Ord MessageAttribute
MessageAttribute -> MessageAttribute -> Bool
MessageAttribute -> MessageAttribute -> Ordering
MessageAttribute -> MessageAttribute -> MessageAttribute
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MessageAttribute -> MessageAttribute -> MessageAttribute
$cmin :: MessageAttribute -> MessageAttribute -> MessageAttribute
max :: MessageAttribute -> MessageAttribute -> MessageAttribute
$cmax :: MessageAttribute -> MessageAttribute -> MessageAttribute
>= :: MessageAttribute -> MessageAttribute -> Bool
$c>= :: MessageAttribute -> MessageAttribute -> Bool
> :: MessageAttribute -> MessageAttribute -> Bool
$c> :: MessageAttribute -> MessageAttribute -> Bool
<= :: MessageAttribute -> MessageAttribute -> Bool
$c<= :: MessageAttribute -> MessageAttribute -> Bool
< :: MessageAttribute -> MessageAttribute -> Bool
$c< :: MessageAttribute -> MessageAttribute -> Bool
compare :: MessageAttribute -> MessageAttribute -> Ordering
$ccompare :: MessageAttribute -> MessageAttribute -> Ordering
$cp1Ord :: Eq MessageAttribute
Ord,Int -> MessageAttribute
MessageAttribute -> Int
MessageAttribute -> [MessageAttribute]
MessageAttribute -> MessageAttribute
MessageAttribute -> MessageAttribute -> [MessageAttribute]
MessageAttribute
-> MessageAttribute -> MessageAttribute -> [MessageAttribute]
(MessageAttribute -> MessageAttribute)
-> (MessageAttribute -> MessageAttribute)
-> (Int -> MessageAttribute)
-> (MessageAttribute -> Int)
-> (MessageAttribute -> [MessageAttribute])
-> (MessageAttribute -> MessageAttribute -> [MessageAttribute])
-> (MessageAttribute -> MessageAttribute -> [MessageAttribute])
-> (MessageAttribute
    -> MessageAttribute -> MessageAttribute -> [MessageAttribute])
-> Enum MessageAttribute
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: MessageAttribute
-> MessageAttribute -> MessageAttribute -> [MessageAttribute]
$cenumFromThenTo :: MessageAttribute
-> MessageAttribute -> MessageAttribute -> [MessageAttribute]
enumFromTo :: MessageAttribute -> MessageAttribute -> [MessageAttribute]
$cenumFromTo :: MessageAttribute -> MessageAttribute -> [MessageAttribute]
enumFromThen :: MessageAttribute -> MessageAttribute -> [MessageAttribute]
$cenumFromThen :: MessageAttribute -> MessageAttribute -> [MessageAttribute]
enumFrom :: MessageAttribute -> [MessageAttribute]
$cenumFrom :: MessageAttribute -> [MessageAttribute]
fromEnum :: MessageAttribute -> Int
$cfromEnum :: MessageAttribute -> Int
toEnum :: Int -> MessageAttribute
$ctoEnum :: Int -> MessageAttribute
pred :: MessageAttribute -> MessageAttribute
$cpred :: MessageAttribute -> MessageAttribute
succ :: MessageAttribute -> MessageAttribute
$csucc :: MessageAttribute -> MessageAttribute
Enum,MessageAttribute
MessageAttribute -> MessageAttribute -> Bounded MessageAttribute
forall a. a -> a -> Bounded a
maxBound :: MessageAttribute
$cmaxBound :: MessageAttribute
minBound :: MessageAttribute
$cminBound :: MessageAttribute
Bounded)

data SqsPermission
    = PermissionAll
    | PermissionSendMessage
    | PermissionReceiveMessage
    | PermissionDeleteMessage
    | PermissionChangeMessageVisibility
    | PermissionGetQueueAttributes
    deriving (Int -> SqsPermission -> ShowS
[SqsPermission] -> ShowS
SqsPermission -> String
(Int -> SqsPermission -> ShowS)
-> (SqsPermission -> String)
-> ([SqsPermission] -> ShowS)
-> Show SqsPermission
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqsPermission] -> ShowS
$cshowList :: [SqsPermission] -> ShowS
show :: SqsPermission -> String
$cshow :: SqsPermission -> String
showsPrec :: Int -> SqsPermission -> ShowS
$cshowsPrec :: Int -> SqsPermission -> ShowS
Show, Int -> SqsPermission
SqsPermission -> Int
SqsPermission -> [SqsPermission]
SqsPermission -> SqsPermission
SqsPermission -> SqsPermission -> [SqsPermission]
SqsPermission -> SqsPermission -> SqsPermission -> [SqsPermission]
(SqsPermission -> SqsPermission)
-> (SqsPermission -> SqsPermission)
-> (Int -> SqsPermission)
-> (SqsPermission -> Int)
-> (SqsPermission -> [SqsPermission])
-> (SqsPermission -> SqsPermission -> [SqsPermission])
-> (SqsPermission -> SqsPermission -> [SqsPermission])
-> (SqsPermission
    -> SqsPermission -> SqsPermission -> [SqsPermission])
-> Enum SqsPermission
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: SqsPermission -> SqsPermission -> SqsPermission -> [SqsPermission]
$cenumFromThenTo :: SqsPermission -> SqsPermission -> SqsPermission -> [SqsPermission]
enumFromTo :: SqsPermission -> SqsPermission -> [SqsPermission]
$cenumFromTo :: SqsPermission -> SqsPermission -> [SqsPermission]
enumFromThen :: SqsPermission -> SqsPermission -> [SqsPermission]
$cenumFromThen :: SqsPermission -> SqsPermission -> [SqsPermission]
enumFrom :: SqsPermission -> [SqsPermission]
$cenumFrom :: SqsPermission -> [SqsPermission]
fromEnum :: SqsPermission -> Int
$cfromEnum :: SqsPermission -> Int
toEnum :: Int -> SqsPermission
$ctoEnum :: Int -> SqsPermission
pred :: SqsPermission -> SqsPermission
$cpred :: SqsPermission -> SqsPermission
succ :: SqsPermission -> SqsPermission
$csucc :: SqsPermission -> SqsPermission
Enum, SqsPermission -> SqsPermission -> Bool
(SqsPermission -> SqsPermission -> Bool)
-> (SqsPermission -> SqsPermission -> Bool) -> Eq SqsPermission
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SqsPermission -> SqsPermission -> Bool
$c/= :: SqsPermission -> SqsPermission -> Bool
== :: SqsPermission -> SqsPermission -> Bool
$c== :: SqsPermission -> SqsPermission -> Bool
Eq)

parseQueueAttribute :: MonadThrow m  => T.Text -> m QueueAttribute
parseQueueAttribute :: ErrorCode -> m QueueAttribute
parseQueueAttribute ErrorCode
"ApproximateNumberOfMessages" = QueueAttribute -> m QueueAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return QueueAttribute
ApproximateNumberOfMessages 
parseQueueAttribute ErrorCode
"ApproximateNumberOfMessagesNotVisible" = QueueAttribute -> m QueueAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return QueueAttribute
ApproximateNumberOfMessagesNotVisible
parseQueueAttribute ErrorCode
"VisibilityTimeout" = QueueAttribute -> m QueueAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return QueueAttribute
VisibilityTimeout
parseQueueAttribute ErrorCode
"CreatedTimestamp" = QueueAttribute -> m QueueAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return QueueAttribute
CreatedTimestamp
parseQueueAttribute ErrorCode
"LastModifiedTimestamp" = QueueAttribute -> m QueueAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return QueueAttribute
LastModifiedTimestamp
parseQueueAttribute ErrorCode
"Policy" = QueueAttribute -> m QueueAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return QueueAttribute
Policy
parseQueueAttribute ErrorCode
"MaximumMessageSize" = QueueAttribute -> m QueueAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return QueueAttribute
MaximumMessageSize
parseQueueAttribute ErrorCode
"MessageRetentionPeriod" = QueueAttribute -> m QueueAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return QueueAttribute
MessageRetentionPeriod
parseQueueAttribute ErrorCode
"QueueArn" = QueueAttribute -> m QueueAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return QueueAttribute
QueueArn
parseQueueAttribute ErrorCode
x = XmlException -> m QueueAttribute
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (XmlException -> m QueueAttribute)
-> XmlException -> m QueueAttribute
forall a b. (a -> b) -> a -> b
$ String -> XmlException
XmlException ( String
"Invalid Attribute Name. " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ErrorCode -> String
forall a. Show a => a -> String
show ErrorCode
x)

printQueueAttribute :: QueueAttribute -> T.Text
printQueueAttribute :: QueueAttribute -> ErrorCode
printQueueAttribute QueueAttribute
QueueAll = ErrorCode
"All"
printQueueAttribute QueueAttribute
ApproximateNumberOfMessages = ErrorCode
"ApproximateNumberOfMessages"
printQueueAttribute QueueAttribute
ApproximateNumberOfMessagesNotVisible = ErrorCode
"ApproximateNumberOfMessagesNotVisible"
printQueueAttribute QueueAttribute
VisibilityTimeout = ErrorCode
"VisibilityTimeout"
printQueueAttribute QueueAttribute
CreatedTimestamp = ErrorCode
"CreatedTimestamp"
printQueueAttribute QueueAttribute
LastModifiedTimestamp = ErrorCode
"LastModifiedTimestamp"
printQueueAttribute QueueAttribute
Policy = ErrorCode
"Policy"
printQueueAttribute QueueAttribute
MaximumMessageSize = ErrorCode
"MaximumMessageSize"
printQueueAttribute QueueAttribute
MessageRetentionPeriod = ErrorCode
"MessageRetentionPeriod"
printQueueAttribute QueueAttribute
QueueArn = ErrorCode
"QueueArn"

parseMessageAttribute :: MonadThrow m  =>  T.Text -> m MessageAttribute
parseMessageAttribute :: ErrorCode -> m MessageAttribute
parseMessageAttribute ErrorCode
"SenderId" = MessageAttribute -> m MessageAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return MessageAttribute
SenderId
parseMessageAttribute ErrorCode
"SentTimestamp" = MessageAttribute -> m MessageAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return MessageAttribute
SentTimestamp
parseMessageAttribute ErrorCode
"ApproximateReceiveCount" = MessageAttribute -> m MessageAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return MessageAttribute
ApproximateReceiveCount
parseMessageAttribute ErrorCode
"ApproximateFirstReceiveTimestamp" = MessageAttribute -> m MessageAttribute
forall (m :: * -> *) a. Monad m => a -> m a
return MessageAttribute
ApproximateFirstReceiveTimestamp
parseMessageAttribute ErrorCode
x = XmlException -> m MessageAttribute
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (XmlException -> m MessageAttribute)
-> XmlException -> m MessageAttribute
forall a b. (a -> b) -> a -> b
$ String -> XmlException
XmlException ( String
"Invalid Attribute Name. " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ErrorCode -> String
forall a. Show a => a -> String
show ErrorCode
x)

printMessageAttribute :: MessageAttribute -> T.Text
printMessageAttribute :: MessageAttribute -> ErrorCode
printMessageAttribute MessageAttribute
MessageAll = ErrorCode
"All"
printMessageAttribute MessageAttribute
SenderId = ErrorCode
"SenderId"
printMessageAttribute MessageAttribute
SentTimestamp = ErrorCode
"SentTimestamp"
printMessageAttribute MessageAttribute
ApproximateReceiveCount = ErrorCode
"ApproximateReceiveCount"
printMessageAttribute MessageAttribute
ApproximateFirstReceiveTimestamp = ErrorCode
"ApproximateFirstReceiveTimestamp"

printPermission :: SqsPermission -> T.Text
printPermission :: SqsPermission -> ErrorCode
printPermission SqsPermission
PermissionAll = ErrorCode
"*"
printPermission SqsPermission
PermissionSendMessage = ErrorCode
"SendMessage"
printPermission SqsPermission
PermissionReceiveMessage = ErrorCode
"ReceiveMessage"
printPermission SqsPermission
PermissionDeleteMessage = ErrorCode
"DeleteMessage"
printPermission SqsPermission
PermissionChangeMessageVisibility = ErrorCode
"ChangeMessageVisibility"
printPermission SqsPermission
PermissionGetQueueAttributes = ErrorCode
"GetQueueAttributes"

newtype ReceiptHandle = ReceiptHandle T.Text deriving(Int -> ReceiptHandle -> ShowS
[ReceiptHandle] -> ShowS
ReceiptHandle -> String
(Int -> ReceiptHandle -> ShowS)
-> (ReceiptHandle -> String)
-> ([ReceiptHandle] -> ShowS)
-> Show ReceiptHandle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReceiptHandle] -> ShowS
$cshowList :: [ReceiptHandle] -> ShowS
show :: ReceiptHandle -> String
$cshow :: ReceiptHandle -> String
showsPrec :: Int -> ReceiptHandle -> ShowS
$cshowsPrec :: Int -> ReceiptHandle -> ShowS
Show, ReadPrec [ReceiptHandle]
ReadPrec ReceiptHandle
Int -> ReadS ReceiptHandle
ReadS [ReceiptHandle]
(Int -> ReadS ReceiptHandle)
-> ReadS [ReceiptHandle]
-> ReadPrec ReceiptHandle
-> ReadPrec [ReceiptHandle]
-> Read ReceiptHandle
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReceiptHandle]
$creadListPrec :: ReadPrec [ReceiptHandle]
readPrec :: ReadPrec ReceiptHandle
$creadPrec :: ReadPrec ReceiptHandle
readList :: ReadS [ReceiptHandle]
$creadList :: ReadS [ReceiptHandle]
readsPrec :: Int -> ReadS ReceiptHandle
$creadsPrec :: Int -> ReadS ReceiptHandle
Read, ReceiptHandle -> ReceiptHandle -> Bool
(ReceiptHandle -> ReceiptHandle -> Bool)
-> (ReceiptHandle -> ReceiptHandle -> Bool) -> Eq ReceiptHandle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReceiptHandle -> ReceiptHandle -> Bool
$c/= :: ReceiptHandle -> ReceiptHandle -> Bool
== :: ReceiptHandle -> ReceiptHandle -> Bool
$c== :: ReceiptHandle -> ReceiptHandle -> Bool
Eq, Eq ReceiptHandle
Eq ReceiptHandle
-> (ReceiptHandle -> ReceiptHandle -> Ordering)
-> (ReceiptHandle -> ReceiptHandle -> Bool)
-> (ReceiptHandle -> ReceiptHandle -> Bool)
-> (ReceiptHandle -> ReceiptHandle -> Bool)
-> (ReceiptHandle -> ReceiptHandle -> Bool)
-> (ReceiptHandle -> ReceiptHandle -> ReceiptHandle)
-> (ReceiptHandle -> ReceiptHandle -> ReceiptHandle)
-> Ord ReceiptHandle
ReceiptHandle -> ReceiptHandle -> Bool
ReceiptHandle -> ReceiptHandle -> Ordering
ReceiptHandle -> ReceiptHandle -> ReceiptHandle
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ReceiptHandle -> ReceiptHandle -> ReceiptHandle
$cmin :: ReceiptHandle -> ReceiptHandle -> ReceiptHandle
max :: ReceiptHandle -> ReceiptHandle -> ReceiptHandle
$cmax :: ReceiptHandle -> ReceiptHandle -> ReceiptHandle
>= :: ReceiptHandle -> ReceiptHandle -> Bool
$c>= :: ReceiptHandle -> ReceiptHandle -> Bool
> :: ReceiptHandle -> ReceiptHandle -> Bool
$c> :: ReceiptHandle -> ReceiptHandle -> Bool
<= :: ReceiptHandle -> ReceiptHandle -> Bool
$c<= :: ReceiptHandle -> ReceiptHandle -> Bool
< :: ReceiptHandle -> ReceiptHandle -> Bool
$c< :: ReceiptHandle -> ReceiptHandle -> Bool
compare :: ReceiptHandle -> ReceiptHandle -> Ordering
$ccompare :: ReceiptHandle -> ReceiptHandle -> Ordering
$cp1Ord :: Eq ReceiptHandle
Ord)
newtype MessageId = MessageId T.Text deriving(Int -> MessageId -> ShowS
[MessageId] -> ShowS
MessageId -> String
(Int -> MessageId -> ShowS)
-> (MessageId -> String)
-> ([MessageId] -> ShowS)
-> Show MessageId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MessageId] -> ShowS
$cshowList :: [MessageId] -> ShowS
show :: MessageId -> String
$cshow :: MessageId -> String
showsPrec :: Int -> MessageId -> ShowS
$cshowsPrec :: Int -> MessageId -> ShowS
Show, ReadPrec [MessageId]
ReadPrec MessageId
Int -> ReadS MessageId
ReadS [MessageId]
(Int -> ReadS MessageId)
-> ReadS [MessageId]
-> ReadPrec MessageId
-> ReadPrec [MessageId]
-> Read MessageId
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MessageId]
$creadListPrec :: ReadPrec [MessageId]
readPrec :: ReadPrec MessageId
$creadPrec :: ReadPrec MessageId
readList :: ReadS [MessageId]
$creadList :: ReadS [MessageId]
readsPrec :: Int -> ReadS MessageId
$creadsPrec :: Int -> ReadS MessageId
Read, MessageId -> MessageId -> Bool
(MessageId -> MessageId -> Bool)
-> (MessageId -> MessageId -> Bool) -> Eq MessageId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MessageId -> MessageId -> Bool
$c/= :: MessageId -> MessageId -> Bool
== :: MessageId -> MessageId -> Bool
$c== :: MessageId -> MessageId -> Bool
Eq, Eq MessageId
Eq MessageId
-> (MessageId -> MessageId -> Ordering)
-> (MessageId -> MessageId -> Bool)
-> (MessageId -> MessageId -> Bool)
-> (MessageId -> MessageId -> Bool)
-> (MessageId -> MessageId -> Bool)
-> (MessageId -> MessageId -> MessageId)
-> (MessageId -> MessageId -> MessageId)
-> Ord MessageId
MessageId -> MessageId -> Bool
MessageId -> MessageId -> Ordering
MessageId -> MessageId -> MessageId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MessageId -> MessageId -> MessageId
$cmin :: MessageId -> MessageId -> MessageId
max :: MessageId -> MessageId -> MessageId
$cmax :: MessageId -> MessageId -> MessageId
>= :: MessageId -> MessageId -> Bool
$c>= :: MessageId -> MessageId -> Bool
> :: MessageId -> MessageId -> Bool
$c> :: MessageId -> MessageId -> Bool
<= :: MessageId -> MessageId -> Bool
$c<= :: MessageId -> MessageId -> Bool
< :: MessageId -> MessageId -> Bool
$c< :: MessageId -> MessageId -> Bool
compare :: MessageId -> MessageId -> Ordering
$ccompare :: MessageId -> MessageId -> Ordering
$cp1Ord :: Eq MessageId
Ord)

printReceiptHandle :: ReceiptHandle -> T.Text
printReceiptHandle :: ReceiptHandle -> ErrorCode
printReceiptHandle (ReceiptHandle ErrorCode
handle) = ErrorCode
handle