From 0e72f991ac08548d339aee90a185a44312406352 Mon Sep 17 00:00:00 2001 From: Duane Murphy Date: Thu, 21 Apr 2016 09:53:21 -0700 Subject: [PATCH 1/2] Support authSource and authenticationDatabase Add support for authenticationDatabase to connect. Map the authSource URL option to authenticationDatabase. --- mongoctl/commands/common/connect.py | 11 +++++++++-- mongoctl/mongo_uri_tools.py | 5 +++++ mongoctl/mongoctl_command_config.py | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mongoctl/commands/common/connect.py b/mongoctl/commands/common/connect.py index 3eb5b0d..e606d46 100644 --- a/mongoctl/commands/common/connect.py +++ b/mongoctl/commands/common/connect.py @@ -27,6 +27,7 @@ "verbose", "ipv6", "port", + "authenticationDatabase", "ssl", "sslCAFile", ] @@ -97,9 +98,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(), @@ -145,6 +149,9 @@ 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"] + server_or_cluster = repository.build_server_or_cluster_from_uri(uri) if isinstance(server_or_cluster, Server): diff --git a/mongoctl/mongo_uri_tools.py b/mongoctl/mongo_uri_tools.py index 824395f..8304044 100644 --- a/mongoctl/mongo_uri_tools.py +++ b/mongoctl/mongo_uri_tools.py @@ -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 diff --git a/mongoctl/mongoctl_command_config.py b/mongoctl/mongoctl_command_config.py index 9bea8d2..6c8b0d7 100644 --- a/mongoctl/mongoctl_command_config.py +++ b/mongoctl/mongoctl_command_config.py @@ -546,6 +546,16 @@ "nargs": 1 }, + { + "name": "authenticationDatabase", + "type": "optional", + "help": "user source (defaults to dbname)", + "cmd_arg": [ + "--authenticationDatabase" + ], + "nargs": 1 + }, + { "name": "ssl", "type": "optional", From 375e29dbfb87a26f444c3e8059687abfe5133044 Mon Sep 17 00:00:00 2001 From: Duane Murphy Date: Fri, 29 Apr 2016 13:58:55 -0700 Subject: [PATCH 2/2] Support authMechanism and authenticationMechanism Add support for authenticationMechanism to connect. Map the authMechanism URL option to authenticationMechanism. --- mongoctl/commands/common/connect.py | 5 +++++ mongoctl/mongoctl_command_config.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/mongoctl/commands/common/connect.py b/mongoctl/commands/common/connect.py index e606d46..51818ac 100644 --- a/mongoctl/commands/common/connect.py +++ b/mongoctl/commands/common/connect.py @@ -28,6 +28,7 @@ "ipv6", "port", "authenticationDatabase", + "authenticationMechanism", "ssl", "sslCAFile", ] @@ -152,6 +153,10 @@ def open_mongo_shell_to_uri(uri, 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): diff --git a/mongoctl/mongoctl_command_config.py b/mongoctl/mongoctl_command_config.py index 6c8b0d7..fff7fc7 100644 --- a/mongoctl/mongoctl_command_config.py +++ b/mongoctl/mongoctl_command_config.py @@ -556,6 +556,16 @@ "nargs": 1 }, + { + "name": "authenticationMechanism", + "type": "optional", + "help": "authentication mechanism", + "cmd_arg": [ + "--authenticationMechanism" + ], + "nargs": 1 + }, + { "name": "ssl", "type": "optional",