aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_clickhouse.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-08-06 16:12:12 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-08-06 18:00:34 +0100
commitc0dd861ca9f579379ab9957ef98c1aaf20f672b3 (patch)
tree11946ea5bc89b07c31ec4404ffcf70bee1a8cc8a /lualib/lua_clickhouse.lua
parente7f24a30034e5717c07da3df2d3010a20faac380 (diff)
downloadrspamd-c0dd861ca9f579379ab9957ef98c1aaf20f672b3.tar.gz
rspamd-c0dd861ca9f579379ab9957ef98c1aaf20f672b3.zip
[Minor] Add generic request method to Clickhouse lib
Diffstat (limited to 'lualib/lua_clickhouse.lua')
-rw-r--r--lualib/lua_clickhouse.lua49
1 files changed, 48 insertions, 1 deletions
diff --git a/lualib/lua_clickhouse.lua b/lualib/lua_clickhouse.lua
index 3e8daa61e..771592e57 100644
--- a/lualib/lua_clickhouse.lua
+++ b/lualib/lua_clickhouse.lua
@@ -260,7 +260,54 @@ exports.insert = function (upstream, settings, params, query, rows,
escape_spaces(query))
end
- rspamd_logger.debugm(N, http_params.log_obj, "clickhouse select request: %s", params.body)
+ return rspamd_http.request(http_params)
+end
+
+--[[[
+-- @function lua_clickhouse.generic(upstream, settings, params, query,
+ ok_cb, fail_cb)
+-- Make a generic request to Clickhouse (e.g. alter)
+-- @param {upstream} upstream clickhouse server upstream
+-- @param {table} settings global settings table:
+-- * use_gsip: use gzip compression
+-- * timeout: request timeout
+-- * no_ssl_verify: skip SSL verification
+-- * user: HTTP user
+-- * password: HTTP password
+-- @param {params} HTTP request params
+-- @param {string} query Clickhouse query (passed in `query` request element with spaces escaped)
+-- @param {function} ok_cb callback to be called in case of success
+-- @param {function} fail_cb callback to be called in case of some error
+-- @return {boolean} whether a connection was successful
+-- @example
+--
+--]]
+exports.generic = function (upstream, settings, params, query,
+ ok_cb, fail_cb)
+ local http_params = {}
+
+ for k,v in pairs(params) do http_params[k] = v end
+
+ http_params.callback = mk_http_insert_cb(upstream, http_params, ok_cb, fail_cb)
+ http_params.gzip = settings.use_gzip
+ http_params.mime_type = 'text/plain'
+ http_params.timeout = settings.timeout or default_timeout
+ http_params.no_ssl_verify = settings.no_ssl_verify
+ http_params.user = settings.user
+ http_params.password = settings.password
+ http_params.log_obj = params.task or params.config
+
+ if not http_params.url then
+ local connect_prefix = "http://"
+ if settings.use_https then
+ connect_prefix = 'https://'
+ end
+ local ip_addr = upstream:get_addr():to_string(true)
+ http_params.url = connect_prefix .. ip_addr .. '/?default_format=JSONEachRow'
+ end
+
+ return rspamd_http.request(http_params)
end
+
return exports \ No newline at end of file