Kea  2.1.7-git
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 
9 #include <database/audit_entry.h>
10 #include <exceptions/exceptions.h>
11 #include <boost/make_shared.hpp>
12 
13 namespace isc {
14 namespace db {
15 
16 AuditEntry::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 
32 AuditEntry::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 
48 AuditEntry::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 
62 AuditEntry::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 
73 void
74 AuditEntry::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
boost::shared_ptr< AuditEntry > AuditEntryPtr
Pointer to the AuditEntry object.
Definition: audit_entry.h:23
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Defines the logger used by the top-level component of kea-lfc.
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
ModificationType
Types of the modifications.
Definition: audit_entry.h:73
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