Kea 2.5.8
audit_entry.cc
Go to the documentation of this file.
1// Copyright (C) 2019-2020 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
11#include <boost/make_shared.hpp>
12
13namespace isc {
14namespace db {
15
16AuditEntry::AuditEntry(const std::string& object_type,
17 const uint64_t object_id,
18 const ModificationType& modification_type,
19 const boost::posix_time::ptime& modification_time,
20 const uint64_t revision_id,
21 const std::string& log_message)
22 : object_type_(object_type),
23 object_id_(object_id),
24 modification_type_(modification_type),
25 modification_time_(modification_time),
26 revision_id_(revision_id),
27 log_message_(log_message) {
28 // Check if the provided values are sane.
29 validate();
30}
31
32AuditEntry::AuditEntry(const std::string& object_type,
33 const uint64_t object_id,
34 const ModificationType& modification_type,
35 const uint64_t revision_id,
36 const std::string& log_message)
37 : object_type_(object_type),
38 object_id_(object_id),
39 modification_type_(modification_type),
40 modification_time_(boost::posix_time::microsec_clock::local_time()),
41 revision_id_(revision_id),
42 log_message_(log_message) {
43 // Check if the provided values are sane.
44 validate();
45}
46
48AuditEntry::create(const std::string& object_type,
49 const uint64_t object_id,
50 const ModificationType& modification_type,
51 const boost::posix_time::ptime& modification_time,
52 const uint64_t revision_id,
53 const std::string& log_message) {
54 return (boost::make_shared<AuditEntry>(object_type, object_id,
55 modification_type,
56 modification_time,
57 revision_id,
58 log_message));
59}
60
62AuditEntry::create(const std::string& object_type,
63 const uint64_t object_id,
64 const ModificationType& modification_type,
65 const uint64_t revision_id,
66 const std::string& log_message) {
67 return (boost::make_shared<AuditEntry>(object_type, object_id,
68 modification_type,
69 revision_id,
70 log_message));
71}
72
73void
74AuditEntry::validate() const {
75 // object type can't be empty
76 if (object_type_.empty()) {
77 isc_throw(BadValue, "object type can't be empty in the database "
78 "audit entry");
79
80 // modification time must be a valid date time value
81 } else if (modification_time_.is_not_a_date_time()) {
82 isc_throw(BadValue, "modification time value is not a valid time "
83 "object in the database audit entry");
84 }
85}
86
87} // end of namespace isc::db
88} // end of namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
ModificationType
Types of the modifications.
Definition: audit_entry.h:73
static AuditEntryPtr create(const std::string &object_type, const uint64_t object_id, const ModificationType &modification_type, const boost::posix_time::ptime &modification_time, const uint64_t revision_id, const std::string &log_message)
Factory function creating an instance of AuditEntry.
Definition: audit_entry.cc:48
AuditEntry(const std::string &object_type, const uint64_t object_id, const ModificationType &modification_type, const boost::posix_time::ptime &modification_time, const uint64_t revision_id, const std::string &log_message)
Constructor using explicit modification time and id.
Definition: audit_entry.cc:16
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< AuditEntry > AuditEntryPtr
Pointer to the AuditEntry object.
Definition: audit_entry.h:26
Defines the logger used by the top-level component of kea-lfc.