climate_ref_core.regression.store
#
Data store for native bundles.
A single :class:NativeStore serves the baseline lifecycle.
It is constructed from a read URL,
plus the S3 routing config and credentials when it must also write:
- A
file://URL or a bare filesystem path is a local store, readable and writable without credentials, laid out two levels deep (<root>/<digest[:2]>/<digest>). Used by tests and local development. - An
http(s)://URL is the public read store. Blobs are pulled with :mod:poochfor caching, retry and hash verification, and are served flat at{url}/{digest}. - The same
http(s)://URL plus an :class:S3WriteConfigadds the credentialed S3-compatible (Cloudflare R2) write path used by themintverb.
The factory :func:build_native_store builds the store from the application
:class:~climate_ref.config.Config and the writable flag.
writable=False never requires credentials.
Write credentials are never read from the persisted config.
The S3 endpoint and bucket are not secrets, while authentication is resolved at client-build time only,
in precedence order: explicit REF_NATIVE_STORE_ACCESS_KEY_ID /
REF_NATIVE_STORE_SECRET_ACCESS_KEY env vars, then a named REF_NATIVE_STORE_PROFILE,
then boto3's default credential chain (which honours an ambient AWS_PROFILE).
Blobs are keyed by their sha256 hex digest.
NativeStore
#
Content-addressed store for native baseline blobs, keyed by sha256 hex digest.
A local store (a file:// URL or a bare path) always reads and writes without credentials.
A remote store reads anonymously through :mod:pooch,
and writes only when it is given an :class:S3WriteConfig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
Where blobs are read from: an |
required | |
cache_dir
|
Local directory pooch caches anonymous remote downloads in. A local store does not use it. |
required | |
write
|
The S3 endpoint, bucket and credentials a remote store writes with.
|
required |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
root = field(init=False)
class-attribute
instance-attribute
#
The local store root, or None when this store is remote.
fetch(digest, dest)
#
Fetch the blob identified by digest and write it to dest.
The sha256 of the written file is verified to equal digest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob to fetch. |
required |
dest
|
Path
|
Destination path to write the blob to. Parent directories are created if they do not exist. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the blob is not present in the store. |
ValueError
|
If the fetched blob's sha256 does not match |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
has(digest)
#
Return True if the blob identified by digest is available.
A local store checks its canonical path,
a writable remote store HEADs the object,
and an anonymous remote store checks the pooch cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
preflight()
#
Verify the store is reachable and usable before relying on it.
A local store's root is created if needed and checked for writability.
A writable remote store performs a cheap authenticated HEAD on a sentinel key,
which is expected to be absent:
a 404 means the request authenticated and the store is usable,
while 401 / 403 become actionable errors,
so a misconfigured credential is caught before the (slow) diagnostic run rather than after.
head_object is used rather than head_bucket,
so the check works with least-privilege, object-scoped tokens.
An anonymous remote store has nothing to verify up front. It has no credentials, and every read is hash-checked per blob.
Raises:
| Type | Description |
|---|---|
NativeStoreUnavailableError
|
If the store cannot be reached or used, with an operator-facing message. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
put(path)
#
Store the file at path and return its sha256 hex digest.
The blob is content-addressed, so storing one that is already present is skipped and re-minting is cheap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the file to store. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The sha256 hex digest of the stored blob. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If this is an anonymous remote store, which cannot write. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
NativeStoreUnavailableError
#
Bases: RuntimeError
Raised when a native store cannot be reached or used.
Covers rejected credentials, a missing bucket, or an unwritable local directory. The message is operator-facing and actionable (it names the env vars / path to check), so callers can surface it directly.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
S3WriteConfig
#
Where a remote store writes, and how it authenticates.
Routing (endpoint_url and bucket) is non-secret and comes from the application config.
Credentials are resolved from the environment at build time and are never persisted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint_url
|
S3 API endpoint for the bucket's account, without the bucket
(e.g. |
required | |
bucket
|
Name of the R2 bucket (e.g. |
required | |
access_key_id
|
R2 access-key id, or |
required | |
secret_access_key
|
R2 secret-access-key, or |
required | |
profile
|
Named AWS/R2 profile to authenticate with, or |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
__attrs_post_init__()
#
Fail fast at construction (mint startup) when the routing config is missing.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
client()
#
Return the cached boto3 S3 client for this endpoint and these credentials.
build_native_store(config, *, writable)
#
Build a :class:NativeStore from a native-store config object.
Accepts any object that exposes url, cache_dir, s3_endpoint_url and bucket
(satisfying :class:_NativeStoreConfigProtocol), so callers pass config.native_store
rather than the full :class:~climate_ref.config.Config.
With writable=False the returned store is anonymous and credential-free,
which suits the CI read and replay paths.
With writable=True and a remote URL the S3 endpoint and bucket come from the config,
and authentication is read from the environment
(REF_NATIVE_STORE_ACCESS_KEY_ID / REF_NATIVE_STORE_SECRET_ACCESS_KEY,
else REF_NATIVE_STORE_PROFILE, else boto3's default chain),
so secrets never live in the persisted config.
A local store is always readable and writable, so writable makes no difference to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
_NativeStoreConfigProtocol
|
A config object providing |
required |
writable
|
bool
|
Whether the store must be able to write. |
required |
Returns:
| Type | Description |
|---|---|
NativeStore
|
The configured store. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the URL scheme is unrecognised, or a writable remote store is requested without an S3 endpoint / bucket configured. |