Enable authentication in mongo modulestore and contentstore

This commit is contained in:
Calen Pennington
2012-10-09 21:28:55 -04:00
parent e2d3ca6f23
commit 8eb4390def
2 changed files with 14 additions and 4 deletions

View File

@@ -14,9 +14,13 @@ from xmodule.exceptions import NotFoundError
class MongoContentStore(ContentStore):
def __init__(self, host, db, port=27017):
def __init__(self, host, db, port=27017, user=None, password=None, **kwargs):
logging.debug( 'Using MongoDB for static content serving at host={0} db={1}'.format(host,db))
_db = Connection(host=host, port=port)[db]
_db = Connection(host=host, port=port, **kwargs)[db]
if self.user is not None and self.password is not None:
_db.authenticate(user, password)
self.fs = gridfs.GridFS(_db)
self.fs_files = _db["fs.files"] # the underlying collection GridFS uses

View File

@@ -97,15 +97,21 @@ class MongoModuleStore(ModuleStoreBase):
# TODO (cpennington): Enable non-filesystem filestores
def __init__(self, host, db, collection, fs_root, render_template,
port=27017, default_class=None,
error_tracker=null_error_tracker):
error_tracker=null_error_tracker,
user=None, password=None, **kwargs):
ModuleStoreBase.__init__(self)
self.collection = pymongo.connection.Connection(
host=host,
port=port
port=port,
**kwargs
)[db][collection]
if user is not None and password is not None:
self.collection.database.authenticate(user, password)
# Force mongo to report errors, at the expense of performance
self.collection.safe = True