diff --git a/app/config.py b/app/config.py index 36048a6..adb40bf 100644 --- a/app/config.py +++ b/app/config.py @@ -4,7 +4,7 @@ import yaml from pydantic import BaseModel -class MinioConfig(BaseModel): +class S3Config(BaseModel): endpoint: str public_endpoint: str = "" bucket: str = "snapledger" @@ -32,7 +32,7 @@ class ApiConfig(BaseModel): class AppConfig(BaseModel): - minio: MinioConfig + s3: S3Config postgresql: PostgresConfig api: ApiConfig diff --git a/app/services/minio.py b/app/services/minio.py index e16e0bc..898b612 100644 --- a/app/services/minio.py +++ b/app/services/minio.py @@ -11,9 +11,9 @@ from app.config import settings def _get_client(): return boto3.client( "s3", - endpoint_url=settings.minio.endpoint, - aws_access_key_id=settings.minio.access_key, - aws_secret_access_key=settings.minio.secret_key, + endpoint_url=settings.s3.endpoint, + aws_access_key_id=settings.s3.access_key, + aws_secret_access_key=settings.s3.secret_key, config=BotoConfig(signature_version="s3v4"), ) @@ -33,7 +33,7 @@ def upload_image(file_bytes: bytes, original_filename: str) -> str: content_type = "image/png" client.put_object( - Bucket=settings.minio.bucket, + Bucket=settings.s3.bucket, Key=object_key, Body=file_bytes, ContentType=content_type, @@ -43,12 +43,12 @@ def upload_image(file_bytes: bytes, original_filename: str) -> str: def _get_presign_client(): """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( "s3", endpoint_url=endpoint, - aws_access_key_id=settings.minio.access_key, - aws_secret_access_key=settings.minio.secret_key, + aws_access_key_id=settings.s3.access_key, + aws_secret_access_key=settings.s3.secret_key, config=BotoConfig(signature_version="s3v4"), ) @@ -58,7 +58,7 @@ def generate_presigned_put_url(object_key: str) -> str: url: str = client.generate_presigned_url( "put_object", Params={ - "Bucket": settings.minio.bucket, + "Bucket": settings.s3.bucket, "Key": object_key, }, ExpiresIn=300, diff --git a/config.example.yaml b/config.example.yaml index 9a30bd8..79ac0e4 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -1,12 +1,12 @@ # SnapLedger Backend Configuration # Copy this file to config.yaml and fill in your credentials. -minio: - endpoint: "https://minio.example.com:9000" - public_endpoint: "https://minio-public.example.com" +s3: + endpoint: "https://.r2.cloudflarestorage.com" + public_endpoint: "" bucket: "snapledger" - access_key: "YOUR_MINIO_ACCESS_KEY" - secret_key: "YOUR_MINIO_SECRET_KEY" + access_key: "YOUR_S3_ACCESS_KEY" + secret_key: "YOUR_S3_SECRET_KEY" postgresql: host: "localhost"