mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[MongoDB] Support mongodb+srv protocol (#2159)
This commit is contained in:
parent
b2abfc5710
commit
b6c8be5f43
6
Pipfile.lock
generated
6
Pipfile.lock
generated
@ -89,6 +89,12 @@
|
|||||||
],
|
],
|
||||||
"version": "==1.3.0"
|
"version": "==1.3.0"
|
||||||
},
|
},
|
||||||
|
"dnspython": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:861e6e58faa730f9845aaaa9c6c832851fbf89382ac52915a51f89c71accdd31"
|
||||||
|
],
|
||||||
|
"version": "==1.15.0"
|
||||||
|
},
|
||||||
"e1839a8": {
|
"e1839a8": {
|
||||||
"editable": true,
|
"editable": true,
|
||||||
"extras": [
|
"extras": [
|
||||||
|
|||||||
@ -9,18 +9,24 @@ _conn = None
|
|||||||
|
|
||||||
|
|
||||||
def _initialize(**kwargs):
|
def _initialize(**kwargs):
|
||||||
|
kwargs.get("URI", "mongodb")
|
||||||
host = kwargs["HOST"]
|
host = kwargs["HOST"]
|
||||||
port = kwargs["PORT"]
|
port = kwargs["PORT"]
|
||||||
admin_user = kwargs["USERNAME"]
|
admin_user = kwargs["USERNAME"]
|
||||||
admin_pass = kwargs["PASSWORD"]
|
admin_pass = kwargs["PASSWORD"]
|
||||||
db_name = kwargs.get("DB_NAME", "default_db")
|
db_name = kwargs.get("DB_NAME", "default_db")
|
||||||
|
|
||||||
|
if port is 0:
|
||||||
|
ports = ""
|
||||||
|
else:
|
||||||
|
ports = ":{}".format(port)
|
||||||
|
|
||||||
if admin_user is not None and admin_pass is not None:
|
if admin_user is not None and admin_pass is not None:
|
||||||
url = "mongodb://{}:{}@{}:{}/{}".format(
|
url = "{}://{}:{}@{}{}/{}".format(
|
||||||
quote_plus(admin_user), quote_plus(admin_pass), host, port, db_name
|
uri, quote_plus(admin_user), quote_plus(admin_pass), host, ports, db_name
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
url = "mongodb://{}:{}/{}".format(host, port, db_name)
|
url = "{}://{}{}/{}".format(uri, host, ports, db_name)
|
||||||
|
|
||||||
global _conn
|
global _conn
|
||||||
_conn = motor.motor_asyncio.AsyncIOMotorClient(url)
|
_conn = motor.motor_asyncio.AsyncIOMotorClient(url)
|
||||||
@ -111,8 +117,22 @@ class Mongo(BaseDriver):
|
|||||||
|
|
||||||
|
|
||||||
def get_config_details():
|
def get_config_details():
|
||||||
|
uri = None
|
||||||
|
while True:
|
||||||
|
uri = input("Enter URI scheme (mongodb or mongodb+srv): ")
|
||||||
|
if uri is "":
|
||||||
|
uri = "mongodb"
|
||||||
|
|
||||||
|
if uri in ["mongodb", "mongodb+srv"]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Invalid URI scheme")
|
||||||
|
|
||||||
host = input("Enter host address: ")
|
host = input("Enter host address: ")
|
||||||
|
if uri is "mongodb":
|
||||||
port = int(input("Enter host port: "))
|
port = int(input("Enter host port: "))
|
||||||
|
else:
|
||||||
|
port = 0
|
||||||
|
|
||||||
admin_uname = input("Enter login username: ")
|
admin_uname = input("Enter login username: ")
|
||||||
admin_password = input("Enter login password: ")
|
admin_password = input("Enter login password: ")
|
||||||
@ -128,5 +148,6 @@ def get_config_details():
|
|||||||
"USERNAME": admin_uname,
|
"USERNAME": admin_uname,
|
||||||
"PASSWORD": admin_password,
|
"PASSWORD": admin_password,
|
||||||
"DB_NAME": db_name,
|
"DB_NAME": db_name,
|
||||||
|
"URI": uri,
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
2
setup.py
2
setup.py
@ -112,7 +112,7 @@ if __name__ == "__main__":
|
|||||||
"pytest-asyncio==0.9.0",
|
"pytest-asyncio==0.9.0",
|
||||||
"six==1.11.0",
|
"six==1.11.0",
|
||||||
],
|
],
|
||||||
"mongo": ["motor==2.0.0", "pymongo==3.7.1"],
|
"mongo": ["motor==2.0.0", "pymongo==3.7.1", "dnspython==1.15.0"],
|
||||||
"docs": [
|
"docs": [
|
||||||
"alabaster==0.7.11",
|
"alabaster==0.7.11",
|
||||||
"babel==2.6.0",
|
"babel==2.6.0",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user