summaryrefslogtreecommitdiff
path: root/src/mongo/client
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-02-18 11:18:56 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-02-18 11:18:56 -0500
commitf93655d58b63c8e8560b86742ad83b4fdaef801d (patch)
treef673cd84c04576af8e6758204d4248721ce1ba40 /src/mongo/client
parent21c2bb6641f863a8569a9496b9d92aeef2a6bca3 (diff)
downloadmongo-f93655d58b63c8e8560b86742ad83b4fdaef801d.tar.gz
Revert "SERVER-22714 MongoURI should use the socketTimeout option"
This reverts commit 21c2bb6641f863a8569a9496b9d92aeef2a6bca3.
Diffstat (limited to 'src/mongo/client')
-rw-r--r--src/mongo/client/mongo_uri.cpp10
-rw-r--r--src/mongo/client/mongo_uri.h22
-rw-r--r--src/mongo/client/mongo_uri_connect.cpp43
3 files changed, 30 insertions, 45 deletions
diff --git a/src/mongo/client/mongo_uri.cpp b/src/mongo/client/mongo_uri.cpp
index 6a11c2cace4..443a35f9858 100644
--- a/src/mongo/client/mongo_uri.cpp
+++ b/src/mongo/client/mongo_uri.cpp
@@ -114,7 +114,7 @@ StatusWith<MongoURI> MongoURI::parse(const std::string& url) {
std::string(optionsTokens[i + 1].begin(), optionsTokens[i + 1].end());
}
- OptionsMap::const_iterator optIter;
+ std::map<std::string, std::string>::const_iterator optIter;
// If a replica set option was specified, store it in the 'setName' field.
bool haveSetName;
@@ -122,6 +122,11 @@ StatusWith<MongoURI> MongoURI::parse(const std::string& url) {
if ((haveSetName = ((optIter = options.find("replicaSet")) != options.end())))
setName = optIter->second;
+ // Add all remaining options into the bson object
+ BSONObjBuilder optionsBob;
+ for (optIter = options.begin(); optIter != options.end(); ++optIter)
+ optionsBob.append(optIter->first, optIter->second);
+
std::string servers_str = matches[3].str();
std::vector<HostAndPort> servers;
std::vector<std::string> servers_split;
@@ -143,8 +148,7 @@ StatusWith<MongoURI> MongoURI::parse(const std::string& url) {
ConnectionString cs(
direct ? ConnectionString::MASTER : ConnectionString::SET, servers, setName);
- return MongoURI(
- std::move(cs), matches[1].str(), matches[2].str(), matches[4].str(), std::move(options));
+ return MongoURI(cs, matches[1].str(), matches[2].str(), matches[4].str(), optionsBob.obj());
}
} // namespace mongo
diff --git a/src/mongo/client/mongo_uri.h b/src/mongo/client/mongo_uri.h
index f9c36163ab4..bc051f24e5d 100644
--- a/src/mongo/client/mongo_uri.h
+++ b/src/mongo/client/mongo_uri.h
@@ -28,7 +28,6 @@
#pragma once
-#include <map>
#include <string>
#include <vector>
@@ -68,11 +67,9 @@ namespace mongo {
*/
class MongoURI {
public:
- using OptionsMap = std::map<std::string, std::string>;
-
static StatusWith<MongoURI> parse(const std::string& url);
- DBClientBase* connect(std::string& errmsg) const;
+ DBClientBase* connect(std::string& errmsg, double socketTimeout = 0) const;
const std::string& getUser() const {
return _user;
@@ -82,7 +79,7 @@ public:
return _password;
}
- const OptionsMap& getOptions() const {
+ const BSONObj& getOptions() const {
return _options;
}
@@ -111,19 +108,19 @@ public:
}
private:
- explicit MongoURI(const ConnectionString connectString)
- : _connectString(std::move(connectString)){};
+ explicit MongoURI(const ConnectionString cs)
+ : _connectString(std::move(cs)), _user(), _password(), _database(), _options(){};
- MongoURI(ConnectionString connectString,
+ MongoURI(ConnectionString _connectString,
const std::string& user,
const std::string& password,
const std::string& database,
- OptionsMap options)
- : _connectString(std::move(connectString)),
+ const BSONObj& options)
+ : _connectString(std::move(_connectString)),
_user(user),
_password(password),
_database(database),
- _options(std::move(options)){};
+ _options(options){};
BSONObj _makeAuthObjFromOptions(int maxWireVersion) const;
@@ -131,7 +128,6 @@ private:
std::string _user;
std::string _password;
std::string _database;
- OptionsMap _options;
+ BSONObj _options;
};
-
} // namespace mongo
diff --git a/src/mongo/client/mongo_uri_connect.cpp b/src/mongo/client/mongo_uri_connect.cpp
index 7918cacb93f..aaee6d2bcc2 100644
--- a/src/mongo/client/mongo_uri_connect.cpp
+++ b/src/mongo/client/mongo_uri_connect.cpp
@@ -111,36 +111,34 @@ BSONObj MongoURI::_makeAuthObjFromOptions(int maxWireVersion) const {
if (!_password.empty())
bob.append(saslCommandPasswordFieldName, _password);
- OptionsMap::const_iterator it;
-
- it = _options.find("authSource");
- if (it != _options.end()) {
- bob.append(saslCommandUserDBFieldName, it->second);
+ BSONElement elt = _options.getField("authSource");
+ if (!elt.eoo()) {
+ bob.appendAs(elt, saslCommandUserDBFieldName);
} else if (!_database.empty()) {
bob.append(saslCommandUserDBFieldName, _database);
} else {
bob.append(saslCommandUserDBFieldName, "admin");
}
- it = _options.find("authMechanism");
- if (it != _options.end()) {
- bob.append(saslCommandMechanismFieldName, it->second);
+ elt = _options.getField("authMechanism");
+ if (!elt.eoo()) {
+ bob.appendAs(elt, saslCommandMechanismFieldName);
} else if (maxWireVersion >= 3) {
bob.append(saslCommandMechanismFieldName, kAuthMechScramSha1);
} else {
bob.append(saslCommandMechanismFieldName, kAuthMechMongoCR);
}
- it = _options.find("authMechanismProperties");
- if (it != _options.end()) {
- BSONObj parsed(parseAuthMechanismProperties(it->second));
+ elt = _options.getField("authMechanismProperties");
+ if (!elt.eoo()) {
+ BSONObj parsed(parseAuthMechanismProperties(elt.String()));
bool hasNameProp = parsed.hasField(kAuthServiceName);
bool hasRealmProp = parsed.hasField(kAuthServiceRealm);
uassert(ErrorCodes::FailedToParse,
"Cannot specify both gssapiServiceName and SERVICE_NAME",
- !(hasNameProp && _options.count("gssapiServiceName")));
+ !(hasNameProp && _options.hasField("gssapiServiceName")));
// we append the parsed object so that mechanisms that don't accept it can assert.
bob.append(kAuthMechanismPropertiesKey, parsed);
// we still append using the old way the SASL code expects it
@@ -154,29 +152,16 @@ BSONObj MongoURI::_makeAuthObjFromOptions(int maxWireVersion) const {
}
}
- it = _options.find("gssapiServiceName");
- if (it != _options.end()) {
- bob.append(saslCommandServiceNameFieldName, it->second);
- }
+ elt = _options.getField("gssapiServiceName");
+ if (!elt.eoo())
+ bob.appendAs(elt, saslCommandServiceNameFieldName);
bob.append("user", username);
return bob.obj();
}
-DBClientBase* MongoURI::connect(std::string& errmsg) const {
- double socketTimeout = 0.0;
-
- OptionsMap::const_iterator it = _options.find("socketTimeoutMS");
- if (it != _options.end()) {
- try {
- socketTimeout = std::stod(it->second);
- } catch (const std::exception& e) {
- uasserted(ErrorCodes::BadValue,
- str::stream() << "Unable to parse socketTimeoutMS value" << causedBy(e));
- }
- }
-
+DBClientBase* MongoURI::connect(std::string& errmsg, double socketTimeout) const {
auto ret = _connectString.connect(errmsg, socketTimeout);
if (!_user.empty()) {
ret->auth(_makeAuthObjFromOptions(ret->getMaxWireVersion()));