Merge pull request #10763 from w41ter/fix_8882

Fix guess region from s3 URL
This commit is contained in:
Jingyu Zhou 2023-08-22 22:24:21 -07:00 committed by GitHub
commit 2a616b3866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -186,13 +186,12 @@ std::string guessRegionFromDomain(std::string domain) {
const char* service = knownServices[i];
std::size_t p = domain.find(service);
if (p == std::string::npos || (p >= 1 && domain[p - 1] != '.')) {
// eg. 127.0.0.1, example.com, s3-service.example.com, mys3.example.com
continue;
}
StringRef h(domain.c_str() + p);
StringRef h = StringRef(domain).substr(p);
if (!h.startsWith("oss-"_sr)) {
h.eat(service); // ignore s3 service
@ -1886,3 +1885,15 @@ TEST_CASE("/backup/s3/v4headers") {
return Void();
}
TEST_CASE("/backup/s3/guess_region") {
std::string url = "blobstore://s3.us-west-2.amazonaws.com/resource_name?bucket=bucket_name&sa=1";
std::string resource;
std::string error;
S3BlobStoreEndpoint::ParametersT parameters;
Reference<S3BlobStoreEndpoint> s3 = S3BlobStoreEndpoint::fromString(url, {}, &resource, &error, &parameters);
ASSERT(s3->getRegion() == "us-west-2");
return Void();
}