]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#396,!205] Server selector is now used for creating audit revisions.
authorMarcin Siodelski <marcin@isc.org>
Fri, 25 Jan 2019 15:34:16 +0000 (16:34 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 30 Jan 2019 09:18:59 +0000 (10:18 +0100)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h

index 903206d132eb1d87dedf723ebd81b4248b6b35c7..7c53bdd7f51801bfd961d8612a96327c662d7487 100644 (file)
@@ -220,7 +220,7 @@ public:
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision
             audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
-                           "global parameter set", false);
+                           server_selector, "global parameter set", false);
 
         // Try to update the existing row.
         if (conn_.updateDeleteQuery(MySqlConfigBackendDHCPv4Impl::UPDATE_GLOBAL_PARAMETER4,
@@ -755,6 +755,7 @@ public:
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision audit_revision(this,
                                            MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+                                           server_selector,
                                            "subnet set", true);
 
         try {
@@ -869,7 +870,9 @@ public:
         // Create scoped audit revision. As long as this instance exists
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision
-            audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+            audit_revision(this,
+                           MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+                           server_selector,
                            log_message, cascade_delete);
 
         auto count = deleteFromTable(index, server_selector, operation, keys...);
@@ -1161,7 +1164,9 @@ public:
         // Create scoped audit revision. As long as this instance exists
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision
-            audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+            audit_revision(this,
+                           MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+                           server_selector,
                            "shared network set", true);
 
         try {
@@ -1274,7 +1279,9 @@ public:
         // Create scoped audit revision. As long as this instance exists
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision
-            audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+            audit_revision(this,
+                           MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+                           server_selector,
                            "global option set", false);
 
         if (existing_option) {
@@ -1343,7 +1350,9 @@ public:
         // Create scoped audit revision. As long as this instance exists
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision
-            audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+            audit_revision(this,
+                           MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+                           server_selector,
                            "subnet specific option set", cascade_update);
 
         if (existing_option) {
@@ -1430,7 +1439,9 @@ public:
         // Create scoped audit revision. As long as this instance exists
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision
-            audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+            audit_revision(this,
+                           MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+                           server_selector,
                            "pool specific option set", cascade_update);
 
         if (existing_option) {
@@ -1499,7 +1510,9 @@ public:
         // Create scoped audit revision. As long as this instance exists
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision
-            audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+            audit_revision(this,
+                           MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+                           server_selector,
                            "shared network specific option set",
                            cascade_update);
 
@@ -1822,7 +1835,9 @@ public:
         // Create scoped audit revision. As long as this instance exists
         // no new audit revisions are created in any subsequent calls.
         ScopedAuditRevision
-            audit_revision(this, MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+            audit_revision(this,
+                           MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
+                           server_selector,
                            "option definition set",
                            true);
 
index 66fe2187d35dbb33123da1f80419521a4110a410..67213e88ab5b6eac27e51250bdde1a26755bcb5a 100644 (file)
@@ -28,10 +28,12 @@ namespace dhcp {
 MySqlConfigBackendImpl::
 ScopedAuditRevision::ScopedAuditRevision(MySqlConfigBackendImpl* impl,
                                          const int index,
+                                         const ServerSelector& server_selector,
                                          const std::string& log_message,
                                          bool cascade_transaction)
     : impl_(impl) {
-    impl_->initAuditRevision(index, log_message, cascade_transaction);
+    impl_->createAuditRevision(index, server_selector, log_message,
+                               cascade_transaction);
 }
 
 MySqlConfigBackendImpl::
@@ -82,16 +84,20 @@ MySqlConfigBackendImpl::~MySqlConfigBackendImpl() {
 }
 
 void
-MySqlConfigBackendImpl::initAuditRevision(const int index,
-                                          const std::string& log_message,
-                                          const bool cascade_transaction) {
+MySqlConfigBackendImpl::createAuditRevision(const int index,
+                                            const ServerSelector& server_selector,
+                                            const std::string& log_message,
+                                            const bool cascade_transaction) {
     // Do not touch existing audit revision in case of the cascade update.
     if (audit_revision_created_) {
         return;
     }
 
+    auto tag = getServerTag(server_selector, "creating new configuration "
+                            "audit revision");
+
     MySqlBindingCollection in_bindings = {
-        MySqlBinding::createString("all"),
+        MySqlBinding::createString(tag),
         MySqlBinding::createString(log_message),
         MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(cascade_transaction))
     };
index e0f66ee056b74d36f2c3804a62c989a13d4b487c..251ed136e6eed7e4d22642c0e6546e660e8f0c82 100644 (file)
@@ -32,7 +32,7 @@ class MySqlConfigBackendImpl {
 protected:
 
     /// @brief RAII object used to protect against creating multiple
-    /// audit revision during cascade configuration updates.
+    /// audit revisions during cascade configuration updates.
     ///
     /// Audit revision is created per a single database transaction.
     /// It includes log message associated with the configuration
@@ -51,13 +51,15 @@ protected:
     /// against creation of multiple audit revisions when child
     /// objects are inserted or updated in the database. When the
     /// instance of this object goes out of scope the new audit
-    /// revisions can be created.
+    /// revisions can be created. The caller must ensure that
+    /// the instance of this object exists throughout the whole
+    /// transaction with the database.
     class ScopedAuditRevision {
     public:
 
         /// @brief Constructor.
         ///
-        /// Initializes new audit revision and sets the flag in the
+        /// Creates new audit revision and sets the flag in the
         /// MySQL CB implementation object which prevents new audit
         /// revisions to be created while this instance exists.
         ///
@@ -65,6 +67,7 @@ protected:
         /// @param index index of the query to set session variables
         /// used for creation of the audit revision and the audit
         /// entries.
+        /// @param server_selector Server selector.
         /// @param log_message log message associated with the audit
         /// revision to be inserted into the database.
         /// @param cascade_transaction boolean flag indicating if
@@ -73,6 +76,7 @@ protected:
         /// options) won't be created.
         ScopedAuditRevision(MySqlConfigBackendImpl* impl,
                             const int index,
+                            const db::ServerSelector& server_selector,
                             const std::string& log_message,
                             bool cascade_transaction);
 
@@ -160,25 +164,23 @@ public:
 
     /// @brief Invokes the corresponding stored procedure in MySQL.
     ///
-    /// The @c initAuditRevision stored procedure initializes several
-    /// session variables used when creating new audit revision in the
-    /// database. That includes setting a log message for the revision,
-    /// setting the boolean value indicating if the audit entries should
-    /// be created for DHCP options (that should only be the case when
-    /// the options are not added as part of the subnet, shared network
-    /// etc.). Finally, it resets the session variables used internally
-    /// by the database to corrdinate between the triggers.
+    /// The @c createAuditRevision stored procedure creates new audit
+    /// revision and initializes several session variables to be used when
+    /// the audit entries will be created for the inserted, updated or
+    /// deleted configuration elements.
     ///
     /// @param index query index.
+    /// @param server_selector Server selector.
     /// @param log_message log message to be used for the audit revision.
     /// @param cascade_transaction Boolean value indicating whether the
     /// configuration modification is performed as part of the ownining
     /// element modification, e.g. subnet is modified resulting in
     /// modification of the DHCP options it owns. In that case only the
     /// audit entry for the owning element should be created.
-    void initAuditRevision(const int index,
-                           const std::string& log_message,
-                           const bool cascade_transaction);
+    void createAuditRevision(const int index,
+                             const db::ServerSelector& server_selector,
+                             const std::string& log_message,
+                             const bool cascade_transaction);
 
     /// @brief Clears the flag blocking creation of the new audit revisions.
     ///