ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Registry.Request

Description

Shared HTTP requests with typed URL failures, ecosystem-specific credential presentation, and the mechanisms a store can declare for service credentials. Requests parsed here refuse redirects, including after credentials attach.

Synopsis

Request finalisation

sealRequest :: Request -> Request Source #

Seal the outbound invariants onto a request, idempotently. A followed redirect could re-send a credential cross-host or steer an anonymous fetch past the host allowlist.

finaliseRequest :: (Request -> Request) -> Request -> Request Source #

Apply the ecosystem's injected credential attach, then seal the result through sealRequest. The attach runs first, so it cannot reopen redirect following.

Credential presentation

data CredentialMapping Source #

One ecosystem's credential presentation, recovered as a value so an attach re-encodes rather than replaying a header. The constructor is hidden, so no adapter spells its own attach point.

credentialMapping :: (RequestHeaders -> Maybe ClientCredential) -> HeaderName -> (ClientCredential -> ByteString) -> CredentialMapping Source #

Declare an ecosystem's credential presentation. The constructor is hidden, so this is the only way to build a CredentialMapping.

credentialRecover :: CredentialMapping -> RequestHeaders -> Maybe ClientCredential Source #

Nothing for a request carrying none in this ecosystem's form, which the edge gate denies rather than half-reading. The compare is over the secret half alone.

attachCredential :: CredentialMapping -> Maybe ClientCredential -> Request -> Request Source #

Attach a credential to an outbound request under the mapping's own header, then finalise it through finaliseRequest. A Nothing attaches no header, and the seal still applies.

authorizationUnder :: Text -> RequestHeaders -> Maybe Text Source #

The first Authorization header's remainder when it carries scheme (compared without case), with the separating spaces dropped. Another scheme or no header yields Nothing.

bareAuthorization :: RequestHeaders -> Maybe ClientCredential Source #

A scheme-less credential from exactly one non-empty Authorization line whose bytes are all in RFC 9110's field-value set: visible ASCII, space and tab. Any other presentation yields Nothing.

Service credential presentation

data AuthMechanism Source #

How a secret travels on Authorization, named without reference to an ecosystem or a store.

Constructors

AuthBearer

Bearer followed by the secret.

AuthBasic Text

HTTP Basic over this username and the secret.

AuthRawKey

The secret alone, with no scheme.

renderAuthMechanism :: AuthMechanism -> ClientCredential -> ByteString Source #

The Authorization value a credential renders to under a mechanism.

data StoreOperation Source #

The half of a store's protocol a service credential is presented to.

Constructors

StoreRead 
StoreWrite 

data ServicePresentation Source #

How a store asks for a service credential on reads and on writes. An operation it declares nothing for keeps the ecosystem's own credential mapping.

nativePresentation :: ServicePresentation Source #

A store that declares nothing: every operation keeps the ecosystem's own presentation.

declaredPresentation :: (StoreOperation -> AuthMechanism) -> ServicePresentation Source #

A store that declares its mechanism for each operation.

sendsCredentialUsername :: ServicePresentation -> StoreOperation -> Bool Source #

Whether an operation sends the credential's own username. Only the ecosystem's own mapping can: a declared mechanism sends the secret alone or the store's own Basic username.

presentedMapping :: ServicePresentation -> StoreOperation -> CredentialMapping -> CredentialMapping Source #

The mapping a service credential renders through for one operation: the declared mechanism on Authorization, or the ecosystem's mapping unchanged. Recovery stays the ecosystem's own.

presentedRequest :: CredentialMapping -> Maybe ClientCredential -> (Maybe ClientCredential -> Either e Request) -> Either e Request Source #

Form a request anonymously, then attach the credential under mapping. The builder must use its credential only to attach it, as every native request builder here does.

Request building

metadataGet :: CredentialMapping -> Maybe ClientCredential -> ByteString -> Request -> Request Source #

Negotiate compressed metadata under the ecosystem's media type and credential presentation.

artifactRequestByUrl :: CredentialMapping -> Maybe ClientCredential -> Text -> Either UrlFormationError Request Source #

Build the artifact GET at the preserved upstream URL through artifactGet.

artifactGet :: CredentialMapping -> Maybe ClientCredential -> Request -> Request Source #

Make a parsed request the artifact GET, in identity coding and never decompressed. Without the field, http-client asks for gzip, and gzip bytes miss the advertised digest.

joinPath :: Text -> Text -> Either UrlFormationError Text Source #

Join a base URL and an already-encoded path with exactly one slash, whatever trailing slashes the configured base writes.

apiEndpoint :: UrlFormationError -> Text -> Text -> Either UrlFormationError Request Source #

Parse an already-encoded API path under a configured root. A root with a query or a fragment is refused with refusal, because the joined path would land inside it.

sidecarUrl :: Text -> Text Source #

Append the companion suffix to the path while preserving query and fragment text.

parseRequestEither :: Text -> Either UrlFormationError Request Source #

Parse a URL into the sealed request every adapter builds from (sealRequest). The URL comes from configuration and an already-safe name, so a parse failure here is a configuration fault.

Requests under a base parsed once

data BaseRequest Source #

An upstream base URL and its one parse, so a request under it appends its path rather than parsing the joined URL again. mkBaseRequest is the only builder.

Instances

Instances details
Show BaseRequest Source # 
Instance details

Defined in Ecluse.Core.Registry.Request

Eq BaseRequest Source # 
Instance details

Defined in Ecluse.Core.Registry.Request

mkBaseRequest :: RegistryUrl -> BaseRequest Source #

Parse url joined to an empty path, which is the request every path under it extends. A URL with a query or a fragment keeps no parse, because a path joined after either lands inside it.

baseRequestUrl :: BaseRequest -> RegistryUrl Source #

The URL the base was parsed from.

requestAt :: BaseRequest -> Text -> Either UrlFormationError Request Source #

The request for the base joined to an already-encoded suffix, equal to parseRequestEither of the joined URL. It parses that URL only when the base kept no parse or the suffix is not verbatim.