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

fix(config) error when specifying port for cassandra #2263

Merged
merged 1 commit into from
Mar 28, 2017

Conversation

Vermeille
Copy link
Contributor

No description provided.

@Vermeille Vermeille changed the base branch from master to next March 27, 2017 08:17
@Vermeille Vermeille changed the base branch from next to master March 27, 2017 09:25
errors[#errors+1] = "can't specify port in cassandra_contact_point, "..
"use cassandra_port for that"
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use something like:

local host, port = utils.normalize_ip(contact_point)
if host and port then
  host = nil
  port = "no port allowed"
end
if not host then
  errors[#errors+1] = "bad Cassandra contact point '" . .contact_point . ."': " .. port
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tieske Tieske added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Mar 27, 2017
@Vermeille Vermeille force-pushed the patch-2 branch 2 times, most recently from 6701cf5 to 1cbe588 Compare March 27, 2017 11:58
@Tieske Tieske added this to the 0.10.1 milestone Mar 27, 2017
@Vermeille
Copy link
Contributor Author

You're right. Checking for hostname sanity was out of scope since it was not already there and is far less likely to be the root of an hard to spot mistake, but given how cheap and easy it is to implement, expect if in few minutes!

local conf, err = conf_loader(nil, {
cassandra_contact_points = "some/really\\bad/host\name,addr2"
})
assert.is_nil(conf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the second \ also needs escaping, as well as testing for a proper error message, as I think it currently errors with something like "bad name" without any 'contact_points' context

Copy link
Member

@thibaultcha thibaultcha Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better off using [[]] here to avoid escaping those \

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to assert what the value of err is here

@@ -183,6 +183,16 @@ local function check_and_infer(conf)
"DCAwareRoundRobin policy is in use"
end

for _, contact_point in pairs(conf.cassandra_contact_points) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is a list, and as such, should be iterated over with ipairs.

errors[#errors+1] = err
elseif endpoint.port then
errors[#errors+1] = "bad Cassandra contact point '" .. contact_point ..
"': port must be specified in cassandra_port"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the alignment of the " character is off by 1 column here

local endpoint, err = utils.normalize_ip(contact_point)
if not endpoint then
errors[#errors+1] = err
elseif endpoint.port then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a blank line before the elseif statement

for _, contact_point in pairs(conf.cassandra_contact_points) do
local endpoint, err = utils.normalize_ip(contact_point)
if not endpoint then
errors[#errors+1] = err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to give more context to this error, like:

errors[#errors + 1] = "bad cassandra contact point '" .. contact_point .. "': " .. err

local conf, err = conf_loader(nil, {
cassandra_contact_points = "some/really\\bad/host\name,addr2"
})
assert.is_nil(conf)
Copy link
Member

@thibaultcha thibaultcha Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better off using [[]] here to avoid escaping those \

local conf, err = conf_loader(nil, {
cassandra_contact_points = "some/really\\bad/host\name,addr2"
})
assert.is_nil(conf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to assert what the value of err is here

@Vermeille
Copy link
Contributor Author

Let me know if you think the error messages are not good enough :)

@Tieske Tieske modified the milestones: 0.10.2, 0.10.1 Mar 28, 2017
})
assert.equal("bad Cassandra contact point 'addr1:9042': port must be specified in cassandra_port", err)
assert.is_nil(conf)
end)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vermeille sorry, but hadn't noticed before you use an indentation of 4 where the rest of the code uses 2. Mind fixing that?

all well otherwise imo.

for _, contact_point in ipairs(conf.cassandra_contact_points) do
local endpoint, err = utils.normalize_ip(contact_point)
if not endpoint then
errors[#errors+1] = "bad cassandra contact point '" .. contact_point ..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two error messages inconsistently capitalize "cassandra". Ideally, both should be lowercase.

cassandra_contact_point does not tolerate port specification.
Issue an error when the user specifies it by mistake.
@Tieske Tieske merged commit e6a44bc into Kong:master Mar 28, 2017
@Tieske
Copy link
Member

Tieske commented Mar 28, 2017

@Vermeille Thx!

@Vermeille Vermeille deleted the patch-2 branch March 29, 2017 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants