Skip to content

Commit ceb2fff

Browse files
committed
feat(): add customize boto core config for OSS storage provider
1 parent 83f0f31 commit ceb2fff

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

flow360/cloud/s3_utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
from abc import ABCMeta, abstractmethod
99
from datetime import datetime
1010
from enum import Enum
11+
from typing import Optional
1112

1213
import boto3
1314
from boto3.s3.transfer import TransferConfig
15+
from botocore.config import Config
1416

1517
# pylint: disable=unused-import
1618
from botocore.exceptions import ClientError as CloudFileNotFoundError
@@ -110,6 +112,8 @@ class _UserCredential(BaseModel):
110112
expiration: datetime
111113
secret_access_key: str = Field(alias="secretAccessKey")
112114
session_token: str = Field(alias="sessionToken")
115+
endpoint: Optional[str] = Field(alias="endpoint", default=None)
116+
storage_provider: Optional[str] = Field(alias="storageProvider", default=None)
113117

114118

115119
class _S3STSToken(BaseModel):
@@ -138,14 +142,29 @@ def get_client(self):
138142
Get s3 client.
139143
:return:
140144
"""
145+
customize_boto3_config = None
146+
if (
147+
self.user_credential.storage_provider is not None
148+
and self.user_credential.storage_provider == "OSS"
149+
):
150+
# OSS does not support aws integrity check
151+
customize_boto3_config = Config(
152+
request_checksum_calculation="when_required",
153+
response_checksum_validation="when_required",
154+
s3={"addressing_style": "virtual"},
155+
)
141156
# pylint: disable=no-member
142157
kwargs = {
143158
"region_name": Env.current.aws_region,
144159
"aws_access_key_id": self.user_credential.access_key_id,
145160
"aws_secret_access_key": self.user_credential.secret_access_key,
146161
"aws_session_token": self.user_credential.session_token,
162+
"config": customize_boto3_config,
147163
}
148164

165+
if self.user_credential.endpoint is not None:
166+
kwargs["endpoint_url"] = self.user_credential.endpoint
167+
149168
if Env.current.s3_endpoint_url is not None:
150169
kwargs["endpoint_url"] = Env.current.s3_endpoint_url
151170

0 commit comments

Comments
 (0)