| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_PRIVILEGES_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_PRIVILEGES_H_ |
| |
| #include <initializer_list> |
| #include <string> |
| #include <string_view> |
| #include <unordered_set> |
| |
| #include "nlohmann/json.hpp" |
| |
| namespace milotic::authz { |
| /* |
| Class to represent redfish privileges. |
| |
| These directly represent user privileges and help represent entity privileges. |
| |
| Each incoming request requires a comparison between privileges held by the user |
| issuing a request and the target entity's privileges |
| */ |
| class RedfishPrivileges { |
| public: |
| // Creating default and initializer list constructor for ease of creation |
| RedfishPrivileges() = default; |
| RedfishPrivileges(std::initializer_list<std::string> privileges) |
| : privileges_(privileges.begin(), privileges.end()) {} |
| RedfishPrivileges(const std::unordered_set<std::string>& privileges) |
| : privileges_(privileges) {} |
| |
| bool IsSupersetOf(const RedfishPrivileges& other) const; |
| std::unordered_set<std::string> GetPrivileges() const; |
| void InsertPrivilege(std::string_view privilege); |
| nlohmann::json::object_t ToJson() const; |
| std::string GetDebugString() const; |
| bool operator==(const RedfishPrivileges& other) const; |
| |
| // go/absl-hash |
| template <typename H> |
| friend H AbslHashValue(H h, const RedfishPrivileges& p) { |
| return H::combine(std::move(h), p.privileges_); |
| } |
| |
| private: |
| std::unordered_set<std::string> privileges_; |
| }; |
| } // namespace milotic::authz |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_AUTHZ_REDFISH_PRIVILEGES_H_ |