|  | #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_TRIE_NODE_H_ | 
|  | #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_TRIE_NODE_H_ | 
|  |  | 
|  | #include <memory> | 
|  | #include <string> | 
|  | #include <string_view> | 
|  | #include <vector> | 
|  |  | 
|  | #include "absl/container/flat_hash_map.h" | 
|  | #include "absl/container/flat_hash_set.h" | 
|  | #include "authorizer_enums.h" | 
|  | #include "redfish_privileges.h" | 
|  |  | 
|  | namespace milotic::authz::internal { | 
|  |  | 
|  | // NOTE: This class is NOT thread safe, only thread aware. | 
|  | // redfish_entity_trie ensures that there will be no data races as mutexes are | 
|  | // always held when accessing these methods | 
|  |  | 
|  | class RedfishSubtreePrivilegesTrieNode { | 
|  | public: | 
|  | // Have to create a default constructor for the root | 
|  | RedfishSubtreePrivilegesTrieNode() = default; | 
|  |  | 
|  | // For purposes of inserting a uri, we will need to return a modifiable | 
|  | // RedfishEntityTrieNode pointer. This method encapsulates this as it will | 
|  | // either get a modifiable pointer to a child that exists or create a child | 
|  | // that doesn't exist and return its pointer to be modified when inserting | 
|  | // uris into the Trie. | 
|  | RedfishSubtreePrivilegesTrieNode* GetOrDefaultChild(std::string_view path); | 
|  |  | 
|  | // For purposes of getting an entity type from the uri, we can have a separate | 
|  | // Get method that is marked const to prevent the Trie from being modified | 
|  | // when only querying it. | 
|  | RedfishSubtreePrivilegesTrieNode* GetChild(std::string_view path) const; | 
|  |  | 
|  | bool ContainsPrivilegeForSubtree(const ecclesia::Operation& operation, | 
|  | const RedfishPrivileges& privilege) const; | 
|  |  | 
|  | void AddPrivilegeForSubtree(const ecclesia::Operation& operation, | 
|  | RedfishPrivileges&& privilege); | 
|  |  | 
|  | // Returning vector here to avoid complications of copying hashset | 
|  | std::vector<RedfishPrivileges> GetPrivilegesForSubtree( | 
|  | const ecclesia::Operation& operation) const; | 
|  |  | 
|  | // Clear children and subtree_privileges | 
|  | void Clear(); | 
|  |  | 
|  | private: | 
|  | absl::flat_hash_map<std::string, | 
|  | std::unique_ptr<RedfishSubtreePrivilegesTrieNode>> | 
|  | children_; | 
|  | // This contains a map of operation to privileges that allow access to the | 
|  | // rest of the current node and all of its children | 
|  | absl::flat_hash_map<ecclesia::Operation, | 
|  | std::unique_ptr<absl::flat_hash_set<RedfishPrivileges>>> | 
|  | subtree_privileges_; | 
|  | }; | 
|  |  | 
|  | }  // namespace milotic::authz::internal | 
|  |  | 
|  | #endif  // THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_TRIE_NODE_H_ |