summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin Albertson <kevin.albertson@10gen.com>2018-01-11 17:20:04 -0500
committerKevin Albertson <kevin.albertson@10gen.com>2018-01-23 09:04:45 -0500
commit805c28ebf2d1df9fefdf9f16726ea5b1ab77c5e9 (patch)
tree981dfdc34e79cf6ac132c0377aadb94fcbd58210 /src
parentf4ac177b55bc762e977dc093a40e442b7061f58c (diff)
downloadmongo-805c28ebf2d1df9fefdf9f16726ea5b1ab77c5e9.tar.gz
SERVER-32094 support appname URI param in shell
Diffstat (limited to 'src')
-rw-r--r--src/mongo/client/mongo_uri.cpp18
-rw-r--r--src/mongo/client/mongo_uri.h2
-rw-r--r--src/mongo/scripting/mozjs/mongo.cpp3
3 files changed, 21 insertions, 2 deletions
diff --git a/src/mongo/client/mongo_uri.cpp b/src/mongo/client/mongo_uri.cpp
index d9dca575e40..820a11da1dc 100644
--- a/src/mongo/client/mongo_uri.cpp
+++ b/src/mongo/client/mongo_uri.cpp
@@ -422,13 +422,20 @@ MongoURI MongoURI::parseImpl(const std::string& url) {
addTXTOptions(parseOptions(connectionOptions, url), canonicalHost, url, isSeedlist);
// If a replica set option was specified, store it in the 'setName' field.
- const auto optIter = options.find("replicaSet");
+ auto optIter = options.find("replicaSet");
std::string setName;
if (optIter != end(options)) {
setName = optIter->second;
invariant(!setName.empty());
}
+ // If an appname option was specified, validate that is 128 bytes or less.
+ optIter = options.find("appname");
+ if (optIter != end(options) && optIter->second.length() > 128) {
+ uasserted(ErrorCodes::FailedToParse,
+ str::stream() << "appname cannot exceed 128 characters: " << optIter->second);
+ }
+
ConnectionString cs(
setName.empty() ? ConnectionString::MASTER : ConnectionString::SET, servers, setName);
return MongoURI(std::move(cs), username, password, database, std::move(options));
@@ -439,4 +446,13 @@ StatusWith<MongoURI> MongoURI::parse(const std::string& url) try {
} catch (const std::exception&) {
return exceptionToStatus();
}
+
+const boost::optional<std::string> MongoURI::getAppName() const {
+ const auto optIter = _options.find("appname");
+ if (optIter != end(_options)) {
+ return optIter->second;
+ } else {
+ return boost::none;
+ }
+}
} // namespace mongo
diff --git a/src/mongo/client/mongo_uri.h b/src/mongo/client/mongo_uri.h
index 11d948a526c..b5cf3ecf15c 100644
--- a/src/mongo/client/mongo_uri.h
+++ b/src/mongo/client/mongo_uri.h
@@ -145,6 +145,8 @@ public:
return _connectString.getServers();
}
+ const boost::optional<std::string> getAppName() const;
+
// If you are trying to clone a URI (including its options/auth information) for a single
// server (say a member of a replica-set), you can pass in its HostAndPort information to
// get a new URI with the same info, except type() will be MASTER and getServers() will
diff --git a/src/mongo/scripting/mozjs/mongo.cpp b/src/mongo/scripting/mozjs/mongo.cpp
index 24582b17179..c28f9e124eb 100644
--- a/src/mongo/scripting/mozjs/mongo.cpp
+++ b/src/mongo/scripting/mozjs/mongo.cpp
@@ -699,8 +699,9 @@ void MongoExternalInfo::construct(JSContext* cx, JS::CallArgs args) {
auto statusWithHost = MongoURI::parse(host);
auto cs = uassertStatusOK(statusWithHost);
+ boost::optional<std::string> appname = cs.getAppName();
std::string errmsg;
- std::unique_ptr<DBClientBase> conn(cs.connect("MongoDB Shell", errmsg));
+ std::unique_ptr<DBClientBase> conn(cs.connect(appname.value_or("MongoDB Shell"), errmsg));
if (!conn.get()) {
uasserted(ErrorCodes::InternalError, errmsg);