pitrou commented on code in PR #50044:
URL: https://github.com/apache/arrow/pull/50044#discussion_r3412595902
##########
cpp/src/arrow/filesystem/s3fs_test.cc:
##########
@@ -398,6 +398,92 @@ TEST_F(S3OptionsTest, FromAccessKey) {
ASSERT_EQ(options.GetSessionToken(), "token");
}
+TEST_F(S3OptionsTest, FromUriAndOptionsCredentials) {
+ std::string path;
+ S3Options options;
+ FileSystemFactoryOptions kv{
+ {"access_key", std::string("ak")},
+ {"secret_key", std::string("sk")},
+ };
+ ASSERT_OK_AND_ASSIGN(options, S3Options::FromUriAndOptions("s3://", kv,
&path));
+ ASSERT_EQ(options.GetAccessKey(), "ak");
+ ASSERT_EQ(options.GetSecretKey(), "sk");
+ ASSERT_EQ(options.GetSessionToken(), "");
+
+ kv.push_back({"session_token", std::string("tok")});
+ ASSERT_OK_AND_ASSIGN(options, S3Options::FromUriAndOptions("s3://", kv,
&path));
+ ASSERT_EQ(options.GetAccessKey(), "ak");
+ ASSERT_EQ(options.GetSecretKey(), "sk");
+ ASSERT_EQ(options.GetSessionToken(), "tok");
+
+ // Failure scenarios
+ // Pairing is correct
Review Comment:
```suggestion
// Pairing is incorrect
```
##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -327,7 +327,68 @@ S3Options S3Options::FromAssumeRoleWithWebIdentity() {
}
Result<S3Options> S3Options::FromUri(const Uri& uri, std::string* out_path) {
- S3Options options;
+ return FromUriAndOptions(uri, FileSystemFactoryOptions{}, out_path);
+}
+
+Result<S3Options> S3Options::FromUri(const std::string& uri_string,
+ std::string* out_path) {
+ Uri uri;
+ RETURN_NOT_OK(uri.Parse(uri_string));
+ return FromUri(uri, out_path);
+}
+
+namespace {
+
+template <typename T>
Review Comment:
These can probably be exposed as internal helpers, for example in
`filesystem/util_internal.h`?
##########
cpp/src/arrow/filesystem/s3fs_test.cc:
##########
@@ -398,6 +398,92 @@ TEST_F(S3OptionsTest, FromAccessKey) {
ASSERT_EQ(options.GetSessionToken(), "token");
}
+TEST_F(S3OptionsTest, FromUriAndOptionsCredentials) {
+ std::string path;
+ S3Options options;
+ FileSystemFactoryOptions kv{
+ {"access_key", std::string("ak")},
+ {"secret_key", std::string("sk")},
+ };
+ ASSERT_OK_AND_ASSIGN(options, S3Options::FromUriAndOptions("s3://", kv,
&path));
+ ASSERT_EQ(options.GetAccessKey(), "ak");
+ ASSERT_EQ(options.GetSecretKey(), "sk");
+ ASSERT_EQ(options.GetSessionToken(), "");
+
+ kv.push_back({"session_token", std::string("tok")});
+ ASSERT_OK_AND_ASSIGN(options, S3Options::FromUriAndOptions("s3://", kv,
&path));
+ ASSERT_EQ(options.GetAccessKey(), "ak");
+ ASSERT_EQ(options.GetSecretKey(), "sk");
+ ASSERT_EQ(options.GetSessionToken(), "tok");
+
+ // Failure scenarios
+ // Pairing is correct
+ ASSERT_THAT(
+ S3Options::FromUriAndOptions("s3://", {{"access_key",
std::string("ak")}}, &path),
+ Raises(StatusCode::Invalid, ::testing::HasSubstr("must be provided
together")));
+ ASSERT_THAT(
+ S3Options::FromUriAndOptions("s3://", {{"session_token",
std::string("tok")}},
+ &path),
+ Raises(StatusCode::Invalid, ::testing::HasSubstr("session_token'
requires")));
+ // unknown option key
+ ASSERT_THAT(S3Options::FromUriAndOptions("s3://", {{"bogus",
std::string("x")}}, &path),
+ Raises(StatusCode::Invalid, ::testing::HasSubstr("Unexpected
option")));
+ // const char* is rejected. Options must be an explicit std::string
+ ASSERT_THAT(S3Options::FromUriAndOptions("s3://", {{"access_key", "42"}},
&path),
+ Raises(StatusCode::Invalid, ::testing::HasSubstr("wrong type")));
+}
+
+TEST_F(S3OptionsTest, FromUriAndOptionsCredentialPrecedence) {
+ std::string path;
+ S3Options options;
+ // options override URI userinfo when not empty
Review Comment:
Instead of overriding, can we perhaps emit an error when the same info is
provided through both means? Or perhaps only if the values are unequal?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]