Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add connectionstring to client hosts config #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The complete documetation is [here](http://elasticsearch-lua.readthedocs.io/).
hosts = {
{ -- Ignoring any of the following hosts parameters is allowed.
-- The default shall be set
connectionstring = "",
protocol = "http",
host = "localhost",
port = 9200,
Expand Down
4 changes: 4 additions & 0 deletions src/elasticsearch/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ local Settings = {}
-- Initial seed of hosts
Settings.hosts = {
{
connectionstring = "",
protocol = "http",
host = "localhost",
port = 9200,
Expand Down Expand Up @@ -131,6 +132,7 @@ function Settings:setParameters()
-- Checking hosts
if self.user_hosts ~= nil then
local default_host = {
connectionstring = self.hosts[1].connectionstring,
protocol = self.hosts[1].protocol,
host = self.hosts[1].host,
port = self.hosts[1].port,
Expand All @@ -142,6 +144,7 @@ function Settings:setParameters()
self.hosts = {}
for i, v in pairs(self.user_hosts) do
self.hosts[i] = {
connectionstring = default_host.connectionstring,
protocol = default_host.protocol,
host = default_host.host,
port = default_host.port,
Expand Down Expand Up @@ -172,6 +175,7 @@ function Settings:setConnectionSettings()
self.connections = {}
for key, host in pairs(self.hosts) do
table.insert(self.connections, Connection:new{
connectionstring = host.connectionstring,
protocol = host.protocol,
host = host.host,
port = host.port,
Expand Down
9 changes: 7 additions & 2 deletions src/elasticsearch/connection/Connection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ local Connection = {}
-------------------------------------------------------------------------------
-- Declaring instance variables
-------------------------------------------------------------------------------

-- The FULL connection string should be use
Connection.connectionstring = nil
-- The protocol of the connection
Connection.protocol = nil
-- The host where the connection should be made
Expand Down Expand Up @@ -83,7 +84,7 @@ function Connection:request(method, uri, params, body, timeout)
request.source = ltn12.source.string(body)
end
-- Adding auth to request
if self.username ~= nil and self.password ~= nil then
if self.username ~= "" and self.password ~= "" then
local authStr, foo = mime.b64(self.username .. ':' .. self.password)
request.headers['Authorization'] = 'Basic ' .. authStr
end
Expand Down Expand Up @@ -171,6 +172,10 @@ function Connection:buildURI(uri, params)
port = self.port,
path = uri
}
if self.connectionstring ~= "" then
urlComponents = url.parse(self.connectionstring)
urlComponents.path = uri
end
if params ~= nil then
urlComponents.query = self:buildQuery(params)
end
Expand Down