s3dol.connection¶
S3Connection — the credential + endpoint SSOT, and the pure resolver.
Design record: misc/docs/decisions/0012-credential-and-endpoint-resolution.md
(all of it) on top of 0002-boto3-as-engine.md (lazy boto3) and
0003-provider-presets-and-capabilities.md (presets, SigV4 mandate).
The two sentences the module follows from (ADR-0012):
A preset is the caller’s explicit endpoint, spelled by name. It sits exactly where
endpoint_url=sits — above every environment and config-file channel. s3dol owns two rungs of the endpoint ladder, not six.**A
Configvalue s3dol does not set is a channel it leaves open to the user.** Every field is a ladder with a documented bottom, and “the row makes no claim” is spelled by omitting the key, never by passingNone.
Structure:
S3Connection— a frozen, picklable spec. No live objects, no escape hatch for one. Construction performs no I/O and imports no boto3.resolve()— a pure function(spec, environ, aws_config) -> Resolutionwhere every field carries its provenance. Tier-1 tests cover the whole ladder with a fake environ dict and zero I/O.load_aws_config()— the separate, named impure loader for the aws-config rungs; pass it (or its result) toresolve().Credential shapes (ADR-0012 D5) — normalised in
__post_init__to small frozen, picklable providers; live botocore objects are rejected with shape-specific messages.
>>> spec = S3Connection(endpoint_url='http://localhost:9000',
... credentials=('AKIAEXAMPLE', 'sEkR3tVALUE'))
>>> res = resolve(spec, {})
>>> res.endpoint_url.value, res.endpoint_url.source
('http://localhost:9000', 'endpoint_url=')
>>> res.signature_version.value # never left to botocore (ADR-0003 §4)
's3v4'
>>> 'sEkR3tVALUE' in repr(spec) # secrets never in repr (ADR-0012 D1)
False
Functions
The named, impure aws-config loader (ADR-0012 D2): loads the shared config via botocore (~16 ms — never on the common path; pass this function as a thunk and |
|
|
Normalise every accepted credential shape; reject the rest, each with its own message (ADR-0012 D5). |
|
Pure resolution: no |
Classes
|
A picklable zero-arg callable returning a mapping with keys |
Base of s3dol's picklable credential specs. |
|
|
Credentials from a named profile — credentials only; the profile's other config is not selected by this (that is what |
|
The result of |
|
A frozen, picklable connection spec. |
|
A resolved value, where it came from, and whether s3dol passes it to botocore explicitly ( |
|
An explicit key pair (optionally a session token). |
- class s3dol.connection.CallableCredentials(fetch)[source]¶
Bases:
CredentialProviderA picklable zero-arg callable returning a mapping with keys
access_key/secret_key(aliases:key/secret), optionaltoken, optionalexpires_at/expiry_time(ISO 8601). With an expiry, credentials are refreshable — the callable is re-invoked by botocore’s refresh machinery (advisory 900 s / mandatory 600 s before expiry).
- class s3dol.connection.CredentialProvider[source]¶
Bases:
objectBase of s3dol’s picklable credential specs.
Subclasses are small frozen dataclasses that describe how to obtain credentials; nothing live is held (nothing live pickles — measured, ADR-0012 D5). At client-build time each is adapted into a botocore provider and replaces botocore’s resolver via
session.register_component('credential_provider', ...)— never prepended (silent fallthrough) and neverinsert_before(raises when a profile is set).
- class s3dol.connection.ProfileCredentials(profile)[source]¶
Bases:
CredentialProviderCredentials from a named profile — credentials only; the profile’s other config is not selected by this (that is what
profile=on the connection is for). Rebuilds live, still-refreshable credentials after unpickling (a frozen dataclass holding only a profile name round-trips).
- class s3dol.connection.Resolution(endpoint_url, region_name, signature_version, addressing_style, checksum, payload_signing_enabled, verify, preset, preset_source, credential_provenance, capabilities, environ_consulted, notes)[source]¶
Bases:
objectThe result of
resolve()— everythingdiagnose()prints and everything client-build consumes. Carries provenance labels, never a credential value.
- class s3dol.connection.S3Connection(preset=None, endpoint_url=None, region_name=None, profile=None, credentials=None, anon=False, signature_version='s3v4', addressing_style=None, checksum=None, payload_signing_enabled=None, verify=None, client_kwargs=(), deny_means_absent=False)[source]¶
Bases:
objectA frozen, picklable connection spec. No live objects — ever.
Construction performs no I/O and does not import boto3 (ADR-0002); the client is built lazily, once, under a per-instance lock (CPython ≥3.12 removed
cached_property’s lock deliberately — measured: 8 racing threads → 8 clients without one).__post_init__is the only door: every normalisation and contradiction check happens here, so a bad shape dies at construction with a message, not later inside botocore.>>> S3Connection(anon=True, profile='prod') Traceback (most recent call last): ... s3dol.errors.ConfigurationError: ...
- property client¶
The boto3 S3 client — built lazily, once, under the lock.
- property presign_client¶
The client presigned URLs are generated with.
For most providers this is
client. Two providers genuinely need different config for presigning than for the API (ADR-0003 §1): Hetzner presigns virtual-hosted while the API is path-style; R2 presigns only on the S3 API domain. When the resolved preset carriespresign_endpoint_url/presign_addressing_style, a second client is built (lazily, once, under the same lock) from the merged config.
- class s3dol.connection.Sourced(value, source, passed=False)[source]¶
Bases:
NamedTupleA resolved value, where it came from, and whether s3dol passes it to botocore explicitly (
passed=False== the key is omitted so the channel below stays open — “omit, never None”).
- class s3dol.connection.StaticCredentials(access_key, secret_key, token=None)[source]¶
Bases:
CredentialProviderAn explicit key pair (optionally a session token).
Note
a static token expires and cannot refresh — prefer
profile=or a callable provider for STS/SSO. Pickling this object carries the secret (that is what “explicit credentials” means); its repr does not.
- s3dol.connection.load_aws_config()[source]¶
The named, impure aws-config loader (ADR-0012 D2): loads the shared config via botocore (~16 ms — never on the common path; pass this function as a thunk and
resolve()calls it only if a rung needs it), scrubbed of anything credential-shaped.- Return type:
- s3dol.connection.normalize_credentials(value)[source]¶
Normalise every accepted credential shape; reject the rest, each with its own message (ADR-0012 D5). The only door is
S3Connection.__post_init__.>>> normalize_credentials(None) is None True >>> normalize_credentials('prod') ProfileCredentials(profile='prod') >>> normalize_credentials(('AKIAXX', 'sec')) StaticCredentials(access_key='AKIA'…, secret_key=***)
- Return type:
- s3dol.connection.resolve(spec, environ, aws_config=None)[source]¶
Pure resolution: no
os.environ, no disk, no network (ADR-0012 D2).environis a plain mapping (passos.environat real call sites, a dict in tests).aws_configis a pre-loaded, credential-scrubbed config mapping, or a thunk for one (load_aws_config()) — called only if a rung needs it.- Return type: