--- /dev/null
+/*
+ * 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
#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 {};
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;
+ }
+}
#include "query.h"
#include "schema/time.h"
+#include "schema/policy.h"
#include "schema/processes.h"
#include <osquery/logger.h>
namespace {
using namespace tsqb;
+using namespace vist::schema;
+
auto time = make_table("time",
make_column("hour", &Time::hour),
make_column("minutes", &Time::minutes),
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
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]);
}
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.");
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)));
}
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