Rename MinIO config to S3, switch to Cloudflare R2
- Rename MinioConfig → S3Config, settings.minio → settings.s3 - Update config.example.yaml with R2 endpoint template - S3 service is now storage-backend agnostic (MinIO, R2, any S3-compatible) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import yaml
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class MinioConfig(BaseModel):
|
class S3Config(BaseModel):
|
||||||
endpoint: str
|
endpoint: str
|
||||||
public_endpoint: str = ""
|
public_endpoint: str = ""
|
||||||
bucket: str = "snapledger"
|
bucket: str = "snapledger"
|
||||||
@@ -32,7 +32,7 @@ class ApiConfig(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class AppConfig(BaseModel):
|
class AppConfig(BaseModel):
|
||||||
minio: MinioConfig
|
s3: S3Config
|
||||||
postgresql: PostgresConfig
|
postgresql: PostgresConfig
|
||||||
api: ApiConfig
|
api: ApiConfig
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ from app.config import settings
|
|||||||
def _get_client():
|
def _get_client():
|
||||||
return boto3.client(
|
return boto3.client(
|
||||||
"s3",
|
"s3",
|
||||||
endpoint_url=settings.minio.endpoint,
|
endpoint_url=settings.s3.endpoint,
|
||||||
aws_access_key_id=settings.minio.access_key,
|
aws_access_key_id=settings.s3.access_key,
|
||||||
aws_secret_access_key=settings.minio.secret_key,
|
aws_secret_access_key=settings.s3.secret_key,
|
||||||
config=BotoConfig(signature_version="s3v4"),
|
config=BotoConfig(signature_version="s3v4"),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ def upload_image(file_bytes: bytes, original_filename: str) -> str:
|
|||||||
content_type = "image/png"
|
content_type = "image/png"
|
||||||
|
|
||||||
client.put_object(
|
client.put_object(
|
||||||
Bucket=settings.minio.bucket,
|
Bucket=settings.s3.bucket,
|
||||||
Key=object_key,
|
Key=object_key,
|
||||||
Body=file_bytes,
|
Body=file_bytes,
|
||||||
ContentType=content_type,
|
ContentType=content_type,
|
||||||
@@ -43,12 +43,12 @@ def upload_image(file_bytes: bytes, original_filename: str) -> str:
|
|||||||
|
|
||||||
def _get_presign_client():
|
def _get_presign_client():
|
||||||
"""Client using public endpoint so presigned URL signatures match the public host."""
|
"""Client using public endpoint so presigned URL signatures match the public host."""
|
||||||
endpoint = settings.minio.public_endpoint or settings.minio.endpoint
|
endpoint = settings.s3.public_endpoint or settings.s3.endpoint
|
||||||
return boto3.client(
|
return boto3.client(
|
||||||
"s3",
|
"s3",
|
||||||
endpoint_url=endpoint,
|
endpoint_url=endpoint,
|
||||||
aws_access_key_id=settings.minio.access_key,
|
aws_access_key_id=settings.s3.access_key,
|
||||||
aws_secret_access_key=settings.minio.secret_key,
|
aws_secret_access_key=settings.s3.secret_key,
|
||||||
config=BotoConfig(signature_version="s3v4"),
|
config=BotoConfig(signature_version="s3v4"),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ def generate_presigned_put_url(object_key: str) -> str:
|
|||||||
url: str = client.generate_presigned_url(
|
url: str = client.generate_presigned_url(
|
||||||
"put_object",
|
"put_object",
|
||||||
Params={
|
Params={
|
||||||
"Bucket": settings.minio.bucket,
|
"Bucket": settings.s3.bucket,
|
||||||
"Key": object_key,
|
"Key": object_key,
|
||||||
},
|
},
|
||||||
ExpiresIn=300,
|
ExpiresIn=300,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
# SnapLedger Backend Configuration
|
# SnapLedger Backend Configuration
|
||||||
# Copy this file to config.yaml and fill in your credentials.
|
# Copy this file to config.yaml and fill in your credentials.
|
||||||
|
|
||||||
minio:
|
s3:
|
||||||
endpoint: "https://minio.example.com:9000"
|
endpoint: "https://<account-id>.r2.cloudflarestorage.com"
|
||||||
public_endpoint: "https://minio-public.example.com"
|
public_endpoint: ""
|
||||||
bucket: "snapledger"
|
bucket: "snapledger"
|
||||||
access_key: "YOUR_MINIO_ACCESS_KEY"
|
access_key: "YOUR_S3_ACCESS_KEY"
|
||||||
secret_key: "YOUR_MINIO_SECRET_KEY"
|
secret_key: "YOUR_S3_SECRET_KEY"
|
||||||
|
|
||||||
postgresql:
|
postgresql:
|
||||||
host: "localhost"
|
host: "localhost"
|
||||||
|
|||||||
Reference in New Issue
Block a user