From: Casey Bodley Date: Thu, 3 Sep 2020 15:03:02 +0000 (-0400) Subject: rgw: add comparison operators for ACL types X-Git-Tag: v16.1.0~1093^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a8975403a693a8f04172e3017271ae64f719a370;p=ceph.git rgw: add comparison operators for ACL types Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_acl.cc b/src/rgw/rgw_acl.cc index e1d1ecb442bb..caee6d329d97 100644 --- a/src/rgw/rgw_acl.cc +++ b/src/rgw/rgw_acl.cc @@ -15,6 +15,64 @@ #define dout_subsys ceph_subsys_rgw +bool operator==(const ACLPermission& lhs, const ACLPermission& rhs) { + return lhs.flags == rhs.flags; +} +bool operator!=(const ACLPermission& lhs, const ACLPermission& rhs) { + return !(lhs == rhs); +} + +bool operator==(const ACLGranteeType& lhs, const ACLGranteeType& rhs) { + return lhs.type == rhs.type; +} +bool operator!=(const ACLGranteeType& lhs, const ACLGranteeType& rhs) { + return lhs.type != rhs.type; +} + +bool operator==(const ACLGrant& lhs, const ACLGrant& rhs) { + return lhs.type == rhs.type && lhs.id == rhs.id + && lhs.email == rhs.email && lhs.permission == rhs.permission + && lhs.name == rhs.name && lhs.group == rhs.group + && lhs.url_spec == rhs.url_spec; +} +bool operator!=(const ACLGrant& lhs, const ACLGrant& rhs) { + return !(lhs == rhs); +} + +bool operator==(const ACLReferer& lhs, const ACLReferer& rhs) { + return lhs.url_spec == rhs.url_spec && lhs.perm == rhs.perm; +} +bool operator!=(const ACLReferer& lhs, const ACLReferer& rhs) { + return !(lhs == rhs); +} + +bool operator==(const RGWAccessControlList& lhs, + const RGWAccessControlList& rhs) { + return lhs.acl_user_map == rhs.acl_user_map + && lhs.acl_group_map == rhs.acl_group_map + && lhs.referer_list == rhs.referer_list + && lhs.grant_map == rhs.grant_map; +} +bool operator!=(const RGWAccessControlList& lhs, + const RGWAccessControlList& rhs) { + return !(lhs == rhs); +} + +bool operator==(const ACLOwner& lhs, const ACLOwner& rhs) { + return lhs.id == rhs.id && lhs.display_name == rhs.display_name; +} +bool operator!=(const ACLOwner& lhs, const ACLOwner& rhs) { + return !(lhs == rhs); +} + +bool operator==(const RGWAccessControlPolicy& lhs, + const RGWAccessControlPolicy& rhs) { + return lhs.acl == rhs.acl && lhs.owner == rhs.owner; +} +bool operator!=(const RGWAccessControlPolicy& lhs, + const RGWAccessControlPolicy& rhs) { + return !(lhs == rhs); +} void RGWAccessControlList::_add_grant(ACLGrant *grant) { diff --git a/src/rgw/rgw_acl.h b/src/rgw/rgw_acl.h index 44a2c1aafccc..c1a68845d8e8 100644 --- a/src/rgw/rgw_acl.h +++ b/src/rgw/rgw_acl.h @@ -68,6 +68,9 @@ public: } void dump(Formatter *f) const; static void generate_test_instances(list& o); + + friend bool operator==(const ACLPermission& lhs, const ACLPermission& rhs); + friend bool operator!=(const ACLPermission& lhs, const ACLPermission& rhs); }; WRITE_CLASS_ENCODER(ACLPermission) @@ -94,6 +97,9 @@ public: } void dump(Formatter *f) const; static void generate_test_instances(list& o); + + friend bool operator==(const ACLGranteeType& lhs, const ACLGranteeType& rhs); + friend bool operator!=(const ACLGranteeType& lhs, const ACLGranteeType& rhs); }; WRITE_CLASS_ENCODER(ACLGranteeType) @@ -204,6 +210,9 @@ public: url_spec = _url_spec; permission.set_permissions(perm); } + + friend bool operator==(const ACLGrant& lhs, const ACLGrant& rhs); + friend bool operator!=(const ACLGrant& lhs, const ACLGrant& rhs); }; WRITE_CLASS_ENCODER(ACLGrant) @@ -255,6 +264,9 @@ struct ACLReferer { } void dump(Formatter *f) const; + friend bool operator==(const ACLReferer& lhs, const ACLReferer& rhs); + friend bool operator!=(const ACLReferer& lhs, const ACLReferer& rhs); + private: boost::optional get_http_host(const std::string_view url) const { size_t pos = url.find("://"); @@ -359,6 +371,9 @@ public: grant.set_canon(id, name, RGW_PERM_FULL_CONTROL); add_grant(&grant); } + + friend bool operator==(const RGWAccessControlList& lhs, const RGWAccessControlList& rhs); + friend bool operator!=(const RGWAccessControlList& lhs, const RGWAccessControlList& rhs); }; WRITE_CLASS_ENCODER(RGWAccessControlList) @@ -396,6 +411,9 @@ public: rgw_user& get_id() { return id; } const rgw_user& get_id() const { return id; } string& get_display_name() { return display_name; } + + friend bool operator==(const ACLOwner& lhs, const ACLOwner& rhs); + friend bool operator!=(const ACLOwner& lhs, const ACLOwner& rhs); }; WRITE_CLASS_ENCODER(ACLOwner) @@ -467,6 +485,9 @@ public: virtual bool compare_group_name(string& id, ACLGroupTypeEnum group) { return false; } bool is_public() const; + + friend bool operator==(const RGWAccessControlPolicy& lhs, const RGWAccessControlPolicy& rhs); + friend bool operator!=(const RGWAccessControlPolicy& lhs, const RGWAccessControlPolicy& rhs); }; WRITE_CLASS_ENCODER(RGWAccessControlPolicy)