s3dol.presets¶
Provider presets: config rows, not subclasses.
Design record: misc/docs/decisions/0003-provider-presets-and-capabilities.md
(the survey of 16 backends, the checksum analysis, capabilities policy) amended
by misc/docs/decisions/0012-credential-and-endpoint-resolution.md §D4
(params/host_patterns/requires_endpoint/soft/config_kwargs,
derived pinned; signature_version and client_kwargs moved to the
connection; addressing_style mandatory with 'auto' illegal; the
structural no-credential rule).
A provider divergence is a row in this registry — never a subclass, never an endpoint-substring branch in the hot path. Users register their own rows:
>>> row = Preset(name='mycorp', addressing_style='path',
... endpoint_url='https://s3.mycorp.example', requires_endpoint=False)
>>> register(row)
>>> get_preset('mycorp').endpoint_url
'https://s3.mycorp.example'
>>> unregister('mycorp') # (cleanup for this doctest)
Most builtin rows are doc-sourced, not verified against a live endpoint —
they say so via verified=False. Wrong values mostly fail loudly, which is
the acceptable failure mode; pinned (which makes a row’s region literal
conflict-raising) is derived and gated on verified, so it is dormant
until a row earns evidence (ADR-0012 D4).
Module Attributes
|
Functions
|
|
|
Detection (resolution pass 2): the non-soft row whose |
|
Look a row up by name; unknown names raise, naming the registry. |
|
Add a row. |
|
Remove a row (mostly for tests). |
|
Refuse credential-carrying URL shapes: userinfo in the netloc, a query string, or a fragment (ADR-0012 D4 — a query-string endpoint is accepted by botocore and retained verbatim in |
Classes
|
What a backend supports. |
|
One provider's facts. |
- s3dol.presets.CONFIG_KWARGS_ALLOWLIST = frozenset({'connect_timeout', 'max_pool_connections', 'read_timeout', 'tcp_keepalive'})¶
Config-constructor kwargs a preset row may carry. Scalars only, andproxies/proxies_config/client_context_paramsare structurally excluded — a preset must not be able to smuggle a credential-bearing proxy URL (ADR-0012 D4).
- class s3dol.presets.Capabilities(list_objects_v2=True, batch_delete=True, presigned_post=True, multipart=True, max_multipart_parts=10000, min_part_size=5242880, object_tagging=True, versioning=True, conditional_writes=True, consistency='strong')[source]¶
Bases:
objectWhat a backend supports. A static declared table, never a probe (a probe costs a round-trip, is wrong under partial permissions, and can’t be trusted anyway — ADR-0003 §2). Missing capabilities are handled per-capability: emulate when exact (batch delete -> loop), substitute when equivalent (ListObjectsV2 -> V1), raise
NotSupportedwhen there is no honest fallback. Never silently degrade correctness.
- class s3dol.presets.Preset(name, addressing_style, endpoint_url=None, region_name=None, checksum=None, payload_signing_enabled=None, capabilities=Capabilities(list_objects_v2=True, batch_delete=True, presigned_post=True, multipart=True, max_multipart_parts=10000, min_part_size=5242880, object_tagging=True, versioning=True, conditional_writes=True, consistency='strong'), presign_endpoint_url=None, presign_addressing_style=None, params=(), host_patterns=(), requires_endpoint=False, soft=False, config_kwargs=(), error_overrides=(), verified=False)[source]¶
Bases:
objectOne provider’s facts. Public, shareable, committable config — which is why there is no credential slot, structurally (ADR-0012 D4).
endpoint_url/region_namemay contain{placeholders}; bind them withbind(). A row whose endpoint template has an unbound required placeholder contributes no endpoint rung (ADR-0012 C1).- addressing_style: Literal['path', 'virtual']¶
Mandatory; no default;
'auto'is illegal (ADR-0012 D4).
- bind(**params)[source]¶
A copy of this row with template
paramsbound.>>> r2 = get_preset('r2').bind(account_id='abc123') >>> r2.bound_endpoint() 'https://abc123.r2.cloudflarestorage.com'
- Return type:
- bound_endpoint(*, region_name=None)[source]¶
The endpoint URL with params bound, or
Noneif the template has unbound placeholders (C1: an unbound row contributes no rung —preset='minio'silently becoming AWS is structurally impossible).region_namebinds a{region_name}placeholder, per the region ladder’s first rung (ADR-0012 D3).
- checksum: Optional[Literal['when_supported', 'when_required']] = None¶
None== the row makes no claim (the ladder continues — ADR-0012 D3).
- config_kwargs: tuple[tuple[str, Any], ...] = ()¶
Extra
botocore.Configkwargs — allowlisted, scalars only.
- error_overrides: tuple[tuple[tuple[Optional[str], Optional[str], Optional[int]], str], ...] = ()¶
Error-classification overrides, consulted before the default table (ADR-0004 §2/§6): rows of
((operation, code, status), kind).
- host_patterns: tuple[str, ...] = ()¶
fnmatchpatterns over the endpoint hostname; used for detection (pass 2) and the C2 named-vs-resolved guard.
- matches_host(endpoint_url)[source]¶
Whether
endpoint_url’s hostname matches this row’s patterns.- Return type:
- missing_endpoint_params(*, region_name=None)[source]¶
Which placeholders keep
bound_endpoint()from producing a URL.- Return type:
- property pinned: bool¶
Whether the row’s region literal is authoritative enough to make a conflicting explicit
region_name=raisePresetConflict. Derived, and gated onverified— dormant while rows are doc-sourced (ADR-0012 D4).
- presign_endpoint_url: Optional[str] = None¶
Presigning sometimes genuinely differs from the API config (Hetzner presigns virtual while the API is path; R2 presigns only on the S3 API domain) — ADR-0003 §1.
- s3dol.presets.detect_preset(endpoint_url)[source]¶
Detection (resolution pass 2): the non-soft row whose
host_patternsmatch the resolved endpoint’s host. Two matching rows is genuinely ambiguous and raises; zero yieldsNone(the caller falls back togeneric-s3/aws— ADR-0012 D4).
- s3dol.presets.get_preset(name)[source]¶
Look a row up by name; unknown names raise, naming the registry.
- Return type:
- s3dol.presets.register(preset, *, overwrite=False)[source]¶
Add a row. Open-closed: adding a provider is adding a row.
- Return type:
- s3dol.presets.validate_endpoint_hygiene(url, *, what='endpoint_url')[source]¶
Refuse credential-carrying URL shapes: userinfo in the netloc, a query string, or a fragment (ADR-0012 D4 — a query-string endpoint is accepted by botocore and retained verbatim in
client.meta.endpoint_url, so it would leak intodiagnose()and tracebacks).>>> validate_endpoint_hygiene('https://s3.example.com') >>> validate_endpoint_hygiene('https://user:pw@s3.example.com') Traceback (most recent call last): ... s3dol.errors.InvalidEndpoint: ...
- Return type: