Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions flow360/cloud/s3_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from abc import ABCMeta, abstractmethod
from datetime import datetime
from enum import Enum
from typing import Optional

import boto3
from boto3.s3.transfer import TransferConfig
from botocore.config import Config

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


class _S3STSToken(BaseModel):
Expand Down Expand Up @@ -138,14 +142,29 @@ def get_client(self):
Get s3 client.
:return:
"""
customize_boto3_config = None
if (
self.user_credential.storage_provider is not None
and self.user_credential.storage_provider == "OSS"
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded string "OSS" should be defined as a constant to improve maintainability and prevent typos. Consider defining OSS_STORAGE_PROVIDER = "OSS" at the module level.

Suggested change
and self.user_credential.storage_provider == "OSS"
and self.user_credential.storage_provider == OSS_STORAGE_PROVIDER

Copilot uses AI. Check for mistakes.

):
# OSS does not support aws integrity check
customize_boto3_config = Config(
request_checksum_calculation="when_required",
response_checksum_validation="when_required",
s3={"addressing_style": "virtual"},
)
# pylint: disable=no-member
kwargs = {
"region_name": Env.current.aws_region,
"aws_access_key_id": self.user_credential.access_key_id,
"aws_secret_access_key": self.user_credential.secret_access_key,
"aws_session_token": self.user_credential.session_token,
"config": customize_boto3_config,
}

if self.user_credential.endpoint is not None:
kwargs["endpoint_url"] = self.user_credential.endpoint

if Env.current.s3_endpoint_url is not None:
kwargs["endpoint_url"] = Env.current.s3_endpoint_url

Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The endpoint URL assignment logic has a potential issue. If both self.user_credential.endpoint and Env.current.s3_endpoint_url are set, the environment variable will overwrite the user credential endpoint without any indication. Consider either documenting this precedence or adding a warning when both are present.

Suggested change
if self.user_credential.endpoint is not None:
log.warning(
"Both user credential endpoint (%s) and environment S3 endpoint (%s) are set. "
"Environment S3 endpoint will take precedence.",
self.user_credential.endpoint,
Env.current.s3_endpoint_url,
)
kwargs["endpoint_url"] = Env.current.s3_endpoint_url

Copilot uses AI. Check for mistakes.

Expand Down
Loading