Skip to content

Commit a9acc4e

Browse files
Travis Wrightsmanmaga-imi
andauthored
feat(grz-common): Add proxy options to config (#335)
Co-authored-by: maga-imi <matthias.ganzinger@med.uni-heidelberg.de>
1 parent 5d302f9 commit a9acc4e

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

packages/grz-common/src/grz_common/models/s3.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
from .base import IgnoringBaseModel, IgnoringBaseSettings
66

77

8+
class ProxyOptions(IgnoringBaseModel):
9+
proxy_ca_bundle: str | None = None
10+
"""
11+
The path to a custom certificate bundle to use when establishing SSL/TLS connections with proxy (optional).
12+
"""
13+
14+
proxy_client_cert: str | None = None
15+
"""
16+
The path to a certificate for proxy TLS client authentication (optional).
17+
"""
18+
19+
proxy_use_forwarding_for_https: bool = False
20+
"""
21+
For HTTPS proxies, forward your requests to HTTPS destinations with an absolute URI. We strongly recommend you only use this option with trusted or corporate proxies.
22+
"""
23+
24+
825
class S3Options(IgnoringBaseModel):
926
endpoint_url: AnyHttpUrl
1027
"""
@@ -53,6 +70,9 @@ class S3Options(IgnoringBaseModel):
5370
The proxy URL for S3 operations (optional).
5471
"""
5572

73+
proxy_config: ProxyOptions | None = None
74+
"""Proxy configuration for S3 operations."""
75+
5676
request_checksum_calculation: Literal["when_supported", "when_required"] | None = None
5777
"""
5878
Whether to calculate checksums for S3 request payloads (optional).

packages/grz-common/src/grz_common/transfer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import boto3
88
from boto3 import client as boto3_client # type: ignore[import-untyped]
9-
from botocore.config import Config as Boto3Config # type: ignore[import-untyped]
9+
from botocore.config import Config as Boto3Config
1010

1111
if TYPE_CHECKING:
1212
from types_boto3_s3 import S3Client
@@ -31,8 +31,10 @@ def init_s3_client(s3_options: S3Options) -> S3Client:
3131
"""Create a boto3 Client from a grz-cli configuration."""
3232
# configure proxies if proxy_url is defined
3333
proxy_url = s3_options.proxy_url
34+
proxies_config = s3_options.proxy_config.model_dump(exclude_none=True) if s3_options.proxy_config else None
3435
s3_config = Boto3Config(
3536
proxies={"http": str(proxy_url), "https": str(proxy_url)} if proxy_url is not None else None,
37+
proxies_config=proxies_config, # type: ignore
3638
request_checksum_calculation=s3_options.request_checksum_calculation,
3739
)
3840

@@ -55,8 +57,10 @@ def init_s3_client(s3_options: S3Options) -> S3Client:
5557
def init_s3_resource(s3_options: S3Options) -> S3ServiceResource:
5658
"""Create a boto3 Resource from a grz-cli configuration."""
5759
proxy_url = s3_options.proxy_url
60+
proxies_config = s3_options.proxy_config.model_dump(exclude_none=True) if s3_options.proxy_config else None
5861
s3_config = Boto3Config(
5962
proxies={"http": str(proxy_url), "https": str(proxy_url)} if proxy_url is not None else None,
63+
proxies_config=proxies_config, # type: ignore
6064
request_checksum_calculation=s3_options.request_checksum_calculation,
6165
)
6266
s3_resource = boto3.resource(

0 commit comments

Comments
 (0)