summaryrefslogtreecommitdiffstats
path: root/src/lib/database/audit_entry.cc
blob: 92cb88702f90a642f4f80237d5bff60da57631b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (C) 2019-2020 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <database/audit_entry.h>
#include <exceptions/exceptions.h>
#include <boost/make_shared.hpp>

namespace isc {
namespace db {

AuditEntry::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)
    : object_type_(object_type),
      object_id_(object_id),
      modification_type_(modification_type),
      modification_time_(modification_time),
      revision_id_(revision_id),
      log_message_(log_message) {
    // Check if the provided values are sane.
    validate();
}

AuditEntry::AuditEntry(const std::string& object_type,
                       const uint64_t object_id,
                       const ModificationType& modification_type,
                       const uint64_t revision_id,
                       const std::string& log_message)
    : object_type_(object_type),
      object_id_(object_id),
      modification_type_(modification_type),
      modification_time_(boost::posix_time::microsec_clock::local_time()),
      revision_id_(revision_id),
      log_message_(log_message) {
    // Check if the provided values are sane.
    validate();
}

AuditEntryPtr
AuditEntry::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) {
    return (boost::make_shared<AuditEntry>(object_type, object_id,
                                           modification_type,
                                           modification_time,
                                           revision_id,
                                           log_message));
}

AuditEntryPtr
AuditEntry::create(const std::string& object_type,
                   const uint64_t object_id,
                   const ModificationType& modification_type,
                   const uint64_t revision_id,
                   const std::string& log_message) {
    return (boost::make_shared<AuditEntry>(object_type, object_id,
                                           modification_type,
                                           revision_id,
                                           log_message));
}

void
AuditEntry::validate() const {
    // object type can't be empty
    if (object_type_.empty()) {
        isc_throw(BadValue, "object type can't be empty in the database "
                  "audit entry");

    // modification time must be a valid date time value
    } else if (modification_time_.is_not_a_date_time()) {
        isc_throw(BadValue, "modification time value is not a valid time "
                  "object in the database audit entry");
    }
}

} // end of namespace isc::db
} // end of namespace isc