Add support for using an authentication database for MongoDB.
A popular convention is to have user accounts stored in a separate authentication database. This change add support for configuring edx-platform to work with such a setup.
This commit is contained in:
@@ -36,6 +36,9 @@ def connect_to_mongodb(
|
||||
# No 'replicaSet' in kwargs - so no secondary reads.
|
||||
mongo_client_class = pymongo.MongoClient
|
||||
|
||||
# If the MongoDB server uses a separate authentication database that should be specified here
|
||||
auth_source = kwargs.pop('auth_source', '') or None
|
||||
|
||||
# If read_preference is given as a name of a valid ReadPreference.<NAME> constant
|
||||
# such as "SECONDARY_PREFERRED", convert it. Otherwise pass it through unchanged.
|
||||
if 'read_preference' in kwargs:
|
||||
@@ -59,10 +62,9 @@ def connect_to_mongodb(
|
||||
mongo_conn,
|
||||
wait_time=retry_wait_time
|
||||
)
|
||||
|
||||
# If credentials were provided, authenticate the user.
|
||||
if user is not None and password is not None:
|
||||
mongo_conn.authenticate(user, password)
|
||||
mongo_conn.authenticate(user, password, source=auth_source)
|
||||
|
||||
return mongo_conn
|
||||
|
||||
|
||||
Reference in New Issue
Block a user