Skip to content

Commit

Permalink
chore(cassandra) bump driver to 0.5.0
Browse files Browse the repository at this point in the history
lua-cassandra 0.5.0 allows to use plain text auth provider arbitrarily,
which re-enables authentication capabilities with C* providers from
Kong.

Background:
< 0.5.0 relied on the Java class name returned in the auth challenge
response to select the appropriate authentication provider. But C*
providers such as Instaclustr implemented their own Java authentication
provider, which must also be answered by the plain text auth provider.
0.5.0 would not recognize custom Java class as valdi authentication
providers and thus, fail to authenticate. 0.6.0 allows to set any auth
provider the user want. In our case, if Kong has username and password
configured, we always use a plain text auth provider.
  • Loading branch information
thibaultcha committed Feb 3, 2016
1 parent 282481b commit b94439d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion kong-0.6.0-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = {
"yaml ~> 1.1.2-1",
"lapis ~> 1.3.1-1",
"stringy ~> 0.4-1",
"lua-cassandra ~> 0.4.2-0",
"lua-cassandra ~> 0.5.0",
"multipart ~> 0.2-1",
"lua-path ~> 0.2.3-1",
"lua-cjson ~> 2.1.0-1",
Expand Down
13 changes: 6 additions & 7 deletions kong/dao/cassandra/factory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ local stringy = require "stringy"
local Object = require "classic"
local utils = require "kong.tools.utils"

if ngx ~= nil and type(ngx.get_phase) == "function" and ngx.get_phase() == "init" and not ngx.stub then
cassandra.set_log_level("INFO")
else
cassandra.set_log_level("QUIET")
end

local CassandraFactory = Object:extend()

-- Shorthand for accessing one of the underlying DAOs
Expand All @@ -36,6 +30,10 @@ function CassandraFactory:new(properties, plugins, spawn_cluster, events_handler
self.type = "cassandra"
self.daos = {}

if properties.username and properties.password then
self.properties.auth = cassandra.auth.PlainTextProvider(properties.username, properties.password)
end

if spawn_cluster then
local ok, err = cassandra.spawn_cluster(self:get_session_options())
if not ok then
Expand Down Expand Up @@ -125,7 +123,8 @@ function CassandraFactory:get_session_options()
enabled = self.properties.ssl.enabled,
verify = self.properties.ssl.verify,
ca = self.properties.ssl.certificate_authority
}
},
auth = self.properties.auth
}
end

Expand Down
16 changes: 10 additions & 6 deletions kong/dao/cassandra/migrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ function Migrations:new(properties, events_handler)
Migrations.super.new(self, properties, events_handler)
end

function Migrations:execute(query, args, keyspace)
return Migrations.super.execute(self, query, args, {prepare = false}, keyspace)
end

function Migrations:keyspace_exists(keyspace)
local rows, err = Migrations.super.execute(self, self.queries.get_keyspace, {self.properties.keyspace}, nil, "system")
local rows, err = self:execute(self.queries.get_keyspace, {self.properties.keyspace}, "system")
if err then
return nil, err
else
Expand All @@ -41,7 +45,7 @@ end
-- @return query result
-- @return error if any
function Migrations:add_migration(migration_name, identifier)
return Migrations.super.execute(self, self.queries.add_migration, {cassandra.list({migration_name}), identifier})
return self:execute(self.queries.add_migration, {cassandra.list({migration_name}), identifier})
end

-- Return all logged migrations with a filter by identifier optionally. Check if keyspace exists before to avoid error during the first migration.
Expand All @@ -59,9 +63,9 @@ function Migrations:get_migrations(identifier)

local rows, err
if identifier ~= nil then
rows, err = Migrations.super.execute(self, self.queries.get_migrations, {identifier})
rows, err = self:execute(self.queries.get_migrations, {identifier})
else
rows, err = Migrations.super.execute(self, self.queries.get_all_migrations)
rows, err = self:execute(self.queries.get_all_migrations)
end

if err and stringy.find(err.message, "unconfigured columnfamily schema_migrations") ~= nil then
Expand All @@ -77,14 +81,14 @@ end
-- @return query result
-- @return error if any
function Migrations:delete_migration(migration_name, identifier)
return Migrations.super.execute(self, self.queries.delete_migration, {cassandra.list({migration_name}), identifier})
return self:execute(self.queries.delete_migration, {cassandra.list({migration_name}), identifier})
end

-- Drop the entire keyspace
-- @param `keyspace` Name of the keyspace to drop
-- @return query result
function Migrations:drop_keyspace(keyspace)
return Migrations.super.execute(self, string.format("DROP keyspace \"%s\"", keyspace))
return self:execute(string.format("DROP keyspace \"%s\"", keyspace))
end

function Migrations:drop()
Expand Down

0 comments on commit b94439d

Please sign in to comment.