| #include "redfish_entity_trie_node.h" |
| |
| #include <cstddef> |
| #include <memory> |
| #include <string> |
| #include <string_view> |
| #include <utility> |
| |
| #include "authorizer_enums.h" |
| |
| namespace milotic::authz::internal { |
| |
| // Note in both Get or GetOrDefault, we must check if the current node is a |
| // collection as any resource collection will only ever have one element inside |
| // its children map because it is supposed to handle all wildcards to the next |
| // level. Since it is not necessarily possible to obtain the generic wildcarded |
| // path, we can just directly return the only element in the children map. |
| |
| RedfishEntityTrieNode* RedfishEntityTrieNode::GetOrDefaultChild( |
| std::string_view path) { |
| if (IsCollection()) { |
| // If it is a collection node, then there is only 1 child entry which is the |
| // wildcard |
| return children_.begin()->second.get(); |
| } |
| |
| auto it = children_.find(path); |
| if (it == children_.end()) { |
| auto [inserted_it, _] = children_.insert( |
| {std::string(path), std::make_unique<RedfishEntityTrieNode>()}); |
| return inserted_it->second.get(); |
| } |
| |
| return it->second.get(); |
| } |
| |
| RedfishEntityTrieNode* RedfishEntityTrieNode::GetChild( |
| std::string_view path) const { |
| if (IsCollection()) { |
| // If it is a collection node, then there is only 1 child entry which is the |
| // wildcard |
| return children_.begin()->second.get(); |
| } |
| |
| auto it = children_.find(path); |
| if (it == children_.end()) { |
| return nullptr; |
| } |
| |
| return it->second.get(); |
| } |
| |
| ecclesia::ResourceEntity RedfishEntityTrieNode::GetEntityTag() const { |
| return entity_tag_; |
| } |
| void RedfishEntityTrieNode::SetEntityTag(ecclesia::ResourceEntity tag) { |
| entity_tag_ = tag; |
| } |
| void RedfishEntityTrieNode::SetNodeIndexInPatternArray(std::size_t index) { |
| node_index_in_pattern_array_ = index; |
| } |
| std::size_t RedfishEntityTrieNode::GetNodeIndexInPatternArray() const { |
| return node_index_in_pattern_array_; |
| } |
| bool RedfishEntityTrieNode::IsCollection() const { return collection_; } |
| void RedfishEntityTrieNode::SetCollection(bool collection) { |
| collection_ = collection; |
| } |
| |
| } // namespace milotic::authz::internal |