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"
|
||||
},
|
||||
"dnspython": {
|
||||
"hashes": [
|
||||
"sha256:861e6e58faa730f9845aaaa9c6c832851fbf89382ac52915a51f89c71accdd31"
|
||||
],
|
||||
"version": "==1.15.0"
|
||||
},
|
||||
"e1839a8": {
|
||||
"editable": true,
|
||||
"extras": [
|
||||
|
||||
@ -9,18 +9,24 @@ _conn = None
|
||||
|
||||
|
||||
def _initialize(**kwargs):
|
||||
kwargs.get("URI", "mongodb")
|
||||
host = kwargs["HOST"]
|
||||
port = kwargs["PORT"]
|
||||
admin_user = kwargs["USERNAME"]
|
||||
admin_pass = kwargs["PASSWORD"]
|
||||
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:
|
||||
url = "mongodb://{}:{}@{}:{}/{}".format(
|
||||
quote_plus(admin_user), quote_plus(admin_pass), host, port, db_name
|
||||
url = "{}://{}:{}@{}{}/{}".format(
|
||||
uri, quote_plus(admin_user), quote_plus(admin_pass), host, ports, db_name
|
||||
)
|
||||
else:
|
||||
url = "mongodb://{}:{}/{}".format(host, port, db_name)
|
||||
url = "{}://{}{}/{}".format(uri, host, ports, db_name)
|
||||
|
||||
global _conn
|
||||
_conn = motor.motor_asyncio.AsyncIOMotorClient(url)
|
||||
@ -111,8 +117,22 @@ class Mongo(BaseDriver):
|
||||
|
||||
|
||||
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: ")
|
||||
if uri is "mongodb":
|
||||
port = int(input("Enter host port: "))
|
||||
else:
|
||||
port = 0
|
||||
|
||||
admin_uname = input("Enter login username: ")
|
||||
admin_password = input("Enter login password: ")
|
||||
@ -128,5 +148,6 @@ def get_config_details():
|
||||
"USERNAME": admin_uname,
|
||||
"PASSWORD": admin_password,
|
||||
"DB_NAME": db_name,
|
||||
"URI": uri,
|
||||
}
|
||||
return ret
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user