Skip to content

Commit

Permalink
Use S3 dualstack endpoint by default
Browse files Browse the repository at this point in the history
When using the default S3 endpoints, request using dualstack
IPv4/IPv6 endpoints by default. This behavior can be disabled by
configuring S3 with use_dualstack_endpoints as false.
  • Loading branch information
hnousiainen committed Mar 26, 2024
1 parent 0a958d3 commit 451b588
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions rohmu/object_storage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class S3ObjectStorageConfig(StorageModel):
connect_timeout: Optional[str] = None
read_timeout: Optional[str] = None
aws_session_token: Optional[str] = Field(None, repr=False)
use_dualstack_endpoint: Optional[bool] = True
storage_type: Literal[StorageDriver.s3] = StorageDriver.s3

@root_validator(skip_on_failure=True)
Expand Down
3 changes: 3 additions & 0 deletions rohmu/object_storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(
read_timeout: Optional[float] = None,
notifier: Optional[Notifier] = None,
aws_session_token: Optional[str] = None,
use_dualstack_endpoint: Optional[bool] = True,
statsd_info: Optional[StatsdConfig] = None,
) -> None:
super().__init__(prefix=prefix, notifier=notifier, statsd_info=statsd_info)
Expand All @@ -137,6 +138,8 @@ def __init__(
if proxy_info:
proxy_url = get_proxy_url(proxy_info)
custom_config["proxies"] = {"https": proxy_url}
if use_dualstack_endpoint is True:
custom_config["use_dualstack_endpoint"] = True
self.s3_client = create_s3_client(
session=session,
config=botocore.config.Config(**custom_config),
Expand Down
5 changes: 4 additions & 1 deletion test/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def test_get_transfer_s3(
) -> None:
expected_config_arg = dict(config)
expected_config_arg.pop("notifier")
expected_botocore_config = {"proxies": {"https": "socks5://bob:[email protected]:16666"}}
expected_botocore_config = {
"proxies": {"https": "socks5://bob:[email protected]:16666"},
"use_dualstack_endpoint": True,
}
mock_config_model.return_value = S3ObjectStorageConfig(**expected_config_arg)

transfer_object = get_transfer(config)
Expand Down

0 comments on commit 451b588

Please sign in to comment.