module Ecluse.Core.Worker.Fetch (
fetchArtifactBytes,
) where
import Network.HTTP.Client (Request)
import Ecluse.Core.Credential (ClientCredential)
import Ecluse.Core.Registry (FetchFault (FetchUrlUnformable), RegistryResponse (responseBody), UrlFormationError)
import Ecluse.Core.Registry.Exchange (boundedFetch, formThen)
import Ecluse.Core.Security (BodyLimit (MirrorArtifactBodyLimit), Limits (progressFloor), maxMirrorArtifactBytes)
import Ecluse.Core.Security.Egress (RegistryUrl, registryUrlText)
import Ecluse.Core.Worker.Types (WorkerM, wrManager)
fetchArtifactBytes ::
Limits ->
(Maybe ClientCredential -> Text -> Either UrlFormationError Request) ->
RegistryUrl ->
WorkerM (Either FetchFault ByteString)
fetchArtifactBytes :: Limits
-> (Maybe ClientCredential
-> Text -> Either UrlFormationError Request)
-> RegistryUrl
-> WorkerM (Either FetchFault ByteString)
fetchArtifactBytes Limits
limits Maybe ClientCredential -> Text -> Either UrlFormationError Request
buildRequest RegistryUrl
url = do
manager <- (WorkerRuntime -> Manager) -> WorkerM Manager
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WorkerRuntime -> Manager
wrManager
liftIO
( formThen
FetchUrlUnformable
(fmap (fmap responseBody) . boundedFetch manager (progressFloor limits) (MirrorArtifactBodyLimit (maxMirrorArtifactBytes limits)))
(buildRequest Nothing (registryUrlText url))
)