From 6a90eb4b4728ac6c56f27e9d3794c5c5f5893a16 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Thu, 17 Oct 2024 16:41:52 +0200 Subject: [PATCH] Add s3_url_compatibility_mode to create_secret_functions --- extension/httpfs/create_secret_functions.cpp | 23 ++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/extension/httpfs/create_secret_functions.cpp b/extension/httpfs/create_secret_functions.cpp index bcfdd82c3115..5fb8ec30b9ac 100644 --- a/extension/httpfs/create_secret_functions.cpp +++ b/extension/httpfs/create_secret_functions.cpp @@ -39,6 +39,7 @@ unique_ptr CreateS3SecretFunctions::CreateSecretFunctionInternal(Cli secret->secret_map["url_style"] = "path"; } + idx_t url_compatibility = -1; // apply any overridden settings for (const auto &named_param : input.options) { auto lower_name = StringUtil::Lower(named_param.first); @@ -66,14 +67,31 @@ unique_ptr CreateS3SecretFunctions::CreateSecretFunctionInternal(Cli throw InvalidInputException("Invalid type past to secret option: '%s', found '%s', expected: 'BOOLEAN'", lower_name, named_param.second.type().ToString()); } - secret->secret_map["url_compatibility_mode"] = Value::BOOLEAN(named_param.second.GetValue()); + const bool v = named_param.second.GetValue(); + if (url_compatibility == -1) { + url_compatibility = v; + } else if (url_compatibility != v) { + throw InvalidInputException("Mismatched values of [s3_]url_compatibility_mode setting. Consider removing the secret."); + } + secret->secret_map["url_compatibility_mode"] = Value::BOOLEAN(v); + } else if (lower_name == "s3_url_compatibility_mode") { + if (named_param.second.type() != LogicalType::BOOLEAN) { + throw InvalidInputException("Invalid type past to secret option: '%s', found '%s', expected: 'BOOLEAN'", + lower_name, named_param.second.type().ToString()); + } + const bool v = named_param.second.GetValue(); + if (url_compatibility == -1) { + url_compatibility = v; + } else if (url_compatibility != v) { + throw InvalidInputException("Mismatched values of [s3_]url_compatibility_mode setting. Consider removing the secret."); + } + secret->secret_map["s3_url_compatibility_mode"] = Value::BOOLEAN(v); } else if (lower_name == "account_id") { continue; // handled already } else { throw InternalException("Unknown named parameter passed to CreateSecretFunctionInternal: " + lower_name); } } - return std::move(secret); } @@ -91,6 +109,7 @@ void CreateS3SecretFunctions::SetBaseNamedParams(CreateSecretFunction &function, function.named_parameters["url_style"] = LogicalType::VARCHAR; function.named_parameters["use_ssl"] = LogicalType::BOOLEAN; function.named_parameters["url_compatibility_mode"] = LogicalType::BOOLEAN; + function.named_parameters["s3_url_compatibility_mode"] = LogicalType::BOOLEAN; if (type == "r2") { function.named_parameters["account_id"] = LogicalType::VARCHAR;