| #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 "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); |
| bool IsCollection() const; |
| void SetCollection(bool collection); |
| |
| private: |
| absl::flat_hash_map<std::string, std::unique_ptr<RedfishEntityTrieNode>> |
| children_; |
| ecclesia::ResourceEntity entity_tag_; |
| std::size_t node_index_in_pattern_array_ = |
| std::numeric_limits<std::size_t>::max(); |
| // If this current node is a collection, it will be set true later. Default to |
| // false |
| // Read more about resource collections on page 28 below |
| // https://www.dmtf.org/sites/default/files/standards/documents/DSP2046_2020.3_1.pdf |
| bool collection_ = false; |
| }; |
| |
| } // namespace milotic::authz::internal |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_ENTITY_TRIE_NODE_H_ |