Skip to content

Support AuthSource and AuthMechanism #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions mongoctl/commands/common/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"verbose",
"ipv6",
"port",
"authenticationDatabase",
"authenticationMechanism",
"ssl",
"sslCAFile",
]
Expand Down Expand Up @@ -97,9 +99,12 @@ def open_mongo_shell_to_server(server,
else:
database = "admin"

if username or server.needs_to_auth(database):
login_database = shell_options["authenticationDatabase"] \
if "authenticationDatabase" in shell_options else database

if username or server.needs_to_auth(login_database):
# authenticate and grab a working username/password
username, password = server.get_working_login(database, username,
username, password = server.get_working_login(login_database, username,
password)

do_open_mongo_shell_to(server.get_connection_address(),
Expand Down Expand Up @@ -145,6 +150,13 @@ def open_mongo_shell_to_uri(uri,
username = username if username else uri_wrapper.username
password = password if password else uri_wrapper.password

if "authsource" in uri_wrapper.options and "authenticationDatabase" not in shell_options:
shell_options["authenticationDatabase"] = uri_wrapper.options["authsource"]

if "authmechanism" in uri_wrapper.options and "authenticationMechanism" not in shell_options:
shell_options["authenticationMechanism"] = uri_wrapper.options["authmechanism"]


server_or_cluster = repository.build_server_or_cluster_from_uri(uri)

if isinstance(server_or_cluster, Server):
Expand Down
5 changes: 5 additions & 0 deletions mongoctl/mongo_uri_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def username(self):
def password(self):
return self._uri_obj["password"]

###########################################################################
@property
def options(self):
return self._uri_obj["options"]

###########################################################################
def is_cluster_uri(self):
return len(self.node_list) > 1
Expand Down
20 changes: 20 additions & 0 deletions mongoctl/mongoctl_command_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,26 @@
"nargs": 1
},

{
"name": "authenticationDatabase",
"type": "optional",
"help": "user source (defaults to dbname)",
"cmd_arg": [
"--authenticationDatabase"
],
"nargs": 1
},

{
"name": "authenticationMechanism",
"type": "optional",
"help": "authentication mechanism",
"cmd_arg": [
"--authenticationMechanism"
],
"nargs": 1
},

{
"name": "ssl",
"type": "optional",
Expand Down