Add policy virtual table
authorSangwan Kwon <sangwan.kwon@samsung.com>
Thu, 24 Oct 2019 02:42:37 +0000 (11:42 +0900)
committerSangwan Kwon <sangwan.kwon@samsung.com>
Thu, 24 Oct 2019 02:42:37 +0000 (11:42 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
src/vist/client/schema/policy.h [new file with mode: 0644]
src/vist/client/schema/processes.h
src/vist/client/schema/time.h
src/vist/client/tests/virtual_table_tests.cpp
src/vist/client/virtual-table.cpp

diff --git a/src/vist/client/schema/policy.h b/src/vist/client/schema/policy.h
new file mode 100644 (file)
index 0000000..17d4a3e
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+
+/**
+ * @file processes.h
+ * @brief The scheme of policy
+ */
+
+
+#pragma once
+
+#include <string>
+
+namespace vist {
+namespace schema {
+
+struct Policy {
+       std::string     name;
+       std::string value;
+};
+
+} // namesapce schema
+} // namesapce vist
index d95dd63f39692a5b71509f0de95c382258c4794a..9e9325cba10d7dd9daa8902eb9b36c5894acc558 100644 (file)
@@ -25,6 +25,9 @@
 
 #include <string>
 
+namespace vist {
+namespace schema {
+
 struct Processes {
        long long int pid;
        std::string name;
@@ -38,3 +41,6 @@ struct Processes {
        long long int resident_size;
        long long int parent;
 };
+
+} // namesapce schema
+} // namesapce vist
index 18a8034e3f11be848404b02d647895a31f26c175..02258dfb621d8959aeef664eed0f4e3b6c421161 100644 (file)
 
 #pragma once
 
+namespace vist {
+namespace schema {
+
 struct Time {
        int hour;
        int minutes;
        int seconds;
 };
+
+} // namesapce schema
+} // namesapce vist
index 7e1783593bd0db8891400d241722029cf90e769e..b30a4e5d366dea2f4fb0e644069bff88cf2c72d6 100644 (file)
 #include "../virtual-table.h"
 
 #include "../schema/time.h"
+#include "../schema/policy.h"
 #include "../schema/processes.h"
 
 using namespace osquery;
 using namespace vist;
+using namespace vist::schema;
 
 class VirtualTableTests : public testing::Test {};
 
@@ -103,3 +105,16 @@ TEST_F(VirtualTableTests, processes_table) {
                LOG(INFO) << "\t parent: " << result.parent;
        }
 }
+
+TEST_F(VirtualTableTests, policy_table) {
+       VirtualTable<Policy> table;
+       EXPECT_TRUE(table.size() > 0);
+
+       for(const auto& row : table) {
+               Policy policy = { row[&Policy::name], row[&Policy::value] };
+
+               LOG(INFO) << "[Test] Policy table:";
+               LOG(INFO) << "\t name: " << policy.name;
+               LOG(INFO) << "\t value: " << policy.value;
+       }
+}
index 32483067ddedeec17d473d2dee2114bff23feaba..a90d18ef7b802d46e0686065deb1e2cdc51d051a 100644 (file)
@@ -23,6 +23,7 @@
 #include "query.h" 
 
 #include "schema/time.h"
+#include "schema/policy.h"
 #include "schema/processes.h"
 
 #include <osquery/logger.h>
@@ -34,6 +35,8 @@
 namespace {
 
 using namespace tsqb;
+using namespace vist::schema;
+
 auto time = make_table("time",
                                           make_column("hour", &Time::hour),
                                           make_column("minutes", &Time::minutes),
@@ -51,7 +54,11 @@ auto processes = make_table("processes",
                                                        make_column("on_disk", &Processes::on_disk),
                                                        make_column("parent", &Processes::parent));
 
-auto db = make_database("db", time, processes);
+auto policy = make_table("policy",
+                                                make_column("name", &Policy::name),
+                                                make_column("value", &Policy::value));
+
+auto metaDB = make_database("db", time, processes, policy);
 
 } // anonymous namespace
 
@@ -60,7 +67,7 @@ namespace vist {
 template <typename T>
 VirtualRow<T>::VirtualRow()
 {
-       auto results = Query::Execute(db.selectAll<T>());
+       auto results = Query::Execute(metaDB.selectAll<T>());
        if (results.size() > 0)
                this->data = std::move(results[0]);
 }
@@ -77,7 +84,7 @@ Member VirtualRow<T>::at(Member Struct::* field) const
        if (this->data.size() == 0)
                throw std::runtime_error("Data is not exist.");
 
-       std::string key = db.getColumnName(field);
+       std::string key = metaDB.getColumnName(field);
        if (key.empty())
                throw std::runtime_error("Key is not exist.");
 
@@ -110,7 +117,7 @@ Member VirtualRow<T>::operator[](Member Struct::*field) const
 template <typename T>
 VirtualTable<T>::VirtualTable()
 {
-       auto results = Query::Execute(db.selectAll<T>());
+       auto results = Query::Execute(metaDB.selectAll<T>());
        for (auto& r : results)
                this->dataset.emplace_back(VirtualRow<T>(std::move(r)));
 }
@@ -130,4 +137,9 @@ template long long int VirtualRow<Processes>::operator[](long long int Processes
 template std::string VirtualRow<Processes>::at(std::string Processes::*) const;
 template std::string VirtualRow<Processes>::operator[](std::string Processes::*) const;
 
+template class VirtualTable<Policy>;
+template class VirtualRow<Policy>;
+template std::string VirtualRow<Policy>::at(std::string Policy::*) const;
+template std::string VirtualRow<Policy>::operator[](std::string Policy::*) const;
+
 } // namespace vist