Skip to content

Commit d007355

Browse files
committed
feat(stream_io): Support the use_https flag in .s3cfg
1 parent 9690542 commit d007355

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

tensorizer/stream_io.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class _ParsedCredentials(typing.NamedTuple):
5858
s3_endpoint: Optional[str]
5959
s3_access_key: Optional[str]
6060
s3_secret_key: Optional[str]
61+
use_https: Optional[bool]
6162

6263

6364
@functools.lru_cache(maxsize=None)
@@ -106,16 +107,24 @@ def _get_s3cfg_values(
106107
if config.read((config_path,)):
107108
break
108109
else:
109-
return _ParsedCredentials(None, None, None, None)
110+
return _ParsedCredentials(None, None, None, None, None)
110111

111112
if "default" not in config:
112113
raise ValueError(f"No default section in {config_path}")
113114

115+
use_https = config["default"].get("use_https")
116+
if use_https == "True":
117+
use_https = True
118+
elif use_https == "False":
119+
use_https = False
120+
else:
121+
use_https = None
114122
return _ParsedCredentials(
115123
config_file=os.fsdecode(config_path),
116124
s3_endpoint=config["default"].get("host_base"),
117125
s3_access_key=config["default"].get("access_key"),
118126
s3_secret_key=config["default"].get("secret_key"),
127+
use_https=use_https,
119128
)
120129

121130

@@ -1124,6 +1133,7 @@ def _infer_credentials(
11241133
s3_endpoint=None,
11251134
s3_access_key=s3_access_key_id,
11261135
s3_secret_key=s3_secret_access_key,
1136+
use_https=None,
11271137
)
11281138

11291139
# Try to find default credentials if at least one is not specified
@@ -1172,6 +1182,7 @@ def _infer_credentials(
11721182
s3_endpoint=parsed.s3_endpoint,
11731183
s3_access_key=s3_access_key_id,
11741184
s3_secret_key=s3_secret_access_key,
1185+
use_https=parsed.use_https,
11751186
)
11761187

11771188

@@ -1220,7 +1231,7 @@ def open_stream(
12201231
s3_endpoint: Optional[str] = None,
12211232
s3_config_path: Optional[Union[str, bytes, os.PathLike]] = None,
12221233
buffer_size: Optional[int] = None,
1223-
force_http: bool = False,
1234+
force_http: Optional[bool] = None,
12241235
*,
12251236
begin: Optional[int] = None,
12261237
end: Optional[int] = None,
@@ -1387,6 +1398,9 @@ def open_stream(
13871398
# Not required to have been found,
13881399
# and doesn't overwrite an explicitly specified endpoint.
13891400
s3_endpoint = s3_endpoint or s3.s3_endpoint
1401+
1402+
if force_http is None and s3.use_https is not None:
1403+
force_http = not s3.use_https
13901404
except (ValueError, FileNotFoundError):
13911405
# TODO: Reimplement this logic somewhere in s3_download
13921406
#
@@ -1407,6 +1421,9 @@ def open_stream(
14071421
# )
14081422
pass
14091423

1424+
if force_http is None:
1425+
force_http = False
1426+
14101427
# Regardless of whether the config needed to be parsed,
14111428
# the endpoint gets a default value based on the operation.
14121429

0 commit comments

Comments
 (0)