From 31029eaec884b0b5bfdb7cda84265b8d2c1dbeba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 13 Sep 2019 14:12:57 +0300 Subject: [PATCH] MXS-2675: Fix server creation with TLS via REST API The TLS parameters were defined but the main parameter that enables it wasn't automatically added. As the REST API documentation states that this parameter does not need to be defined, the runtime configuration must add it. --- include/maxscale/config.hh | 14 ++++++++++++++ server/core/config_runtime.cc | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/include/maxscale/config.hh b/include/maxscale/config.hh index 917ff0f99..342572025 100644 --- a/include/maxscale/config.hh +++ b/include/maxscale/config.hh @@ -434,6 +434,20 @@ public: */ bool contains(const std::string& key) const; + /** + * Check if any of the given keys are defined + * + * @param keys The keys to check + * + * @return True if at least one of the keys is defined + */ + bool contains_any(const std::initializer_list& keys) const + { + return std::any_of(keys.begin(), keys.end(), [this](const std::string& a) { + return contains(a); + }); + } + /** * Set a key-value combination. If the key doesn't exist, it is added. The function is static * to handle the special case of params being empty. This is needed until the config management diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 52934d148..859447a31 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -1893,6 +1893,11 @@ bool runtime_create_server_from_json(json_t* json) { params.set_multiple(extract_parameters_from_json(json)); + if (params.contains_any({CN_SSL_KEY, CN_SSL_CERT, CN_SSL_CA_CERT})) + { + params.set(CN_SSL, "true"); + } + if (Server* server = Server::server_alloc(name, params)) { if (link_server_to_objects(server, relations) && server->serialize())