{-# LANGUAGE AllowAmbiguousTypes #-}
module Amazonka.Env.Hooks
( Hook,
Hook_,
Hooks (..),
Finality (..),
requestHook,
waitHook,
configuredRequestHook,
signedRequestHook,
clientRequestHook,
clientResponseHook,
rawResponseBodyHook,
requestRetryHook,
awaitRetryHook,
responseHook,
errorHook,
noHook,
noHook_,
addHook,
addHook_,
addAWSRequestHook,
addAWSRequestHook_,
addHookFor,
addHookFor_,
removeHooksFor,
removeHooksFor_,
silenceError,
addLoggingHooks,
noHooks,
)
where
import {-# SOURCE #-} Amazonka.Env (Env' (..))
import Amazonka.Logger (build, logDebug, logError, logTrace)
import Amazonka.Prelude hiding (error)
import Amazonka.Types
( AWSRequest,
AWSResponse,
ClientRequest,
ClientResponse,
Error,
Request,
Signed (..),
)
import Amazonka.Waiter (Accept, Wait (..))
import Control.Lens (Getting, has)
import qualified Control.Retry as Retry
import Data.List (intersperse)
import Data.Monoid (Any)
import Data.Typeable (Typeable, eqT, (:~:) (..))
type Hook a = forall withAuth. Env' withAuth -> a -> IO a
type Hook_ a = forall withAuth. Env' withAuth -> a -> IO ()
data Finality = NotFinal | Final
deriving stock (Finality
Finality -> Finality -> Bounded Finality
forall a. a -> a -> Bounded a
$cminBound :: Finality
minBound :: Finality
$cmaxBound :: Finality
maxBound :: Finality
Bounded, Int -> Finality
Finality -> Int
Finality -> [Finality]
Finality -> Finality
Finality -> Finality -> [Finality]
Finality -> Finality -> Finality -> [Finality]
(Finality -> Finality)
-> (Finality -> Finality)
-> (Int -> Finality)
-> (Finality -> Int)
-> (Finality -> [Finality])
-> (Finality -> Finality -> [Finality])
-> (Finality -> Finality -> [Finality])
-> (Finality -> Finality -> Finality -> [Finality])
-> Enum Finality
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Finality -> Finality
succ :: Finality -> Finality
$cpred :: Finality -> Finality
pred :: Finality -> Finality
$ctoEnum :: Int -> Finality
toEnum :: Int -> Finality
$cfromEnum :: Finality -> Int
fromEnum :: Finality -> Int
$cenumFrom :: Finality -> [Finality]
enumFrom :: Finality -> [Finality]
$cenumFromThen :: Finality -> Finality -> [Finality]
enumFromThen :: Finality -> Finality -> [Finality]
$cenumFromTo :: Finality -> Finality -> [Finality]
enumFromTo :: Finality -> Finality -> [Finality]
$cenumFromThenTo :: Finality -> Finality -> Finality -> [Finality]
enumFromThenTo :: Finality -> Finality -> Finality -> [Finality]
Enum, Finality -> Finality -> Bool
(Finality -> Finality -> Bool)
-> (Finality -> Finality -> Bool) -> Eq Finality
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Finality -> Finality -> Bool
== :: Finality -> Finality -> Bool
$c/= :: Finality -> Finality -> Bool
/= :: Finality -> Finality -> Bool
Eq, Eq Finality
Eq Finality =>
(Finality -> Finality -> Ordering)
-> (Finality -> Finality -> Bool)
-> (Finality -> Finality -> Bool)
-> (Finality -> Finality -> Bool)
-> (Finality -> Finality -> Bool)
-> (Finality -> Finality -> Finality)
-> (Finality -> Finality -> Finality)
-> Ord Finality
Finality -> Finality -> Bool
Finality -> Finality -> Ordering
Finality -> Finality -> Finality
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
$ccompare :: Finality -> Finality -> Ordering
compare :: Finality -> Finality -> Ordering
$c< :: Finality -> Finality -> Bool
< :: Finality -> Finality -> Bool
$c<= :: Finality -> Finality -> Bool
<= :: Finality -> Finality -> Bool
$c> :: Finality -> Finality -> Bool
> :: Finality -> Finality -> Bool
$c>= :: Finality -> Finality -> Bool
>= :: Finality -> Finality -> Bool
$cmax :: Finality -> Finality -> Finality
max :: Finality -> Finality -> Finality
$cmin :: Finality -> Finality -> Finality
min :: Finality -> Finality -> Finality
Ord, Int -> Finality -> ShowS
[Finality] -> ShowS
Finality -> [Char]
(Int -> Finality -> ShowS)
-> (Finality -> [Char]) -> ([Finality] -> ShowS) -> Show Finality
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Finality -> ShowS
showsPrec :: Int -> Finality -> ShowS
$cshow :: Finality -> [Char]
show :: Finality -> [Char]
$cshowList :: [Finality] -> ShowS
showList :: [Finality] -> ShowS
Show, (forall x. Finality -> Rep Finality x)
-> (forall x. Rep Finality x -> Finality) -> Generic Finality
forall x. Rep Finality x -> Finality
forall x. Finality -> Rep Finality x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Finality -> Rep Finality x
from :: forall x. Finality -> Rep Finality x
$cto :: forall x. Rep Finality x -> Finality
to :: forall x. Rep Finality x -> Finality
Generic)
data Hooks = Hooks
{
Hooks -> forall a. (AWSRequest a, Typeable a) => Hook a
request :: forall a. (AWSRequest a, Typeable a) => Hook a,
Hooks -> forall a. (AWSRequest a, Typeable a) => Hook (Request a)
configuredRequest :: forall a. (AWSRequest a, Typeable a) => Hook (Request a),
Hooks -> forall a. (AWSRequest a, Typeable a) => Hook (Wait a)
wait :: forall a. (AWSRequest a, Typeable a) => Hook (Wait a),
Hooks -> forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a)
signedRequest :: forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a),
Hooks -> Hook ClientRequest
clientRequest :: Hook ClientRequest,
Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
clientResponse ::
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ()),
Hooks -> Hook ByteStringLazy
rawResponseBody :: Hook ByteStringLazy,
Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
requestRetry ::
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, Retry.RetryStatus),
Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
awaitRetry ::
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, Retry.RetryStatus),
Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse (AWSResponse a))
response ::
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse (AWSResponse a)),
Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
error ::
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
}
{-# INLINE requestHook #-}
requestHook ::
(forall a. (AWSRequest a, Typeable a) => Hook a -> Hook a) ->
Hooks ->
Hooks
requestHook :: (forall a. (AWSRequest a, Typeable a) => Hook a -> Hook a)
-> Hooks -> Hooks
requestHook forall a. (AWSRequest a, Typeable a) => Hook a -> Hook a
f hooks :: Hooks
hooks@Hooks {forall a. (AWSRequest a, Typeable a) => Hook a
$sel:request:Hooks :: Hooks -> forall a. (AWSRequest a, Typeable a) => Hook a
request :: forall a. (AWSRequest a, Typeable a) => Hook a
request} =
Hooks
hooks {request = f request}
{-# INLINE waitHook #-}
waitHook ::
(forall a. (AWSRequest a, Typeable a) => Hook (Wait a) -> Hook (Wait a)) ->
Hooks ->
Hooks
waitHook :: (forall a.
(AWSRequest a, Typeable a) =>
Hook (Wait a) -> Hook (Wait a))
-> Hooks -> Hooks
waitHook forall a.
(AWSRequest a, Typeable a) =>
Hook (Wait a) -> Hook (Wait a)
f hooks :: Hooks
hooks@Hooks {forall a. (AWSRequest a, Typeable a) => Hook (Wait a)
$sel:wait:Hooks :: Hooks -> forall a. (AWSRequest a, Typeable a) => Hook (Wait a)
wait :: forall a. (AWSRequest a, Typeable a) => Hook (Wait a)
wait} =
Hooks
hooks {wait = f wait}
{-# INLINE configuredRequestHook #-}
configuredRequestHook ::
( forall a.
(AWSRequest a, Typeable a) =>
Hook (Request a) ->
Hook (Request a)
) ->
Hooks ->
Hooks
configuredRequestHook :: (forall a.
(AWSRequest a, Typeable a) =>
Hook (Request a) -> Hook (Request a))
-> Hooks -> Hooks
configuredRequestHook forall a.
(AWSRequest a, Typeable a) =>
Hook (Request a) -> Hook (Request a)
f hooks :: Hooks
hooks@Hooks {forall a. (AWSRequest a, Typeable a) => Hook (Request a)
$sel:configuredRequest:Hooks :: Hooks -> forall a. (AWSRequest a, Typeable a) => Hook (Request a)
configuredRequest :: forall a. (AWSRequest a, Typeable a) => Hook (Request a)
configuredRequest} =
Hooks
hooks {configuredRequest = f configuredRequest}
{-# INLINE signedRequestHook #-}
signedRequestHook ::
( forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Signed a) ->
Hook_ (Signed a)
) ->
Hooks ->
Hooks
signedRequestHook :: (forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Signed a) -> Hook_ (Signed a))
-> Hooks -> Hooks
signedRequestHook forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Signed a) -> Hook_ (Signed a)
f hooks :: Hooks
hooks@Hooks {forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a)
$sel:signedRequest:Hooks :: Hooks -> forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a)
signedRequest :: forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a)
signedRequest} =
Hooks
hooks {signedRequest = f signedRequest}
{-# INLINE clientRequestHook #-}
clientRequestHook ::
(Hook ClientRequest -> Hook ClientRequest) ->
Hooks ->
Hooks
clientRequestHook :: (Hook ClientRequest -> Hook ClientRequest) -> Hooks -> Hooks
clientRequestHook Hook ClientRequest -> Hook ClientRequest
f hooks :: Hooks
hooks@Hooks {Hook ClientRequest
$sel:clientRequest:Hooks :: Hooks -> Hook ClientRequest
clientRequest :: Hook ClientRequest
clientRequest} =
Hooks
hooks {clientRequest = f clientRequest}
{-# INLINE clientResponseHook #-}
clientResponseHook ::
( forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ()) ->
Hook_ (Request a, ClientResponse ())
) ->
Hooks ->
Hooks
clientResponseHook :: (forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
-> Hook_ (Request a, ClientResponse ()))
-> Hooks -> Hooks
clientResponseHook forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
-> Hook_ (Request a, ClientResponse ())
f hooks :: Hooks
hooks@Hooks {forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
$sel:clientResponse:Hooks :: Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
clientResponse :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
clientResponse} =
Hooks
hooks {clientResponse = f clientResponse}
{-# INLINE rawResponseBodyHook #-}
rawResponseBodyHook ::
(Hook ByteStringLazy -> Hook ByteStringLazy) ->
Hooks ->
Hooks
rawResponseBodyHook :: (Hook ByteStringLazy -> Hook ByteStringLazy) -> Hooks -> Hooks
rawResponseBodyHook Hook ByteStringLazy -> Hook ByteStringLazy
f hooks :: Hooks
hooks@Hooks {Hook ByteStringLazy
$sel:rawResponseBody:Hooks :: Hooks -> Hook ByteStringLazy
rawResponseBody :: Hook ByteStringLazy
rawResponseBody} =
Hooks
hooks {rawResponseBody = f rawResponseBody}
{-# INLINE requestRetryHook #-}
requestRetryHook ::
( forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, Retry.RetryStatus) ->
Hook_ (Request a, Text, Retry.RetryStatus)
) ->
Hooks ->
Hooks
requestRetryHook :: (forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
-> Hook_ (Request a, Text, RetryStatus))
-> Hooks -> Hooks
requestRetryHook forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
-> Hook_ (Request a, Text, RetryStatus)
f hooks :: Hooks
hooks@Hooks {forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
$sel:requestRetry:Hooks :: Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
requestRetry :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
requestRetry} =
Hooks
hooks {requestRetry = f requestRetry}
{-# INLINE awaitRetryHook #-}
awaitRetryHook ::
( forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, Retry.RetryStatus) ->
Hook_ (Request a, Wait a, Accept, Retry.RetryStatus)
) ->
Hooks ->
Hooks
awaitRetryHook :: (forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
-> Hook_ (Request a, Wait a, Accept, RetryStatus))
-> Hooks -> Hooks
awaitRetryHook forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
-> Hook_ (Request a, Wait a, Accept, RetryStatus)
f hooks :: Hooks
hooks@Hooks {forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
$sel:awaitRetry:Hooks :: Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
awaitRetry :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
awaitRetry} =
Hooks
hooks {awaitRetry = f awaitRetry}
{-# INLINE responseHook #-}
responseHook ::
( forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse (AWSResponse a)) ->
Hook_ (Request a, ClientResponse (AWSResponse a))
) ->
Hooks ->
Hooks
responseHook :: (forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse (AWSResponse a))
-> Hook_ (Request a, ClientResponse (AWSResponse a)))
-> Hooks -> Hooks
responseHook forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse (AWSResponse a))
-> Hook_ (Request a, ClientResponse (AWSResponse a))
f hooks :: Hooks
hooks@Hooks {forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse (AWSResponse a))
$sel:response:Hooks :: Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse (AWSResponse a))
response :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse (AWSResponse a))
response} =
Hooks
hooks {response = f response}
{-# INLINE errorHook #-}
errorHook ::
( forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error) ->
Hook_ (Finality, Request a, Error)
) ->
Hooks ->
Hooks
errorHook :: (forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
-> Hook_ (Finality, Request a, Error))
-> Hooks -> Hooks
errorHook forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
-> Hook_ (Finality, Request a, Error)
f hooks :: Hooks
hooks@Hooks {forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
error :: Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
error :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
error} =
Hooks
hooks {error = f error}
noHook :: Hook a -> Hook a
noHook :: forall a. Hook a -> Hook a
noHook Hook a
_ Env' withAuth
_ = a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
noHook_ :: Hook_ a -> Hook_ a
noHook_ :: forall a. Hook_ a -> Hook_ a
noHook_ Hook_ a
_ Env' withAuth
_ a
_ = () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
addHook :: Typeable a => Hook a -> Hook a -> Hook a
addHook :: forall a. Typeable a => Hook a -> Hook a -> Hook a
addHook Hook a
newHook Hook a
oldHook Env' withAuth
env = Env' withAuth -> a -> IO a
Hook a
oldHook Env' withAuth
env (a -> IO a) -> (a -> IO a) -> a -> IO a
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Env' withAuth -> a -> IO a
Hook a
newHook Env' withAuth
env
addHook_ :: Typeable a => Hook_ a -> Hook_ a -> Hook_ a
addHook_ :: forall a. Typeable a => Hook_ a -> Hook_ a -> Hook_ a
addHook_ Hook_ a
newHook Hook_ a
oldHook Env' withAuth
env a
a = Env' withAuth -> a -> IO ()
Hook_ a
oldHook Env' withAuth
env a
a IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Env' withAuth -> a -> IO ()
Hook_ a
newHook Env' withAuth
env a
a
addAWSRequestHook :: (AWSRequest a, Typeable a) => Hook a -> Hook a -> Hook a
addAWSRequestHook :: forall a. (AWSRequest a, Typeable a) => Hook a -> Hook a -> Hook a
addAWSRequestHook = Hook a -> Hook a -> Env' withAuth -> a -> IO a
Hook a -> Hook a -> Hook a
forall a. Typeable a => Hook a -> Hook a -> Hook a
addHook
addAWSRequestHook_ :: (AWSRequest a, Typeable a) => Hook_ a -> Hook_ a -> Hook_ a
addAWSRequestHook_ :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ a -> Hook_ a -> Hook_ a
addAWSRequestHook_ = Hook_ a -> Hook_ a -> Env' withAuth -> a -> IO ()
Hook_ a -> Hook_ a -> Hook_ a
forall a. Typeable a => Hook_ a -> Hook_ a -> Hook_ a
addHook_
addHookFor ::
forall a b. (Typeable a, Typeable b) => Hook a -> Hook b -> Hook b
addHookFor :: forall a b. (Typeable a, Typeable b) => Hook a -> Hook b -> Hook b
addHookFor Hook a
newHook Hook b
oldHook Env' withAuth
env =
Env' withAuth -> b -> IO b
Hook b
oldHook Env' withAuth
env (b -> IO b) -> (b -> IO b) -> b -> IO b
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> case forall {k} (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
forall a b. (Typeable a, Typeable b) => Maybe (a :~: b)
eqT @a @b of
Just a :~: b
Refl -> Env' withAuth -> a -> IO a
Hook a
newHook Env' withAuth
env
Maybe (a :~: b)
Nothing -> b -> IO b
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
addHookFor_ ::
forall a b. (Typeable a, Typeable b) => Hook_ a -> Hook_ b -> Hook_ b
addHookFor_ :: forall a b.
(Typeable a, Typeable b) =>
Hook_ a -> Hook_ b -> Hook_ b
addHookFor_ Hook_ a
newHook Hook_ b
oldHook Env' withAuth
env b
a = do
Env' withAuth -> b -> IO ()
Hook_ b
oldHook Env' withAuth
env b
a
case forall {k} (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
forall a b. (Typeable a, Typeable b) => Maybe (a :~: b)
eqT @a @b of
Just a :~: b
Refl -> Env' withAuth -> a -> IO ()
Hook_ a
newHook Env' withAuth
env a
b
a
Maybe (a :~: b)
Nothing -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
removeHooksFor :: forall a b. (Typeable a, Typeable b) => Hook b -> Hook b
removeHooksFor :: forall a b. (Typeable a, Typeable b) => Hook b -> Hook b
removeHooksFor Hook b
oldHook Env' withAuth
env = case forall {k} (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
forall a b. (Typeable a, Typeable b) => Maybe (a :~: b)
eqT @a @b of
Just a :~: b
Refl -> b -> IO b
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
Maybe (a :~: b)
Nothing -> Env' withAuth -> b -> IO b
Hook b
oldHook Env' withAuth
env
removeHooksFor_ :: forall a b. (Typeable a, Typeable b) => Hook_ b -> Hook_ b
removeHooksFor_ :: forall a b. (Typeable a, Typeable b) => Hook_ b -> Hook_ b
removeHooksFor_ Hook_ b
oldHook Env' withAuth
env b
a = case forall {k} (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
forall a b. (Typeable a, Typeable b) => Maybe (a :~: b)
eqT @a @b of
Just a :~: b
Refl -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Maybe (a :~: b)
Nothing -> Env' withAuth -> b -> IO ()
Hook_ b
oldHook Env' withAuth
env b
a
silenceError ::
Getting Any Error e ->
Hook_ (Finality, Request a, Error) ->
Hook_ (Finality, Request a, Error)
silenceError :: forall e a.
Getting Any Error e
-> Hook_ (Finality, Request a, Error)
-> Hook_ (Finality, Request a, Error)
silenceError Getting Any Error e
g Hook_ (Finality, Request a, Error)
oldHook Env' withAuth
env t :: (Finality, Request a, Error)
t@(Finality
_, Request a
_, Error
err) =
if Getting Any Error e -> Error -> Bool
forall s a. Getting Any s a -> s -> Bool
has Getting Any Error e
g Error
err then () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure () else Env' withAuth -> (Finality, Request a, Error) -> IO ()
Hook_ (Finality, Request a, Error)
oldHook Env' withAuth
env (Finality, Request a, Error)
t
addLoggingHooks :: Hooks -> Hooks
addLoggingHooks :: Hooks -> Hooks
addLoggingHooks
hooks :: Hooks
hooks@Hooks
{ forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a)
$sel:signedRequest:Hooks :: Hooks -> forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a)
signedRequest :: forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a)
signedRequest,
Hook ClientRequest
$sel:clientRequest:Hooks :: Hooks -> Hook ClientRequest
clientRequest :: Hook ClientRequest
clientRequest,
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
$sel:clientResponse:Hooks :: Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
clientResponse :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
clientResponse,
Hook ByteStringLazy
$sel:rawResponseBody:Hooks :: Hooks -> Hook ByteStringLazy
rawResponseBody :: Hook ByteStringLazy
rawResponseBody,
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
$sel:requestRetry:Hooks :: Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
requestRetry :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
requestRetry,
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
$sel:awaitRetry:Hooks :: Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
awaitRetry :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
awaitRetry,
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
error :: Hooks
-> forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
error :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
error
} =
Hooks
hooks
{ signedRequest = \env :: Env' withAuth
env@Env {Logger
logger :: Logger
$sel:logger:Env :: forall (withAuth :: * -> *). Env' withAuth -> Logger
logger} s :: Signed a
s@Signed {Meta
signedMeta :: Meta
$sel:signedMeta:Signed :: forall a. Signed a -> Meta
signedMeta} -> do
Env' withAuth -> Signed a -> IO ()
forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a)
Hook_ (Signed a)
signedRequest Env' withAuth
env Signed a
s
Logger -> Meta -> IO ()
forall (m :: * -> *) a. (MonadIO m, ToLog a) => Logger -> a -> m ()
logTrace Logger
logger Meta
signedMeta,
clientRequest = \env :: Env' withAuth
env@Env {Logger
$sel:logger:Env :: forall (withAuth :: * -> *). Env' withAuth -> Logger
logger :: Logger
logger} ClientRequest
rq -> do
ClientRequest
rq' <- Env' withAuth -> ClientRequest -> IO ClientRequest
Hook ClientRequest
clientRequest Env' withAuth
env ClientRequest
rq
ClientRequest
rq' ClientRequest -> IO () -> IO ClientRequest
forall a b. a -> IO b -> IO a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Logger -> ClientRequest -> IO ()
forall (m :: * -> *) a. (MonadIO m, ToLog a) => Logger -> a -> m ()
logDebug Logger
logger ClientRequest
rq',
clientResponse = \env :: Env' withAuth
env@Env {Logger
$sel:logger:Env :: forall (withAuth :: * -> *). Env' withAuth -> Logger
logger :: Logger
logger} t :: (Request a, ClientResponse ())
t@(Request a
_, ClientResponse ()
rs) -> do
Env' withAuth -> (Request a, ClientResponse ()) -> IO ()
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
Hook_ (Request a, ClientResponse ())
clientResponse Env' withAuth
env (Request a, ClientResponse ())
t
Logger -> ClientResponse () -> IO ()
forall (m :: * -> *) a. (MonadIO m, ToLog a) => Logger -> a -> m ()
logDebug Logger
logger ClientResponse ()
rs,
rawResponseBody = \env :: Env' withAuth
env@Env {Logger
$sel:logger:Env :: forall (withAuth :: * -> *). Env' withAuth -> Logger
logger :: Logger
logger} ByteStringLazy
body -> do
ByteStringLazy
body' <- Env' withAuth -> ByteStringLazy -> IO ByteStringLazy
Hook ByteStringLazy
rawResponseBody Env' withAuth
env ByteStringLazy
body
ByteStringLazy
body' ByteStringLazy -> IO () -> IO ByteStringLazy
forall a b. a -> IO b -> IO a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Logger -> ByteStringLazy -> IO ()
forall (m :: * -> *) a. (MonadIO m, ToLog a) => Logger -> a -> m ()
logTrace Logger
logger (ByteStringLazy
"[Raw Response Body] {\n" ByteStringLazy -> ByteStringLazy -> ByteStringLazy
forall a. Semigroup a => a -> a -> a
<> ByteStringLazy
body' ByteStringLazy -> ByteStringLazy -> ByteStringLazy
forall a. Semigroup a => a -> a -> a
<> ByteStringLazy
"\n}"),
requestRetry = \env :: Env' withAuth
env@Env {Logger
$sel:logger:Env :: forall (withAuth :: * -> *). Env' withAuth -> Logger
logger :: Logger
logger} t :: (Request a, Text, RetryStatus)
t@(Request a
_, Text
name, RetryStatus
retryStatus) -> do
Env' withAuth -> (Request a, Text, RetryStatus) -> IO ()
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
Hook_ (Request a, Text, RetryStatus)
requestRetry Env' withAuth
env (Request a, Text, RetryStatus)
t
Logger -> ByteStringBuilder -> IO ()
forall (m :: * -> *) a. (MonadIO m, ToLog a) => Logger -> a -> m ()
logDebug Logger
logger (ByteStringBuilder -> IO ())
-> ([ByteStringBuilder] -> ByteStringBuilder)
-> [ByteStringBuilder]
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteStringBuilder] -> ByteStringBuilder
munwords ([ByteStringBuilder] -> IO ()) -> [ByteStringBuilder] -> IO ()
forall a b. (a -> b) -> a -> b
$
[ ByteStringBuilder
"[Retry " ByteStringBuilder -> ByteStringBuilder -> ByteStringBuilder
forall a. Semigroup a => a -> a -> a
<> Text -> ByteStringBuilder
forall a. ToLog a => a -> ByteStringBuilder
build Text
name ByteStringBuilder -> ByteStringBuilder -> ByteStringBuilder
forall a. Semigroup a => a -> a -> a
<> ByteStringBuilder
"]",
ByteStringBuilder
"after",
Int -> ByteStringBuilder
forall a. ToLog a => a -> ByteStringBuilder
build (RetryStatus -> Int
Retry.rsIterNumber RetryStatus
retryStatus Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1),
ByteStringBuilder
"attempt(s)."
],
awaitRetry = \env :: Env' withAuth
env@Env {Logger
$sel:logger:Env :: forall (withAuth :: * -> *). Env' withAuth -> Logger
logger :: Logger
logger} t :: (Request a, Wait a, Accept, RetryStatus)
t@(Request a
_, Wait {ByteString
name :: ByteString
$sel:name:Wait :: forall a. Wait a -> ByteString
name}, Accept
accept, RetryStatus
retryStatus) -> do
Env' withAuth -> (Request a, Wait a, Accept, RetryStatus) -> IO ()
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
Hook_ (Request a, Wait a, Accept, RetryStatus)
awaitRetry Env' withAuth
env (Request a, Wait a, Accept, RetryStatus)
t
Logger -> ByteStringBuilder -> IO ()
forall (m :: * -> *) a. (MonadIO m, ToLog a) => Logger -> a -> m ()
logDebug Logger
logger (ByteStringBuilder -> IO ())
-> ([ByteStringBuilder] -> ByteStringBuilder)
-> [ByteStringBuilder]
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteStringBuilder] -> ByteStringBuilder
munwords ([ByteStringBuilder] -> IO ()) -> [ByteStringBuilder] -> IO ()
forall a b. (a -> b) -> a -> b
$
[ ByteStringBuilder
"[Await " ByteStringBuilder -> ByteStringBuilder -> ByteStringBuilder
forall a. Semigroup a => a -> a -> a
<> ByteString -> ByteStringBuilder
forall a. ToLog a => a -> ByteStringBuilder
build ByteString
name ByteStringBuilder -> ByteStringBuilder -> ByteStringBuilder
forall a. Semigroup a => a -> a -> a
<> ByteStringBuilder
"]",
Accept -> ByteStringBuilder
forall a. ToLog a => a -> ByteStringBuilder
build Accept
accept,
ByteStringBuilder
"after",
Int -> ByteStringBuilder
forall a. ToLog a => a -> ByteStringBuilder
build (RetryStatus -> Int
Retry.rsIterNumber RetryStatus
retryStatus Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1),
ByteStringBuilder
"attempts."
],
error = \env :: Env' withAuth
env@Env {Logger
$sel:logger:Env :: forall (withAuth :: * -> *). Env' withAuth -> Logger
logger :: Logger
logger} t :: (Finality, Request a, Error)
t@(Finality
finality, Request a
_, Error
err) -> do
Env' withAuth -> (Finality, Request a, Error) -> IO ()
forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
Hook_ (Finality, Request a, Error)
error Env' withAuth
env (Finality, Request a, Error)
t
case Finality
finality of
Finality
NotFinal -> Logger -> Error -> IO ()
forall (m :: * -> *) a. (MonadIO m, ToLog a) => Logger -> a -> m ()
logDebug Logger
logger Error
err
Finality
Final -> Logger -> Error -> IO ()
forall (m :: * -> *) a. (MonadIO m, ToLog a) => Logger -> a -> m ()
logError Logger
logger Error
err
}
where
munwords :: [ByteStringBuilder] -> ByteStringBuilder
munwords = [ByteStringBuilder] -> ByteStringBuilder
forall a. Monoid a => [a] -> a
mconcat ([ByteStringBuilder] -> ByteStringBuilder)
-> ([ByteStringBuilder] -> [ByteStringBuilder])
-> [ByteStringBuilder]
-> ByteStringBuilder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteStringBuilder -> [ByteStringBuilder] -> [ByteStringBuilder]
forall a. a -> [a] -> [a]
intersperse ByteStringBuilder
" "
noHooks :: Hooks
noHooks :: Hooks
noHooks =
Hooks
{ $sel:request:Hooks :: forall a. (AWSRequest a, Typeable a) => Hook a
request = (a -> IO a) -> Env' withAuth -> a -> IO a
forall a b. a -> b -> a
const a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure,
$sel:configuredRequest:Hooks :: forall a. (AWSRequest a, Typeable a) => Hook (Request a)
configuredRequest = (Request a -> IO (Request a))
-> Env' withAuth -> Request a -> IO (Request a)
forall a b. a -> b -> a
const Request a -> IO (Request a)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure,
$sel:wait:Hooks :: forall a. (AWSRequest a, Typeable a) => Hook (Wait a)
wait = (Wait a -> IO (Wait a)) -> Env' withAuth -> Wait a -> IO (Wait a)
forall a b. a -> b -> a
const Wait a -> IO (Wait a)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure,
$sel:signedRequest:Hooks :: forall a. (AWSRequest a, Typeable a) => Hook_ (Signed a)
signedRequest = \Env' withAuth
_ Signed a
_ -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (),
$sel:clientRequest:Hooks :: Hook ClientRequest
clientRequest = (ClientRequest -> IO ClientRequest)
-> Env' withAuth -> ClientRequest -> IO ClientRequest
forall a b. a -> b -> a
const ClientRequest -> IO ClientRequest
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure,
$sel:clientResponse:Hooks :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse ())
clientResponse = \Env' withAuth
_ (Request a, ClientResponse ())
_ -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (),
$sel:rawResponseBody:Hooks :: Hook ByteStringLazy
rawResponseBody = (ByteStringLazy -> IO ByteStringLazy)
-> Env' withAuth -> ByteStringLazy -> IO ByteStringLazy
forall a b. a -> b -> a
const ByteStringLazy -> IO ByteStringLazy
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure,
$sel:requestRetry:Hooks :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Text, RetryStatus)
requestRetry = \Env' withAuth
_ (Request a, Text, RetryStatus)
_ -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (),
$sel:awaitRetry:Hooks :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, Wait a, Accept, RetryStatus)
awaitRetry = \Env' withAuth
_ (Request a, Wait a, Accept, RetryStatus)
_ -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (),
$sel:response:Hooks :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Request a, ClientResponse (AWSResponse a))
response = \Env' withAuth
_ (Request a, ClientResponse (AWSResponse a))
_ -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (),
error :: forall a.
(AWSRequest a, Typeable a) =>
Hook_ (Finality, Request a, Error)
error = \Env' withAuth
_ (Finality, Request a, Error)
_ -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
}