From 40807e8edf1af3da9df0cbed7ea365ffdc825735 Mon Sep 17 00:00:00 2001 From: Leo Q Date: Fri, 22 Mar 2024 01:12:38 +0000 Subject: [PATCH 1/2] Add S3_ADDRESS_STYLE configuration option --- api/config.py | 2 ++ api/extensions/ext_storage.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api/config.py b/api/config.py index 61ccdfee7b0b1..55eabab94d485 100644 --- a/api/config.py +++ b/api/config.py @@ -22,6 +22,7 @@ 'SERVICE_API_URL': 'https://api.dify.ai', 'APP_WEB_URL': 'https://udify.app', 'FILES_URL': '', + 'S3_ADDRESS_STYLE': 'auto', 'STORAGE_TYPE': 'local', 'STORAGE_LOCAL_PATH': 'storage', 'CHECK_UPDATE_URL': 'https://updates.dify.ai', @@ -180,6 +181,7 @@ def __init__(self): self.S3_ACCESS_KEY = get_env('S3_ACCESS_KEY') self.S3_SECRET_KEY = get_env('S3_SECRET_KEY') self.S3_REGION = get_env('S3_REGION') + self.S3_ADDRESS_STYLE = get_env('S3_ADDRESS_STYLE') self.AZURE_BLOB_ACCOUNT_NAME = get_env('AZURE_BLOB_ACCOUNT_NAME') self.AZURE_BLOB_ACCOUNT_KEY = get_env('AZURE_BLOB_ACCOUNT_KEY') self.AZURE_BLOB_CONTAINER_NAME = get_env('AZURE_BLOB_CONTAINER_NAME') diff --git a/api/extensions/ext_storage.py b/api/extensions/ext_storage.py index 497ce5d2b7840..f28086de0f436 100644 --- a/api/extensions/ext_storage.py +++ b/api/extensions/ext_storage.py @@ -8,6 +8,7 @@ import boto3 from azure.storage.blob import AccountSasPermissions, BlobServiceClient, ResourceTypes, generate_account_sas from botocore.exceptions import ClientError +from botocore.client import Config from flask import Flask @@ -27,7 +28,8 @@ def init_app(self, app: Flask): aws_secret_access_key=app.config.get('S3_SECRET_KEY'), aws_access_key_id=app.config.get('S3_ACCESS_KEY'), endpoint_url=app.config.get('S3_ENDPOINT'), - region_name=app.config.get('S3_REGION') + region_name=app.config.get('S3_REGION'), + config=Config(s3={'addressing_style': app.config.get('S3_ADDRESS_STYLE')}) ) elif self.storage_type == 'azure-blob': self.bucket_name = app.config.get('AZURE_BLOB_CONTAINER_NAME') From abed56a624b9eec3fed1a2bb16a8749c0b5d62e0 Mon Sep 17 00:00:00 2001 From: Leo Q Date: Mon, 25 Mar 2024 10:16:55 +0800 Subject: [PATCH 2/2] Fix lint error --- api/extensions/ext_storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/extensions/ext_storage.py b/api/extensions/ext_storage.py index f28086de0f436..3a8e314d9273f 100644 --- a/api/extensions/ext_storage.py +++ b/api/extensions/ext_storage.py @@ -7,8 +7,8 @@ import boto3 from azure.storage.blob import AccountSasPermissions, BlobServiceClient, ResourceTypes, generate_account_sas -from botocore.exceptions import ClientError from botocore.client import Config +from botocore.exceptions import ClientError from flask import Flask