| #include "redfish_privileges.h" |
| |
| #include <string> |
| #include <string_view> |
| #include <unordered_set> |
| |
| #include "absl/strings/str_cat.h" |
| #include "absl/strings/str_join.h" |
| #include "nlohmann/json.hpp" |
| |
| namespace milotic::authz { |
| |
| std::unordered_set<std::string> RedfishPrivileges::GetPrivileges() const { |
| return privileges_; |
| } |
| |
| bool RedfishPrivileges::IsSupersetOf(const RedfishPrivileges& other) const { |
| if (other.GetPrivileges().size() > privileges_.size()) { |
| return false; |
| } |
| // Iterate through the smaller set |
| for (const std::string& privilege : other.GetPrivileges()) { |
| if (privileges_.find(privilege) == privileges_.end()) { |
| return false; |
| } |
| } |
| return true; |
| } |
| |
| void RedfishPrivileges::InsertPrivilege(std::string_view privilege) { |
| privileges_.insert(std::string(privilege)); |
| } |
| |
| nlohmann::json::object_t RedfishPrivileges::ToJson() const { |
| nlohmann::json::object_t redfish_privileges_json; |
| redfish_privileges_json["Privilege"] = nlohmann::json::array(); |
| |
| for (const std::string& privilege : privileges_) { |
| redfish_privileges_json["Privilege"].push_back(privilege); |
| } |
| |
| return redfish_privileges_json; |
| } |
| |
| std::string RedfishPrivileges::GetDebugString() const { |
| return absl::StrCat("|PeerPrivileges|={", absl::StrJoin(privileges_, ", "), |
| "}"); |
| } |
| |
| bool RedfishPrivileges::operator==(const RedfishPrivileges& other) const { |
| return privileges_ == other.privileges_; |
| } |
| |
| } // namespace milotic::authz |