mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Merge pull request #58148 from yariks5s/fix_s3_regions
S3-links region independency
This commit is contained in:
commit
41c275274b
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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 ®ion)
|
||||
{
|
||||
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.
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user