mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add mongo config option: authdb, see issue #884
This commit is contained in:
@@ -87,13 +87,17 @@ local function mongo_auth(mongoc)
|
|||||||
local pass = rawget(mongoc, "password")
|
local pass = rawget(mongoc, "password")
|
||||||
local authmod = rawget(mongoc, "authmod") or "scram_sha1"
|
local authmod = rawget(mongoc, "authmod") or "scram_sha1"
|
||||||
authmod = "auth_" .. authmod
|
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()
|
return function()
|
||||||
if user ~= nil and pass ~= nil then
|
if user ~= nil and pass ~= nil then
|
||||||
-- autmod can be "mongodb_cr" or "scram_sha1"
|
-- autmod can be "mongodb_cr" or "scram_sha1"
|
||||||
local auth_func = mongoc[authmod]
|
local auth_func = mongoc[authmod]
|
||||||
assert(auth_func , "Invalid authmod")
|
assert(auth_func , "Invalid authmod")
|
||||||
assert(auth_func(mongoc,user, pass))
|
assert(auth_func(authdb or mongoc, user, pass))
|
||||||
end
|
end
|
||||||
local rs_data = mongoc:runCommand("ismaster")
|
local rs_data = mongoc:runCommand("ismaster")
|
||||||
if rs_data.ok == 1 then
|
if rs_data.ok == 1 then
|
||||||
@@ -156,6 +160,7 @@ function mongo.client( conf )
|
|||||||
username = first.username,
|
username = first.username,
|
||||||
password = first.password,
|
password = first.password,
|
||||||
authmod = first.authmod,
|
authmod = first.authmod,
|
||||||
|
authdb = first.authdb,
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.__id = 0
|
obj.__id = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user