diff --git a/programs/server/config.xml b/programs/server/config.xml index b8a6ac3cd5b..38eceb083dd 100644 --- a/programs/server/config.xml +++ b/programs/server/config.xml @@ -93,13 +93,13 @@ - .s3.amazonaws.com + https://{bucket}.s3.amazonaws.com - .storage.googleapis.com + https://{bucket}.storage.googleapis.com - .oss.aliyuncs.com + https://{bucket}.oss.aliyuncs.com diff --git a/src/Common/Macros.cpp b/src/Common/Macros.cpp index f43fed6c499..e9a7053bb01 100644 --- a/src/Common/Macros.cpp +++ b/src/Common/Macros.cpp @@ -36,6 +36,13 @@ Macros::Macros(const Poco::Util::AbstractConfiguration & config, const String & } } +Macros::Macros(const String & key, const String & value) +{ + macros[key] = value; + if (key == "database" || key == "table" || key == "uuid") + enable_special_macros = false; +} + String Macros::expand(const String & s, MacroExpansionInfo & info) const { diff --git a/src/Common/Macros.h b/src/Common/Macros.h index d403f5d2cee..42c22afe0ba 100644 --- a/src/Common/Macros.h +++ b/src/Common/Macros.h @@ -27,6 +27,7 @@ class Macros public: Macros() = default; Macros(const Poco::Util::AbstractConfiguration & config, const String & key, Poco::Logger * log = nullptr); + Macros(const String & key, const String & value); struct MacroExpansionInfo { diff --git a/src/IO/S3/URI.cpp b/src/IO/S3/URI.cpp index 794f3b5af3a..d01bbe4bb55 100644 --- a/src/IO/S3/URI.cpp +++ b/src/IO/S3/URI.cpp @@ -1,5 +1,7 @@ #include #include +#include "Common/Macros.h" +#include #include #if USE_AWS_S3 #include @@ -23,13 +25,8 @@ struct URIConverter { static void modifyURI(Poco::URI & uri, std::unordered_map mapper) { - if (uri.getScheme() == "s3" || uri.getScheme() == "oss" || uri.getScheme() == "gs") - { - uri.setHost(uri.getHost() + mapper[uri.getScheme()]); - uri.setScheme("https"); - } - else if (!mapper["nc_s3"].empty()) /// Case for tests - uri = Poco::URI(mapper["nc_s3"] + "/" + uri.getHost() + uri.getPath()); + Macros macros("bucket", uri.getHost()); + uri = Poco::URI(macros.expand(mapper[uri.getScheme()]) + "/" + uri.getPathAndQuery()); } }; @@ -71,13 +68,13 @@ URI::URI(const std::string & uri_) std::vector config_keys; config->keys("url_scheme_mappers", config_keys); for (const std::string & config_key : config_keys) - mapper[config_key] = config->getString("url_scheme_mappers." + config_key + ".domain"); + mapper[config_key] = config->getString("url_scheme_mappers." + config_key + ".to"); } else { - mapper["s3"] = ".s3.amazonaws.com"; - mapper["gs"] = ".storage.googleapis.com"; - mapper["oss"] = ".oss.aliyuncs.com"; + mapper["s3"] = "https://{bucket}.s3.amazonaws.com"; + mapper["gs"] = "https://{bucket}.storage.googleapis.com"; + mapper["oss"] = "https://{bucket}.oss.aliyuncs.com"; } if (!mapper.empty()) diff --git a/tests/integration/test_s3_style_link/configs/config.d/minio.xml b/tests/integration/test_s3_style_link/configs/config.d/minio.xml index bed7e737745..072d07b7f73 100644 --- a/tests/integration/test_s3_style_link/configs/config.d/minio.xml +++ b/tests/integration/test_s3_style_link/configs/config.d/minio.xml @@ -3,8 +3,8 @@ - - http://minio1:9001/root - + + http://minio1:9001/root/{bucket} +