36 auto const& it =
apiTable.find(name);
47 dir = opendir(dirname.c_str());
50 <<
"': " <<
string(strerror(errno)));
52 std::unique_ptr<DIR, void(*)(DIR*)> defer(dir, [](DIR* d) { closedir(d); });
54 struct dirent *ent = readdir(dir);
59 string filename(ent->d_name);
60 size_t len = filename.size();
65 if ((filename[0] ==
'_') ||
66 (filename[len - 1] !=
'n') ||
67 (filename[len - 2] !=
'o') ||
68 (filename[len - 3] !=
's') ||
69 (filename[len - 4] !=
'j') ||
70 (filename[len - 5] !=
'.')) {
74 filename = dirname +
"/" + filename;
78 }
catch (
const std::exception& ex) {
80 <<
"' failed with " << ex.what());
85 <<
"': got no command config?");
106 for (
auto const& entry : cfg->mapValue()) {
107 if (entry.first ==
"name") {
111 name = entry.second->stringValue();
115 }
else if (entry.first ==
"access") {
119 access = entry.second->stringValue();
120 if (access.empty()) {
123 if ((access !=
"read") && (access !=
"write")) {
125 <<
"' is not 'read' or 'write'");
127 }
else if (entry.first ==
"hook") {
131 hook = entry.second->stringValue();
132 }
else if (!others) {
134 << entry.first <<
"'");
140 if (access.empty()) {
149 static_cast<void>(
apiHooks.insert(hook));
static ElementPtr fromJSONFile(const std::string &file_name, bool preproc=false)
Reads contents of specified file and interprets it as JSON.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
static ApiPtr getApiByName(const std::string &name)
Lookup in the table.
static void parse(data::ConstElementPtr cfg, bool others=false)
Parse a command config.
static void fillApiTable(const std::string &dirname)
Fill the API command table.
Api(const std::string &name, const std::string &access, const std::string &hook)
Constructor.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
boost::shared_ptr< const Element > ConstElementPtr
isc::log::Logger rbac_logger("rbac-hooks")
set< string > apiHooks
The API hook list.
boost::shared_ptr< Api > ApiPtr
Type of shared pointer to Api.
ApiTable apiTable
The API command table.
set< string > apiAccesses
The API access list (should be "read" and "write").
boost::multi_index_container< ApiPtr, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::tag< ApiNameIndexTag >, boost::multi_index::const_mem_fun< Api, std::string, &Api::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ApiAccessIndexTag >, boost::multi_index::const_mem_fun< Api, std::string, &Api::getAccess > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< ApiHookIndexTag >, boost::multi_index::const_mem_fun< Api, std::string, &Api::getHook > > > > ApiTable
The type of the API command table.
Defines the logger used by the top-level component of kea-lfc.
const isc::log::MessageID RBAC_READ_API_FILES