|
8 | 8 | from abc import ABCMeta, abstractmethod |
9 | 9 | from datetime import datetime |
10 | 10 | from enum import Enum |
| 11 | +from typing import Optional |
11 | 12 |
|
12 | 13 | import boto3 |
13 | 14 | from boto3.s3.transfer import TransferConfig |
| 15 | +from botocore.config import Config |
14 | 16 |
|
15 | 17 | # pylint: disable=unused-import |
16 | 18 | from botocore.exceptions import ClientError as CloudFileNotFoundError |
@@ -110,6 +112,8 @@ class _UserCredential(BaseModel): |
110 | 112 | expiration: datetime |
111 | 113 | secret_access_key: str = Field(alias="secretAccessKey") |
112 | 114 | 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) |
113 | 117 |
|
114 | 118 |
|
115 | 119 | class _S3STSToken(BaseModel): |
@@ -138,14 +142,29 @@ def get_client(self): |
138 | 142 | Get s3 client. |
139 | 143 | :return: |
140 | 144 | """ |
| 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 | + ) |
141 | 156 | # pylint: disable=no-member |
142 | 157 | kwargs = { |
143 | 158 | "region_name": Env.current.aws_region, |
144 | 159 | "aws_access_key_id": self.user_credential.access_key_id, |
145 | 160 | "aws_secret_access_key": self.user_credential.secret_access_key, |
146 | 161 | "aws_session_token": self.user_credential.session_token, |
| 162 | + "config": customize_boto3_config, |
147 | 163 | } |
148 | 164 |
|
| 165 | + if self.user_credential.endpoint is not None: |
| 166 | + kwargs["endpoint_url"] = self.user_credential.endpoint |
| 167 | + |
149 | 168 | if Env.current.s3_endpoint_url is not None: |
150 | 169 | kwargs["endpoint_url"] = Env.current.s3_endpoint_url |
151 | 170 |
|
|
0 commit comments