mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-06 08:55:13 +00:00
[#396,!205] Added audit for global parameters.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
|
||||
# Copyright (C) 2012-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
|
||||
@@ -1334,6 +1334,118 @@ SET version = '7', minor = '0';
|
||||
|
||||
# This line concludes database upgrade to version 7.0.
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `dhcp4_audit_revision`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS dhcp4_audit_revision (
|
||||
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
modification_ts TIMESTAMP NOT NULL,
|
||||
log_message TEXT,
|
||||
PRIMARY KEY (id),
|
||||
KEY key_dhcp4_audit_revision_by_modification_ts (modification_ts)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Drop columns from the dhcp4_audit table which now
|
||||
-- belong to the dhcp4_audit_revision.
|
||||
-- -----------------------------------------------------
|
||||
ALTER TABLE dhcp4_audit
|
||||
DROP COLUMN modification_ts,
|
||||
DROP COLUMN log_message;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Add column revision_id and the foreign key with a
|
||||
-- refrence to the dhcp4_audit_revision table.
|
||||
-- -----------------------------------------------------
|
||||
ALTER TABLE dhcp4_audit
|
||||
ADD COLUMN revision_id BIGINT(20) UNSIGNED NOT NULL;
|
||||
|
||||
ALTER TABLE dhcp4_audit
|
||||
ADD CONSTRAINT fk_dhcp4_audit_revision FOREIGN KEY (revision_id)
|
||||
REFERENCES dhcp4_audit_revision (id)
|
||||
ON DELETE NO ACTION ON UPDATE CASCADE;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Stored procedure which creates a new entry in the
|
||||
-- dhcp4_audit_revision table. This procedure should
|
||||
-- be called from the triggers of the tables where
|
||||
-- the config modifications are applied. If the
|
||||
-- corresponding revision doesn't exist, it will be
|
||||
-- created by this procedure.
|
||||
-- -----------------------------------------------------
|
||||
DROP PROCEDURE IF EXISTS createAuditRevisionDHCP4;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE createAuditRevisionDHCP4()
|
||||
BEGIN
|
||||
IF @audit_revision_id IS NULL THEN
|
||||
INSERT INTO dhcp4_audit_revision (modification_ts, log_message)
|
||||
VALUES (NOW(), @audit_log_message);
|
||||
SET @audit_revision_id = LAST_INSERT_ID();
|
||||
END IF;
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Stored procedure which creates a new entry in the
|
||||
-- dhcp4_audit table. It should be called from the
|
||||
-- triggers of the tables where the config modifications
|
||||
-- are applied. The @audit_revision_id variable contains
|
||||
-- the revision id to be placed in the audit entries.
|
||||
-- ----------------------------------------------------
|
||||
DROP PROCEDURE IF EXISTS createAuditEntryDHCP4;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE createAuditEntryDHCP4(IN object_type_val VARCHAR(256),
|
||||
IN object_id_val BIGINT(20) UNSIGNED,
|
||||
IN modification_type_val TINYINT(1))
|
||||
BEGIN
|
||||
INSERT INTO dhcp4_audit (object_type, object_id, modification_type, revision_id)
|
||||
VALUES (object_type_val, object_id_val, modification_type_val, @audit_revision_id);
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Triggers used to create entries in the audit
|
||||
-- tables upon insertion, update or deletion of the
|
||||
-- configuration entries.
|
||||
-- -----------------------------------------------------
|
||||
|
||||
# Create dhcp4_global_parameter insert trigger
|
||||
DELIMITER $$
|
||||
CREATE TRIGGER dhcp4_global_parameter_AINS AFTER INSERT ON dhcp4_global_parameter
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL createAuditRevisionDHCP4();
|
||||
CALL createAuditEntryDHCP4('dhcp4_global_parameter', NEW.id, 0);
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Create dhcp4_global_parameter update trigger
|
||||
DELIMITER $$
|
||||
CREATE TRIGGER dhcp4_global_parameter_AUPD AFTER UPDATE ON dhcp4_global_parameter
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL createAuditRevisionDHCP4();
|
||||
CALL createAuditEntryDHCP4('dhcp4_global_parameter', NEW.id, 1);
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Create dhcp4_global_parameter delete trigger
|
||||
DELIMITER $$
|
||||
CREATE TRIGGER dhcp4_global_parameter_ADEL AFTER DELETE ON dhcp4_global_parameter
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL createAuditRevisionDHCP4();
|
||||
CALL createAuditEntryDHCP4('dhcp4_global_parameter', OLD.id, 2);
|
||||
END $$
|
||||
DELIMITER ;
|
||||
|
||||
# Update the schema version number
|
||||
UPDATE schema_version
|
||||
SET version = '8', minor = '0';
|
||||
|
||||
# This line concludes database upgrade to version 8.0.
|
||||
|
||||
|
||||
# Notes:
|
||||
#
|
||||
# Indexes
|
||||
|
Reference in New Issue
Block a user