2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +00:00

[#396,!205] Audit revision timestamp is set by Kea.

This commit is contained in:
Marcin Siodelski
2019-01-28 20:14:59 +01:00
parent 58e6f3b475
commit 84d9d7a401
7 changed files with 37 additions and 26 deletions

View File

@@ -755,8 +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);
server_selector, "subnet set", true);
try {
@@ -872,8 +871,7 @@ public:
ScopedAuditRevision
audit_revision(this,
MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
server_selector,
log_message, cascade_delete);
server_selector, log_message, cascade_delete);
auto count = deleteFromTable(index, server_selector, operation, keys...);
@@ -1166,8 +1164,7 @@ public:
ScopedAuditRevision
audit_revision(this,
MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
server_selector,
"shared network set", true);
server_selector, "shared network set", true);
try {
@@ -1281,8 +1278,7 @@ public:
ScopedAuditRevision
audit_revision(this,
MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
server_selector,
"global option set", false);
server_selector, "global option set", false);
if (existing_option) {
in_bindings.push_back(MySqlBinding::createString(tag));
@@ -1352,8 +1348,8 @@ public:
ScopedAuditRevision
audit_revision(this,
MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
server_selector,
"subnet specific option set", cascade_update);
server_selector, "subnet specific option set",
cascade_update);
if (existing_option) {
in_bindings.push_back(MySqlBinding::createString(tag));
@@ -1441,8 +1437,8 @@ public:
ScopedAuditRevision
audit_revision(this,
MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
server_selector,
"pool specific option set", cascade_update);
server_selector, "pool specific option set",
cascade_update);
if (existing_option) {
in_bindings.push_back(MySqlBinding::createString(tag));
@@ -1512,8 +1508,7 @@ public:
ScopedAuditRevision
audit_revision(this,
MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
server_selector,
"shared network specific option set",
server_selector, "shared network specific option set",
cascade_update);
if (existing_option) {
@@ -1837,8 +1832,7 @@ public:
ScopedAuditRevision
audit_revision(this,
MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
server_selector,
"option definition set",
server_selector, "option definition set",
true);
if (existing_definition) {
@@ -2053,7 +2047,7 @@ TaggedStatementArray;
/// retrieve data from the database.
TaggedStatementArray tagged_statements = { {
{ MySqlConfigBackendDHCPv4Impl::CREATE_AUDIT_REVISION,
"CALL createAuditRevisionDHCP4(?, ?, ?)"
"CALL createAuditRevisionDHCP4(?, ?, ?, ?)"
},
// Select global parameter by name.

View File

@@ -32,7 +32,9 @@ ScopedAuditRevision::ScopedAuditRevision(MySqlConfigBackendImpl* impl,
const std::string& log_message,
bool cascade_transaction)
: impl_(impl) {
impl_->createAuditRevision(index, server_selector, log_message,
impl_->createAuditRevision(index, server_selector,
boost::posix_time::microsec_clock::local_time(),
log_message,
cascade_transaction);
}
@@ -86,6 +88,7 @@ MySqlConfigBackendImpl::~MySqlConfigBackendImpl() {
void
MySqlConfigBackendImpl::createAuditRevision(const int index,
const ServerSelector& server_selector,
const boost::posix_time::ptime& audit_ts,
const std::string& log_message,
const bool cascade_transaction) {
// Do not touch existing audit revision in case of the cascade update.
@@ -97,6 +100,7 @@ MySqlConfigBackendImpl::createAuditRevision(const int index,
"audit revision");
MySqlBindingCollection in_bindings = {
MySqlBinding::createTimestamp(audit_ts),
MySqlBinding::createString(tag),
MySqlBinding::createString(log_message),
MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(cascade_transaction))

View File

@@ -171,6 +171,8 @@ public:
///
/// @param index query index.
/// @param server_selector Server selector.
/// @param audit_ts Timestamp to be associated with the audit
/// revision.
/// @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
@@ -179,6 +181,7 @@ public:
/// audit entry for the owning element should be created.
void createAuditRevision(const int index,
const db::ServerSelector& server_selector,
const boost::posix_time::ptime& audit_ts,
const std::string& log_message,
const bool cascade_transaction);

View File

@@ -296,6 +296,9 @@ public:
timestamps_["tomorrow"] = timestamps_["today"] + boost::posix_time::hours(24);
}
/// @brief Logs audit entries in the @c audit_entries_ member.
///
/// This function is called in case of an error.
std::string logExistingAuditEntries() {
std::ostringstream s;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -80,7 +80,7 @@ public:
OptionDescriptor(const OptionPtr& opt, bool persist,
const std::string& formatted_value = "",
data::ConstElementPtr user_context = data::ConstElementPtr())
: option_(opt), persistent_(persist),
: data::StampedElement(), option_(opt), persistent_(persist),
formatted_value_(formatted_value),
space_name_() {
setContext(user_context);
@@ -90,14 +90,15 @@ public:
///
/// @param persist if true option is always sent.
OptionDescriptor(bool persist)
: option_(OptionPtr()), persistent_(persist),
: data::StampedElement(), option_(OptionPtr()), persistent_(persist),
formatted_value_(), space_name_() {};
/// @brief Constructor.
///
/// @param desc descriptor
OptionDescriptor(const OptionDescriptor& desc)
: option_(desc.option_), persistent_(desc.persistent_),
: data::StampedElement(), option_(desc.option_),
persistent_(desc.persistent_),
formatted_value_(desc.formatted_value_),
space_name_(desc.space_name_) {
setContext(desc.getContext());

View File

@@ -1459,6 +1459,8 @@ ALTER TABLE dhcp4_audit
-- data in the database, e.g. when new subnet is added.
--
-- Parameters:
-- - audit_ts timestamp to be associated with the audit
-- revision.
-- - server_tag is used to retrieve the server_id which
-- associates the changes applied with the particular
-- server or all servers.
@@ -1478,14 +1480,15 @@ ALTER TABLE dhcp4_audit
-- -----------------------------------------------------
DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4;
DELIMITER $$
CREATE PROCEDURE createAuditRevisionDHCP4(IN server_tag VARCHAR(256),
CREATE PROCEDURE createAuditRevisionDHCP4(IN audit_ts TIMESTAMP(6),
IN server_tag VARCHAR(256),
IN audit_log_message TEXT,
IN cascade_transaction TINYINT(1))
BEGIN
DECLARE srv_id BIGINT(20);
SELECT id INTO srv_id FROM dhcp4_server WHERE tag = server_tag;
INSERT INTO dhcp4_audit_revision (modification_ts, server_id, log_message)
VALUES (NOW(), srv_id, audit_log_message);
VALUES (audit_ts, srv_id, audit_log_message);
SET @audit_revision_id = LAST_INSERT_ID();
SET @cascade_transaction = cascade_transaction;
END $$

View File

@@ -142,6 +142,8 @@ ALTER TABLE dhcp4_audit
# data in the database, e.g. when new subnet is added.
--
# Parameters:
# - audit_ts timestamp to be associated with the audit
# revision.
# - server_tag is used to retrieve the server_id which
# associates the changes applied with the particular
# server or all servers.
@@ -161,14 +163,15 @@ ALTER TABLE dhcp4_audit
# -----------------------------------------------------
DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4;
DELIMITER $$
CREATE PROCEDURE createAuditRevisionDHCP4(IN server_tag VARCHAR(256),
CREATE PROCEDURE createAuditRevisionDHCP4(IN audit_ts TIMESTAMP(6),
IN server_tag VARCHAR(256),
IN audit_log_message TEXT,
IN cascade_transaction TINYINT(1))
BEGIN
DECLARE srv_id BIGINT(20);
SELECT id INTO srv_id FROM dhcp4_server WHERE tag = server_tag;
INSERT INTO dhcp4_audit_revision (modification_ts, server_id, log_message)
VALUES (NOW(), srv_id, audit_log_message);
VALUES (audit_ts, srv_id, audit_log_message);
SET @audit_revision_id = LAST_INSERT_ID();
SET @cascade_transaction = cascade_transaction;
END $$