Merge pull request #58148 from yariks5s/fix_s3_regions

S3-links region independency
This commit is contained in:
Yarik Briukhovetskyi 2023-12-26 12:59:00 +01:00 committed by GitHub
commit 41c275274b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 0 deletions

View File

@ -574,6 +574,9 @@ Client::doRequest(RequestType & request, RequestFn request_fn) const
if (!new_uri)
return result;
if (initial_endpoint.substr(11) == "amazonaws.com") // Check if user didn't mention any region
new_uri->addRegionToURI(request.getRegionOverride());
const auto & current_uri_override = request.getURIOverride();
/// we already tried with this URI
if (current_uri_override && current_uri_override->uri == new_uri->uri)

View File

@ -58,6 +58,11 @@ public:
return BaseRequest::GetChecksumAlgorithmName();
}
std::string getRegionOverride() const
{
return region_override;
}
void overrideRegion(std::string region) const
{
region_override = std::move(region);

View File

@ -146,6 +146,12 @@ URI::URI(const std::string & uri_)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Bucket or key name are invalid in S3 URI.");
}
void URI::addRegionToURI(const std::string &region)
{
if (auto pos = endpoint.find("amazonaws.com"); pos != std::string::npos)
endpoint = endpoint.substr(0, pos) + region + "." + endpoint.substr(pos);
}
void URI::validateBucket(const String & bucket, const Poco::URI & uri)
{
/// S3 specification requires at least 3 and at most 63 characters in bucket name.

View File

@ -32,6 +32,7 @@ struct URI
URI() = default;
explicit URI(const std::string & uri_);
void addRegionToURI(const std::string & region);
static void validateBucket(const std::string & bucket, const Poco::URI & uri);
};