1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2015 Couchbase, Inc.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 #pragma once
18 
19 #include <inttypes.h>
20 #include <nlohmann/json_fwd.hpp>
21 #include <platform/sized_buffer.h>
22 #include <string>
23 
24 class AuditImpl;
25 class AuditConfig;
26 
27 class Event {
28 public:
29     const uint32_t id;
30     const std::string payload;
31 
32     // Constructor required for ConfigureEvent
Event()33     Event()
34         : id(0) {}
35 
Event(const uint32_t event_id, cb::const_char_buffer payload)36     Event(const uint32_t event_id, cb::const_char_buffer payload)
37         : id(event_id), payload(payload.data(), payload.size()) {
38     }
39 
40     virtual bool process(AuditImpl& audit);
41 
42     /**
43      * State whether a given event should be filtered out given the userid.
44      *
45      * @param eventPayload  pointer to the event payload
46      * @param config  reference to the audit configuration
47      * @param userid  reference to the userid_type string, which will either be
48      *                effective_userid or real_userid
49      * @return true if event should be filtered out, else false.
50      */
51     bool filterEventByUserid(const nlohmann::json& eventPayload,
52                              const AuditConfig& config,
53                              const std::string& userid_type);
54 
55     /**
56      * State whether a given event should be filtered out.
57      *
58      * @param eventPayload  pointer to the event payload
59      * @param config  reference to the audit configuration
60      * @return true if event should be filtered out, else false.
61      */
62     bool filterEvent(const nlohmann::json& eventPayload,
63                      const AuditConfig& audit);
64 
~Event()65     virtual ~Event() {}
66 
67 };
68