Repository navigation
feat: Add S3 bucket configuration for path-style URL support. #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
6476f4f
38a1b08
d30e9c1
b7403bc
3e342af
23a57b3
2519ffa
78e4b64
b9780c4
6cd6967
cc77594
2c298c6
eade03a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,20 +20,50 @@ | |
|
|
||
| namespace facebook::velox::connector::clp { | ||
|
|
||
| namespace { | ||
| // Detects AWS S3 virtual-hosted style endpoints where bucket is in the | ||
| // hostname. Virtual-hosted: https://<bucket>.s3.<region>.amazonaws.com (returns | ||
| // true) Path-style: https://s3.<region>.amazonaws.com (returns false) | ||
| bool isAwsVirtualHostedStyleEndpoint(const std::string& endpoint) { | ||
| if (endpoint.find("amazonaws.com") == std::string::npos) { | ||
| return false; | ||
| } | ||
|
|
||
| auto schemeEnd = endpoint.find("://"); | ||
| if (schemeEnd == std::string::npos) { | ||
| return false; | ||
| } | ||
|
|
||
| // Virtual-hosted has ".s3." in hostname (bucket.s3.region.amazonaws.com) | ||
| // Path-style starts with "s3." (s3.region.amazonaws.com) | ||
| auto hostPortion = endpoint.substr(schemeEnd + 3); | ||
| return hostPortion.find(".s3.") != std::string::npos; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strengthen virtual-hosted detection to avoid false negatives. The current heuristic requires a scheme and a literal “.s3.” in the host. That misses valid AWS virtual‑hosted endpoints like 🔧 Suggested fix-bool isAwsVirtualHostedStyleEndpoint(const std::string& endpoint) {
- if (endpoint.find("amazonaws.com") == std::string::npos) {
- return false;
- }
-
- auto schemeEnd = endpoint.find("://");
- if (schemeEnd == std::string::npos) {
- return false;
- }
-
- // Virtual-hosted has ".s3." in hostname (bucket.s3.region.amazonaws.com)
- // Path-style starts with "s3." (s3.region.amazonaws.com)
- auto hostPortion = endpoint.substr(schemeEnd + 3);
- return hostPortion.find(".s3.") != std::string::npos;
-}
+bool isAwsVirtualHostedStyleEndpoint(const std::string& endpoint) {
+ // Allow endpoints with or without a scheme.
+ size_t hostStart = endpoint.find("://");
+ hostStart = (hostStart == std::string::npos) ? 0 : hostStart + 3;
+ size_t hostEnd = endpoint.find('/', hostStart);
+ auto hostPort = endpoint.substr(hostStart, hostEnd - hostStart);
+ auto host = hostPort.substr(0, hostPort.find(':'));
+
+ if (host.find("amazonaws.com") == std::string::npos) {
+ return false;
+ }
+
+ auto firstDot = host.find('.');
+ if (firstDot == std::string::npos) {
+ return false;
+ }
+ auto firstLabel = host.substr(0, firstDot);
+ return firstLabel.rfind("s3", 0) != 0;
+}🤖 Prompt for AI Agents |
||
| } // namespace | ||
|
|
||
| std::string ClpPackageS3AuthProvider::constructS3Url( | ||
| std::string_view splitPath) { | ||
| VELOX_CHECK(!splitPath.empty(), "splitPath cannot be empty"); | ||
| return fmt::format("{}/{}", this->endPoint_, splitPath); | ||
| if (bucket_.empty()) { | ||
| return fmt::format("{}/{}", endPoint_, splitPath); | ||
| } | ||
| return fmt::format("{}/{}/{}", endPoint_, bucket_, splitPath); | ||
| } | ||
|
|
||
| bool ClpPackageS3AuthProvider::exportAuthEnvironmentVariables() { | ||
| this->endPoint_ = config_->get<std::string>(kEndPoint, ""); | ||
| VELOX_CHECK( | ||
| !this->endPoint_.empty(), fmt::format("{} cannot be empty", kEndPoint)); | ||
| if ('/' == this->endPoint_.back()) { | ||
| this->endPoint_.pop_back(); | ||
| endPoint_ = config_->get<std::string>(kEndPoint, ""); | ||
| VELOX_CHECK(!endPoint_.empty(), fmt::format("{} cannot be empty", kEndPoint)); | ||
| if ('/' == endPoint_.back()) { | ||
| endPoint_.pop_back(); | ||
| } | ||
|
|
||
| bucket_ = config_->get<std::string>(kBucket, ""); | ||
| VELOX_CHECK( | ||
| bucket_.empty() || !isAwsVirtualHostedStyleEndpoint(endPoint_), | ||
| "{} should not be set when using AWS S3 virtual-hosted style URLs. " | ||
| "The bucket is already part of the endpoint hostname.", | ||
| kBucket); | ||
|
|
||
| auto accessKeyId = config_->get<std::string>(kAccessKeyId, ""); | ||
| auto secretAccessKey = config_->get<std::string>(kSecretAccessKey, ""); | ||
| auto sessionToken = config_->get<std::string>(kSessionToken, ""); | ||
|
|
@@ -42,8 +72,10 @@ bool ClpPackageS3AuthProvider::exportAuthEnvironmentVariables() { | |
| VELOX_CHECK( | ||
| !secretAccessKey.empty(), | ||
| fmt::format("{} cannot be empty", kSecretAccessKey)); | ||
|
|
||
| setEnvironmentVariable(kEnvAwsAccessKeyId, accessKeyId); | ||
| setEnvironmentVariable(kEnvAwsSecretAccessKey, secretAccessKey); | ||
|
|
||
| if (!sessionToken.empty()) { | ||
| setEnvironmentVariable(kEnvAwsSessionToken, sessionToken); | ||
| } else { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.