add mongo config option: authdb, see issue #884

This commit is contained in:
Cloud Wu
2018-08-29 19:52:41 +08:00
parent 8ce816de7f
commit e6e69ae805

View File

@@ -87,13 +87,17 @@ local function mongo_auth(mongoc)
local pass = rawget(mongoc, "password")
local authmod = rawget(mongoc, "authmod") or "scram_sha1"
authmod = "auth_" .. authmod
local authdb = rawget(mongoc, "authdb")
if authdb then
authdb = mongo_client.getDB(mongoc, authdb) -- mongoc has not set metatable yet
end
return function()
if user ~= nil and pass ~= nil then
-- autmod can be "mongodb_cr" or "scram_sha1"
local auth_func = mongoc[authmod]
assert(auth_func , "Invalid authmod")
assert(auth_func(mongoc,user, pass))
assert(auth_func(authdb or mongoc, user, pass))
end
local rs_data = mongoc:runCommand("ismaster")
if rs_data.ok == 1 then
@@ -156,6 +160,7 @@ function mongo.client( conf )
username = first.username,
password = first.password,
authmod = first.authmod,
authdb = first.authdb,
}
obj.__id = 0