Self-contained ingestion module (mirrors fleettickets) for the WhatsApp fuel-record feed in the rustfs `fuel` bucket: - import_fuel.py — snapshot/changes/file modes, raw-jsonb upsert on id - migrations/01_fuel_schema.sql — fuel schema, plate/fuel-type/department normalizers, trigger-derived columns, reporting.v_fuel_fills + v_fuel_efficiency, grafana_ro grants - s3util.py / shared.py / run_migrations.py — rustfs client + DB helpers - docs/plan.html — implementation plan Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
31 lines
925 B
Python
31 lines
925 B
Python
"""
|
|
s3util.py — fleetfuel · rustfs (S3-compatible) client factory.
|
|
|
|
rustfs needs path-style addressing and a custom endpoint. Credentials and
|
|
endpoint come from the RUSTFS_* env vars (see .env.example). Kept in one place
|
|
so import_fuel.py just asks for a ready client.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
import boto3
|
|
from botocore.config import Config
|
|
|
|
|
|
def get_s3():
|
|
"""Return a boto3 S3 client configured for the rustfs endpoint (path-style)."""
|
|
endpoint = os.environ["RUSTFS_ENDPOINT"]
|
|
return boto3.client(
|
|
"s3",
|
|
endpoint_url=endpoint,
|
|
aws_access_key_id=os.environ["RUSTFS_ACCESS_KEY"],
|
|
aws_secret_access_key=os.environ["RUSTFS_SECRET_KEY"],
|
|
region_name=os.getenv("RUSTFS_REGION", "us-east-1"),
|
|
config=Config(s3={"addressing_style": "path"}, signature_version="s3v4"),
|
|
)
|
|
|
|
|
|
def bucket() -> str:
|
|
return os.getenv("FUEL_BUCKET", "fuel")
|