32 lines
925 B
Python
32 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")
|