module Network.AWS.Internal.Env where
import Control.Lens
import Control.Retry
import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.List (intersperse)
import Data.Monoid
import Network.AWS.Data (ToBuilder(..), buildBS)
import Network.AWS.Types
import Network.HTTP.Conduit
data Env = Env
{ _envRegion :: !Region
, _envLogger :: Logger
, _envRetryCheck :: Int -> HttpException -> IO Bool
, _envRetryPolicy :: Maybe RetryPolicy
, _envManager :: Manager
, _envAuth :: Auth
}
envRegion :: Lens' Env Region
envRegion = lens _envRegion (\s a -> s { _envRegion = a })
envLogger :: Lens' Env Logger
envLogger = lens _envLogger (\s a -> s { _envLogger = a })
envRetryCheck :: Lens' Env (Int -> HttpException -> IO Bool)
envRetryCheck = lens _envRetryCheck (\s a -> s { _envRetryCheck = a })
envRetryPolicy :: Lens' Env (Maybe RetryPolicy)
envRetryPolicy = lens _envRetryPolicy (\s a -> s { _envRetryPolicy = a })
envManager :: Lens' Env Manager
envManager = lens _envManager (\s a -> s { _envManager = a })
envAuth :: Lens' Env Auth
envAuth = lens _envAuth (\s a -> s { _envAuth = a })
instance ToBuilder Env where
build Env{..} = mconcat $ intersperse "\n"
[ "[Amazonka Env] {"
, " region = " <> build _envRegion
, " retry (n=0) = " <> maybe "Nothing" policy _envRetryPolicy
, build . indent $ buildBS _envAuth
, "}"
]
where
policy (RetryPolicy f) = "Just " <> build (f 0)
indent = mappend " "
. LBS.concat
. intersperse "\n "
. LBS.lines