Skip to content

Commit

Permalink
rohmu/s3: support connectivity through proxies
Browse files Browse the repository at this point in the history
Extend proxy support to s3 driver as well. Socks support requires
botocore with boto/botocore#2081 merged.
  • Loading branch information
hnousiainen authored and rdunklau committed Apr 27, 2022
1 parent 6109d4f commit aa0bec6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion rohmu/object_storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time

import botocore.client
import botocore.config
import botocore.exceptions
import botocore.session

Expand Down Expand Up @@ -43,16 +44,34 @@ def __init__(
is_secure=False,
is_verify_tls=False,
segment_size=MULTIPART_CHUNK_SIZE,
encrypted=False
encrypted=False,
proxy_info=None
):
super().__init__(prefix=prefix)
botocore_session = botocore.session.get_session()
self.bucket_name = bucket_name
self.location = ""
self.region = region
if not host or not port:
custom_config = {}
if proxy_info:
username = proxy_info.get("user")
password = proxy_info.get("pass")
if username and password:
auth = f"{username}:{password}@"
else:
auth = ""
host = proxy_info["host"]
port = proxy_info["port"]
if proxy_info.get("type") == "socks5":
schema = "socks5"
else:
schema = "http"
proxy_url = f"{schema}://{auth}{host}:{port}"
custom_config["proxies"] = {"https": proxy_url}
self.s3_client = botocore_session.create_client(
"s3",
config=botocore.config.Config(**custom_config),
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
region_name=region,
Expand Down

0 comments on commit aa0bec6

Please sign in to comment.