bug fix: authentication mongodb

This commit is contained in:
Steve Nyemba 2022-05-06 14:25:12 -05:00
parent fd9523e99a
commit 899339f11f
2 changed files with 9 additions and 5 deletions

View File

@ -8,7 +8,7 @@ def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read() return open(os.path.join(os.path.dirname(__file__), fname)).read()
args = { args = {
"name":"data-transport", "name":"data-transport",
"version":"1.4.10", "version":"1.5.0",
"author":"The Phi Technology LLC","author_email":"info@the-phi.com", "author":"The Phi Technology LLC","author_email":"info@the-phi.com",
"license":"MIT", "license":"MIT",
"packages":["transport"]} "packages":["transport"]}

View File

@ -33,20 +33,24 @@ class Mongo :
:username username for authentication :username username for authentication
:password password for current user :password password for current user
""" """
host = args['host'] if 'host' in args else 'localhost:27017' port = str(args['port']) if 'port' in args else '27017'
host = args['host'] if 'host' in args else 'localhost'
host = ":".join([host,port]) #-- Formatting host information here
self.uid = args['doc'] if 'doc' in args else None #-- document identifier
self.dbname = args['dbname'] if 'dbname' in args else args['db']
self._lock = False if 'lock' not in args else args['lock']
if 'user' in args and 'password' in args: if 'user' in args and 'password' in args:
self.client = MongoClient(host, self.client = MongoClient(host,
username=args['username'] , username=args['username'] ,
password=args['password'] , password=args['password'] ,
authSource=(args['authSource'] if 'authSource' in args else self.dbname),
authMechanism='SCRAM-SHA-256') authMechanism='SCRAM-SHA-256')
else: else:
self.client = MongoClient(host,maxPoolSize=10000) self.client = MongoClient(host,maxPoolSize=10000)
self.uid = args['doc'] #-- document identifier
self.dbname = args['dbname'] if 'dbname' in args else args['db']
self.db = self.client[self.dbname] self.db = self.client[self.dbname]
self._lock = False if 'lock' not in args else args['lock']
def isready(self): def isready(self):
p = self.dbname in self.client.list_database_names() p = self.dbname in self.client.list_database_names()