Skip to content

Commit 1362122

Browse files
messensepitrou
andauthored
apacheGH-38663: [C++] Add support for service-specific endpoint for S3 using AWS_ENDPOINT_URL_S3 (apache#39160)
### Rationale for this change See apache#38663 ### What changes are included in this PR? set variable `endpoint_override` according the environment variable, prefer service-specific endpoint url over global endpoint url. ### Are these changes tested? unittest ### Are there any user-facing changes? No * Closes: apache#38663 Lead-authored-by: messense <[email protected]> Co-authored-by: Antoine Pitrou <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent 48f704e commit 1362122

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

cpp/src/arrow/filesystem/s3fs.cc

+10-3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ using internal::ToURLEncodedAwsString;
156156

157157
static const char kSep = '/';
158158
constexpr char kAwsEndpointUrlEnvVar[] = "AWS_ENDPOINT_URL";
159+
constexpr char kAwsEndpointUrlS3EnvVar[] = "AWS_ENDPOINT_URL_S3";
159160

160161
// -----------------------------------------------------------------------
161162
// S3ProxyOptions implementation
@@ -366,9 +367,15 @@ Result<S3Options> S3Options::FromUri(const Uri& uri, std::string* out_path) {
366367
} else {
367368
options.ConfigureDefaultCredentials();
368369
}
369-
auto endpoint_env = arrow::internal::GetEnvVar(kAwsEndpointUrlEnvVar);
370-
if (endpoint_env.ok()) {
371-
options.endpoint_override = *endpoint_env;
370+
// Prefer AWS service-specific endpoint url
371+
auto s3_endpoint_env = arrow::internal::GetEnvVar(kAwsEndpointUrlS3EnvVar);
372+
if (s3_endpoint_env.ok()) {
373+
options.endpoint_override = *s3_endpoint_env;
374+
} else {
375+
auto endpoint_env = arrow::internal::GetEnvVar(kAwsEndpointUrlEnvVar);
376+
if (endpoint_env.ok()) {
377+
options.endpoint_override = *endpoint_env;
378+
}
372379
}
373380

374381
bool region_set = false;

cpp/src/arrow/filesystem/s3fs_test.cc

+5
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ TEST_F(S3OptionsTest, FromUri) {
303303
ASSERT_RAISES(Invalid, S3Options::FromUri("s3://mybucket/?xxx=zzz", &path));
304304

305305
// Endpoint from environment variable
306+
{
307+
EnvVarGuard endpoint_guard("AWS_ENDPOINT_URL_S3", "http://127.0.0.1:9000");
308+
ASSERT_OK_AND_ASSIGN(options, S3Options::FromUri("s3://mybucket/", &path));
309+
ASSERT_EQ(options.endpoint_override, "http://127.0.0.1:9000");
310+
}
306311
{
307312
EnvVarGuard endpoint_guard("AWS_ENDPOINT_URL", "http://127.0.0.1:9000");
308313
ASSERT_OK_AND_ASSIGN(options, S3Options::FromUri("s3://mybucket/", &path));

docs/source/cpp/env_vars.rst

+7
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ that changing their value later will have an effect.
163163
.. envvar:: AWS_ENDPOINT_URL
164164

165165
Endpoint URL used for S3-like storage, for example Minio or s3.scality.
166+
Alternatively, one can set :envvar:`AWS_ENDPOINT_URL_S3`.
167+
168+
.. envvar:: AWS_ENDPOINT_URL_S3
169+
170+
Endpoint URL used for S3-like storage, for example Minio or s3.scality.
171+
This takes precedence over :envvar:`AWS_ENDPOINT_URL` if both variables
172+
are set.
166173

167174
.. envvar:: GANDIVA_CACHE_SIZE
168175

0 commit comments

Comments
 (0)