diff options
author | Spencer T Brody <spencer@10gen.com> | 2012-12-04 18:11:25 -0500 |
---|---|---|
committer | Spencer T Brody <spencer@10gen.com> | 2012-12-05 18:14:04 -0500 |
commit | fe0d238b0ac31f4b2294bda827cc913d59d6de57 (patch) | |
tree | a00d4642d0be41d166e00703f96f5d7ef1b1bfd8 /src/mongo/db/commands/hashcmd.cpp | |
parent | 50f923938ab2058f4d1a34c72b05abb86ae4122c (diff) | |
download | mongo-fe0d238b0ac31f4b2294bda827cc913d59d6de57.tar.gz |
SERVER-7122 Add setParameter option to enable/disable testing commands
Diffstat (limited to 'src/mongo/db/commands/hashcmd.cpp')
-rw-r--r-- | src/mongo/db/commands/hashcmd.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/mongo/db/commands/hashcmd.cpp b/src/mongo/db/commands/hashcmd.cpp index 043ab37a77b..acf4000505e 100644 --- a/src/mongo/db/commands/hashcmd.cpp +++ b/src/mongo/db/commands/hashcmd.cpp @@ -23,6 +23,8 @@ #include <string> #include <vector> +#include "mongo/base/init.h" +#include "mongo/base/status.h" #include "mongo/db/auth/action_set.h" #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/authorization_manager.h" @@ -33,14 +35,17 @@ namespace mongo { + // Testing only, enabled via command-line. class CmdHashElt : public Command { public: CmdHashElt() : Command("_hashBSONElement") {}; virtual LockType locktype() const { return NONE; } virtual bool slaveOk() const { return true; } + // No auth needed because it only works when enabled via command line. + virtual bool requiresAuth() { return false; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, - std::vector<Privilege>* out) {} // No auth required + std::vector<Privilege>* out) {} virtual void help( stringstream& help ) const { help << "returns the hash of the first BSONElement val in a BSONObj"; } @@ -77,5 +82,12 @@ namespace mongo { result.append( "out" , BSONElementHasher::hash64( cmdObj.firstElement() , seed ) ); return true; } - } cmdHashElt; + }; + MONGO_INITIALIZER(RegisterHashEltCmd)(InitializerContext* context) { + if (Command::testCommandsEnabled) { + // Leaked intentionally: a Command registers itself when constructed. + new CmdHashElt(); + } + return Status::OK(); + } } |