| 
														 | 
														 | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														from botocore.client import Config | 
														 | 
														 | 
														from botocore.client import Config | 
													
													
												
													
														 | 
														 | 
														from botocore.exceptions import ClientError | 
														 | 
														 | 
														from botocore.exceptions import ClientError | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														
  | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														from configs import dify_config | 
													
													
												
													
														 | 
														 | 
														from extensions.storage.base_storage import BaseStorage | 
														 | 
														 | 
														from extensions.storage.base_storage import BaseStorage | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														
  | 
													
													
												
													
														 | 
														 | 
														logger = logging.getLogger(__name__) | 
														 | 
														 | 
														logger = logging.getLogger(__name__) | 
													
													
												
											
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														
  | 
													
													
												
													
														 | 
														 | 
														    def __init__(self): | 
														 | 
														 | 
														    def __init__(self): | 
													
													
												
													
														 | 
														 | 
														        super().__init__() | 
														 | 
														 | 
														        super().__init__() | 
													
													
												
													
														 | 
														 | 
														        app_config = self.app.config | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														        self.bucket_name = app_config.get("S3_BUCKET_NAME") | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														        if app_config.get("S3_USE_AWS_MANAGED_IAM"): | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														        self.bucket_name = dify_config.S3_BUCKET_NAME | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														        if dify_config.S3_USE_AWS_MANAGED_IAM: | 
													
													
												
													
														 | 
														 | 
														            logger.info("Using AWS managed IAM role for S3") | 
														 | 
														 | 
														            logger.info("Using AWS managed IAM role for S3") | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														
  | 
													
													
												
													
														 | 
														 | 
														            session = boto3.Session() | 
														 | 
														 | 
														            session = boto3.Session() | 
													
													
												
													
														 | 
														 | 
														            region_name = app_config.get("S3_REGION") | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														            region_name = dify_config.S3_REGION | 
													
													
												
													
														 | 
														 | 
														            self.client = session.client(service_name="s3", region_name=region_name) | 
														 | 
														 | 
														            self.client = session.client(service_name="s3", region_name=region_name) | 
													
													
												
													
														 | 
														 | 
														        else: | 
														 | 
														 | 
														        else: | 
													
													
												
													
														 | 
														 | 
														            logger.info("Using ak and sk for S3") | 
														 | 
														 | 
														            logger.info("Using ak and sk for S3") | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														
  | 
													
													
												
													
														 | 
														 | 
														            self.client = boto3.client( | 
														 | 
														 | 
														            self.client = boto3.client( | 
													
													
												
													
														 | 
														 | 
														                "s3", | 
														 | 
														 | 
														                "s3", | 
													
													
												
													
														 | 
														 | 
														                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"), | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														                config=Config(s3={"addressing_style": app_config.get("S3_ADDRESS_STYLE")}), | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                aws_secret_access_key=dify_config.S3_SECRET_KEY, | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                aws_access_key_id=dify_config.S3_ACCESS_KEY, | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                endpoint_url=dify_config.S3_ENDPOINT, | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                region_name=dify_config.S3_REGION, | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                config=Config(s3={"addressing_style": dify_config.S3_ADDRESS_STYLE}), | 
													
													
												
													
														 | 
														 | 
														            ) | 
														 | 
														 | 
														            ) | 
													
													
												
													
														 | 
														 | 
														        # create bucket | 
														 | 
														 | 
														        # create bucket | 
													
													
												
													
														 | 
														 | 
														        try: | 
														 | 
														 | 
														        try: |