module Ecluse.Service.Internal (
dataPlaneManagers,
) where
import Network.HTTP.Client (Manager)
import Ecluse.Composition.Plan (BootPlan (bpPrivateConnections, bpPublicConnections, bpValidated))
import Ecluse.Composition.Sizing (newPooledManager)
import Ecluse.Composition.Validate (ValidatedPlan (vpSettings))
import Ecluse.Config (AppConfig (cfgEgress), EgressSettings (egrOperatorContact))
import Ecluse.Core.BuildIdentity (identityManagerSettings, renderUserAgent)
import Ecluse.Core.Fault.Http (typedTlsManagerSettings)
dataPlaneManagers :: BootPlan -> IO (Manager, Manager)
dataPlaneManagers :: BootPlan -> IO (Manager, Manager)
dataPlaneManagers BootPlan
bootPlan = (,) (Manager -> Manager -> (Manager, Manager))
-> IO Manager -> IO (Manager -> (Manager, Manager))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> IO Manager
pooled (BootPlan -> Int
bpPublicConnections BootPlan
bootPlan) IO (Manager -> (Manager, Manager))
-> IO Manager -> IO (Manager, Manager)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> IO Manager
pooled (BootPlan -> Int
bpPrivateConnections BootPlan
bootPlan)
where
renderedAgent :: ByteString
renderedAgent = Maybe OperatorContact -> ByteString
renderUserAgent (EgressSettings -> Maybe OperatorContact
egrOperatorContact (AppConfig -> EgressSettings
cfgEgress (ValidatedPlan -> AppConfig
vpSettings (BootPlan -> ValidatedPlan
bpValidated BootPlan
bootPlan))))
pooled :: Int -> IO Manager
pooled Int
connections = Int -> ManagerSettings -> IO Manager
newPooledManager Int
connections (ByteString -> ManagerSettings -> ManagerSettings
identityManagerSettings ByteString
renderedAgent ManagerSettings
typedTlsManagerSettings)