summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2018-04-25 11:28:40 -0400
committerBilly Donahue <billy.donahue@mongodb.com>2018-04-25 15:45:49 -0400
commitc50a57061af31f92c1c6aab09b1417ab127fed0c (patch)
tree488537b275059c8efd0292fd14e899b892868619
parent2deac715b6345a8103acc1da6187f77e65843019 (diff)
downloadmongo-c50a57061af31f92c1c6aab09b1417ab127fed0c.tar.gz
SERVER-34653 refactor audit's parseNs(..) to ns()
-rw-r--r--src/mongo/db/audit.cpp2
-rw-r--r--src/mongo/db/audit.h4
-rw-r--r--src/mongo/db/commands.cpp38
3 files changed, 22 insertions, 22 deletions
diff --git a/src/mongo/db/audit.cpp b/src/mongo/db/audit.cpp
index 6156350bae0..0ae7a5bb946 100644
--- a/src/mongo/db/audit.cpp
+++ b/src/mongo/db/audit.cpp
@@ -37,7 +37,7 @@ void mongo::audit::logAuthentication(Client* client,
void mongo::audit::logCommandAuthzCheck(Client* client,
const OpMsgRequest& cmdObj,
- CommandInterface* command,
+ const CommandInterface& command,
ErrorCodes::Error result) {}
void mongo::audit::logDeleteAuthzCheck(Client* client,
diff --git a/src/mongo/db/audit.h b/src/mongo/db/audit.h
index d05ed79b8c9..be20849545a 100644
--- a/src/mongo/db/audit.h
+++ b/src/mongo/db/audit.h
@@ -61,7 +61,7 @@ class CommandInterface {
public:
virtual ~CommandInterface() = default;
virtual void redactForLogging(mutablebson::Document* cmdObj) const = 0;
- virtual std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const = 0;
+ virtual NamespaceString ns() const = 0;
};
/**
@@ -84,7 +84,7 @@ void logAuthentication(Client* client,
*/
void logCommandAuthzCheck(Client* client,
const OpMsgRequest& cmdObj,
- CommandInterface* command,
+ const CommandInterface& command,
ErrorCodes::Error result);
/**
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index acedc4dc486..2e6f36007b0 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -69,23 +69,6 @@ const WriteConcernOptions kMajorityWriteConcern(
WriteConcernOptions::SyncMode::UNSET,
Seconds(60));
-// A facade presenting CommandDefinition as an audit::CommandInterface.
-class CommandAuditHook : public audit::CommandInterface {
-public:
- explicit CommandAuditHook(const Command* command) : _command{command} {}
-
- void redactForLogging(mutablebson::Document* cmdObj) const final {
- _command->redactForLogging(cmdObj);
- }
-
- std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const final {
- return _command->parseNs(dbname, cmdObj);
- }
-
-private:
- const Command* _command;
-};
-
} // namespace
@@ -117,8 +100,25 @@ void CommandHelpers::logAuthViolation(OperationContext* opCtx,
const Command* command,
const OpMsgRequest& request,
ErrorCodes::Error err) {
- CommandAuditHook hook{command};
- audit::logCommandAuthzCheck(opCtx->getClient(), request, &hook, err);
+ struct Hook final : public audit::CommandInterface {
+ public:
+ Hook(const Command* command, const OpMsgRequest& request)
+ : _command{command}, _request{request} {}
+
+ void redactForLogging(mutablebson::Document* cmdObj) const override {
+ _command->redactForLogging(cmdObj);
+ }
+
+ NamespaceString ns() const override {
+ return NamespaceString(
+ _command->parseNs(_request.getDatabase().toString(), _request.body));
+ }
+
+ private:
+ const Command* _command;
+ const OpMsgRequest& _request;
+ };
+ audit::logCommandAuthzCheck(opCtx->getClient(), request, Hook(command, request), err);
}
void CommandHelpers::uassertNoDocumentSequences(StringData commandName,