diff --git a/src/etcd_state_client.cpp b/src/etcd_state_client.cpp index cdae49e0..95a8e05c 100644 --- a/src/etcd_state_client.cpp +++ b/src/etcd_state_client.cpp @@ -56,6 +56,23 @@ void etcd_state_client_t::etcd_call(std::string api, json11::Json payload, int t http_request_json(tfd, etcd_address, req, timeout, callback); } +void etcd_state_client_t::add_etcd_url(std::string addr) +{ + if (addr.length() > 0) + { + if (strtolower(addr.substr(0, 7)) == "http://") + addr = addr.substr(7); + else if (strtolower(addr.substr(0, 8)) == "https://") + { + printf("HTTPS is unsupported for etcd. Either use plain HTTP or setup a local proxy for etcd interaction\n"); + exit(1); + } + if (addr.find('/') < 0) + addr += "/v3"; + this->etcd_addresses.push_back(addr); + } +} + void etcd_state_client_t::parse_config(json11::Json & config) { this->etcd_addresses.clear(); @@ -65,13 +82,7 @@ void etcd_state_client_t::parse_config(json11::Json & config) while (1) { int pos = ea.find(','); - std::string addr = pos >= 0 ? ea.substr(0, pos) : ea; - if (addr.length() > 0) - { - if (addr.find('/') < 0) - addr += "/v3"; - this->etcd_addresses.push_back(addr); - } + add_etcd_url(pos >= 0 ? ea.substr(0, pos) : ea); if (pos >= 0) ea = ea.substr(pos+1); else @@ -82,13 +93,7 @@ void etcd_state_client_t::parse_config(json11::Json & config) { for (auto & ea: config["etcd_address"].array_items()) { - std::string addr = ea.string_value(); - if (addr != "") - { - if (addr.find('/') < 0) - addr += "/v3"; - this->etcd_addresses.push_back(addr); - } + add_etcd_url(ea.string_value()); } } this->etcd_prefix = config["etcd_prefix"].string_value(); diff --git a/src/etcd_state_client.h b/src/etcd_state_client.h index 89fd5200..8059793a 100644 --- a/src/etcd_state_client.h +++ b/src/etcd_state_client.h @@ -54,6 +54,9 @@ struct pool_config_t struct etcd_state_client_t { +protected: + void add_etcd_url(std::string); +public: std::vector etcd_addresses; std::string etcd_prefix; int log_level = 0; diff --git a/src/fio_cluster.cpp b/src/fio_cluster.cpp index 97c6efdd..6a916f87 100644 --- a/src/fio_cluster.cpp +++ b/src/fio_cluster.cpp @@ -117,8 +117,15 @@ static struct fio_option options[] = { static int sec_setup(struct thread_data *td) { + sec_options *o = (sec_options*)td->eo; sec_data *bsd; + if (!o->etcd_host) + { + td_verror(td, EINVAL, "etcd address is missing"); + return 1; + } + bsd = new sec_data; if (!bsd) { diff --git a/src/http_client.cpp b/src/http_client.cpp index 63b8bd5d..be7229bd 100644 --- a/src/http_client.cpp +++ b/src/http_client.cpp @@ -22,7 +22,6 @@ #define READ_BUFFER_SIZE 9000 static int extract_port(std::string & host); -static std::string strtolower(const std::string & in); static std::string trim(const std::string & in); static std::string ws_format_frame(int type, uint64_t size); static bool ws_parse_frame(std::string & buf, int & type, std::string & res); @@ -673,7 +672,7 @@ static int extract_port(std::string & host) return port; } -static std::string strtolower(const std::string & in) +std::string strtolower(const std::string & in) { std::string s = in; for (int i = 0; i < s.length(); i++) diff --git a/src/http_client.h b/src/http_client.h index 04d78347..4a5d68df 100644 --- a/src/http_client.h +++ b/src/http_client.h @@ -49,6 +49,8 @@ std::vector getifaddr_list(bool include_v6 = false); uint64_t stoull_full(const std::string & str, int base = 10); +std::string strtolower(const std::string & in); + void http_request(timerfd_manager_t *tfd, const std::string & host, const std::string & request, const http_options_t & options, std::function callback);