Kea 3.3.4
rbac_api.h
Go to the documentation of this file.
1// Copyright (C) 2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef RBAC_API_H
8#define RBAC_API_H
9
10#include <cc/data.h>
11#include <boost/shared_ptr.hpp>
12#include <boost/multi_index_container.hpp>
13#include <boost/multi_index/hashed_index.hpp>
14#include <boost/multi_index/ordered_index.hpp>
15#include <boost/multi_index/mem_fun.hpp>
16#include <set>
17#include <string>
18
19namespace isc {
20namespace rbac {
21
23class Api;
24
26typedef boost::shared_ptr<Api> ApiPtr;
27
29class Api {
30public:
31
37 Api(const std::string& name, const std::string& access,
38 const std::string& hook) : name_(name), access_(access), hook_(hook) {
39 }
40
42 virtual ~Api() = default;
43
47 std::string getName() const {
48 return (name_);
49 }
50
54 std::string getAccess() const {
55 return (access_);
56 }
57
61 void setAccess(const std::string& access) {
62 access_ = access;
63 }
64
68 std::string getHook() const {
69 return (hook_);
70 }
71
75 void setHook(const std::string& hook) {
76 hook_ = hook;
77 }
78
83 static ApiPtr getApiByName(const std::string& name);
84
88 static void fillApiTable(const std::string& dirname);
89
94 static void parse(data::ConstElementPtr cfg, bool others = false);
95
96protected:
98 std::string name_;
99
101 std::string access_;
102
104 std::string hook_;
105};
106
109
112
115
117typedef boost::multi_index_container<
118 // Elements of shared pointer to Api objects.
119 ApiPtr,
120 boost::multi_index::indexed_by<
121 // First index is by name.
122 boost::multi_index::hashed_unique<
123 boost::multi_index::tag<ApiNameIndexTag>,
124 boost::multi_index::const_mem_fun<Api, std::string, &Api::getName>
125 >,
126 // Second index is by access.
127 boost::multi_index::ordered_non_unique<
128 boost::multi_index::tag<ApiAccessIndexTag>,
129 boost::multi_index::const_mem_fun<Api, std::string, &Api::getAccess>
130 >,
131 // Third index is by hook.
132 boost::multi_index::hashed_non_unique<
133 boost::multi_index::tag<ApiHookIndexTag>,
134 boost::multi_index::const_mem_fun<Api, std::string, &Api::getHook>
135 >
136 >
138
140extern ApiTable apiTable;
141
143extern std::set<std::string> apiAccesses;
144
146extern std::set<std::string> apiHooks;
147
148} // end of namespace rbac
149} // end of namespace isc
150#endif
Command from the API class.
Definition rbac_api.h:29
std::string name_
The command name.
Definition rbac_api.h:98
std::string hook_
The name of the hook which registers the command (may not be set).
Definition rbac_api.h:104
std::string getAccess() const
Returns the command access.
Definition rbac_api.h:54
static ApiPtr getApiByName(const std::string &name)
Lookup in the table.
Definition rbac_api.cc:35
void setAccess(const std::string &access)
Set the command access.
Definition rbac_api.h:61
void setHook(const std::string &hook)
Set the command hook name.
Definition rbac_api.h:75
std::string getHook() const
Returns the command hook name.
Definition rbac_api.h:68
std::string getName() const
Returns the command name.
Definition rbac_api.h:47
static void parse(data::ConstElementPtr cfg, bool others=false)
Parse a command config.
Definition rbac_api.cc:96
std::string access_
The command access (read or write).
Definition rbac_api.h:101
virtual ~Api()=default
Destructor.
static void fillApiTable(const std::string &dirname)
Fill the API command table.
Definition rbac_api.cc:44
Api(const std::string &name, const std::string &access, const std::string &hook)
Constructor.
Definition rbac_api.h:37
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
set< string > apiHooks
The API hook list.
Definition rbac_api.cc:32
boost::shared_ptr< Api > ApiPtr
Type of shared pointer to Api.
Definition rbac_api.h:26
ApiTable apiTable
The API command table.
Definition rbac_api.cc:28
set< string > apiAccesses
The API access list (should be "read" and "write").
Definition rbac_api.cc:30
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.
Definition rbac_api.h:137
Defines the logger used by the top-level component of kea-lfc.
A tag for accessing access index.
Definition rbac_api.h:111
A tag for accessing hook index.
Definition rbac_api.h:114
A tag for accessing name index.
Definition rbac_api.h:108