module Ecluse.Core.Registry.PyPI.Request (
pypiArtifactHosts,
simpleIndexRequest,
artifactRequestByFile,
artifactRequestByUrl,
simpleIndexUrl,
artifactFileUrl,
artifactPath,
) where
import Network.HTTP.Client (Request (decompress, requestHeaders))
import Network.HTTP.Types.Header (hAccept, hAcceptEncoding)
import Ecluse.Core.Credential (ClientCredential)
import Ecluse.Core.Package (PackageName)
import Ecluse.Core.Registry (UrlFormationError)
import Ecluse.Core.Registry.PyPI.Credential (pypiCredential)
import Ecluse.Core.Registry.PyPI.Project (canonicalName)
import Ecluse.Core.Registry.PyPI.Wire (simpleIndexMediaType)
import Ecluse.Core.Registry.Request (attachCredential, joinPath, parseRequestEither)
import Ecluse.Core.Registry.Request qualified as Request
import Ecluse.Core.Server.Path (encodeComponent)
pypiArtifactHosts :: [Text]
pypiArtifactHosts :: [Text]
pypiArtifactHosts = [Text
"https://files.pythonhosted.org"]
simpleIndexRequest ::
Text ->
Maybe ClientCredential ->
PackageName ->
Either UrlFormationError Request
simpleIndexRequest :: Text
-> Maybe ClientCredential
-> PackageName
-> Either UrlFormationError Request
simpleIndexRequest Text
baseUrl Maybe ClientCredential
credential PackageName
name = do
url <- Text -> PackageName -> Either UrlFormationError Text
simpleIndexUrl Text
baseUrl PackageName
name
base <- parseRequestEither url
pure
. attachCredential pypiCredential credential
$ base
{ requestHeaders =
(hAccept, simpleIndexMediaType)
: (hAcceptEncoding, "gzip")
: requestHeaders base
}
artifactRequestByFile ::
Text ->
Maybe ClientCredential ->
PackageName ->
Text ->
Either UrlFormationError Request
artifactRequestByFile :: Text
-> Maybe ClientCredential
-> PackageName
-> Text
-> Either UrlFormationError Request
artifactRequestByFile Text
baseUrl Maybe ClientCredential
credential PackageName
name Text
filename = do
url <- Text -> PackageName -> Text -> Either UrlFormationError Text
artifactFileUrl Text
baseUrl PackageName
name Text
filename
base <- parseRequestEither url
pure
. attachCredential pypiCredential credential
$ base{decompress = const False}
artifactRequestByUrl ::
Maybe ClientCredential ->
Text ->
Either UrlFormationError Request
artifactRequestByUrl :: Maybe ClientCredential -> Text -> Either UrlFormationError Request
artifactRequestByUrl = CredentialMapping
-> Maybe ClientCredential
-> Text
-> Either UrlFormationError Request
Request.artifactRequestByUrl CredentialMapping
pypiCredential
simpleIndexUrl :: Text -> PackageName -> Either UrlFormationError Text
simpleIndexUrl :: Text -> PackageName -> Either UrlFormationError Text
simpleIndexUrl Text
baseUrl PackageName
name = Text -> Text -> Either UrlFormationError Text
joinPath Text
baseUrl (Text -> Text
projectPath (PackageName -> Text
canonicalName PackageName
name) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/")
artifactFileUrl :: Text -> PackageName -> Text -> Either UrlFormationError Text
artifactFileUrl :: Text -> PackageName -> Text -> Either UrlFormationError Text
artifactFileUrl Text
baseUrl PackageName
name Text
filename = Text -> Text -> Either UrlFormationError Text
joinPath Text
baseUrl (Text -> Text -> Text
artifactPath (PackageName -> Text
canonicalName PackageName
name) Text
filename)
artifactPath :: Text -> Text -> Text
artifactPath :: Text -> Text -> Text
artifactPath Text
project Text
filename = Text -> Text
projectPath Text
project Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
encodeComponent Text
filename
projectPath :: Text -> Text
projectPath :: Text -> Text
projectPath Text
project = Text
"simple/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
encodeComponent Text
project