You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
|
|
"""Mongo create check if user exists utility
|
|
|
|
|
|
"""
|
|
|
|
|
|
import sys
|
|
|
|
|
|
import urllib.parse
|
|
|
|
|
|
|
|
|
|
|
|
import pymongo
|
|
|
|
|
|
|
|
|
|
|
|
mongo_ip = sys.argv[1]
|
|
|
|
|
|
mongo_admin = sys.argv[2]
|
|
|
|
|
|
mongo_password = sys.argv[3]
|
|
|
|
|
|
|
|
|
|
|
|
mongo_admin = urllib.parse.quote_plus(mongo_admin)
|
|
|
|
|
|
mongo_password = urllib.parse.quote_plus(mongo_password)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
client = pymongo.MongoClient(f"mongodb://{mongo_ip}:27017/")
|
|
|
|
|
|
admin = client['admin']
|
|
|
|
|
|
userscol = admin['system.users']
|
|
|
|
|
|
print(userscol.find_one())
|
|
|
|
|
|
# ok, the user doesn't exist
|
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
except pymongo.errors.OperationFailure as err:
|
|
|
|
|
|
# unable to login without password
|
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|