| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_ENTITY_TRIE_NODE_H_ | |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_ENTITY_TRIE_NODE_H_ | |
| #include <cstddef> | |
| #include <limits> | |
| #include <memory> | |
| #include <string> | |
| #include <string_view> | |
| #include "absl/container/flat_hash_map.h" | |
| #include "absl/strings/string_view.h" | |
| #include "authorizer_enums.h" | |
| namespace milotic::authz::internal { | |
| class RedfishEntityTrieNode { | |
| public: | |
| // Have to create a default constructor for the root | |
| RedfishEntityTrieNode() = 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. | |
| RedfishEntityTrieNode* 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. | |
| RedfishEntityTrieNode* GetChild(std::string_view path) const; | |
| ecclesia::ResourceEntity GetEntityTag() const; | |
| void SetEntityTag(ecclesia::ResourceEntity tag); | |
| std::size_t GetNodeIndexInPatternArray() const; | |
| void SetNodeIndexInPatternArray(std::size_t index); | |
| private: | |
| static bool IsWildcard(absl::string_view path); | |
| absl::flat_hash_map<std::string, std::unique_ptr<RedfishEntityTrieNode>> | |
| children_; | |
| ecclesia::ResourceEntity entity_tag_ = ecclesia::ResourceEntity::kUndefined; | |
| std::size_t node_index_in_pattern_array_ = | |
| std::numeric_limits<std::size_t>::max(); | |
| // Hold at most one child for collection. | |
| // Read more about resource collections on page 28 below | |
| // https://www.dmtf.org/sites/default/files/standards/documents/DSP2046_2020.3_1.pdf | |
| RedfishEntityTrieNode* collection_child_ = nullptr; | |
| }; | |
| } // namespace milotic::authz::internal | |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_ENTITY_TRIE_NODE_H_ |