if (ret < 0)
return ret;
- policy.to_xml(dpp, os);
+ rgw::s3::write_policy_xml(policy, os);
return 0;
}
ACLGroupTypeEnum group;
std::string url_spec;
+ friend void to_xml(const ACLGrant& grant, std::ostream& out);
+
public:
ACLGrant() : group(ACL_GROUP_NONE) {}
virtual ~ACLGrant() {}
static string rgw_uri_all_users = RGW_URI_ALL_USERS;
static string rgw_uri_auth_users = RGW_URI_AUTH_USERS;
-void ACLPermission_S3::to_xml(ostream& out)
+void to_xml(ACLPermission perm, std::ostream& out)
{
+ const uint32_t flags = perm.get_permissions();
if ((flags & RGW_PERM_FULL_CONTROL) == RGW_PERM_FULL_CONTROL) {
out << "<Permission>FULL_CONTROL</Permission>";
} else {
return true;
}
-void ACLOwner_S3::to_xml(ostream& out) {
+void to_xml(const ACLOwner& o, std::ostream& out)
+{
string s;
- id.to_str(s);
+ o.id.to_str(s);
if (s.empty())
return;
out << "<Owner>" << "<ID>" << s << "</ID>";
- if (!display_name.empty())
- out << "<DisplayName>" << display_name << "</DisplayName>";
+ if (!o.display_name.empty())
+ out << "<DisplayName>" << o.display_name << "</DisplayName>";
out << "</Owner>";
}
return true;
}
-void ACLGrant_S3::to_xml(const DoutPrefixProvider* dpp, ostream& out) {
- ACLPermission_S3& perm = static_cast<ACLPermission_S3 &>(permission);
+void to_xml(const ACLGrant& grant, ostream& out)
+{
+ const ACLPermission perm = grant.get_permission();
/* only show s3 compatible permissions */
if (!(perm.get_permissions() & RGW_PERM_ALL_S3))
string uri;
out << "<Grant>" <<
- "<Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"" << ACLGranteeType_S3::to_string(type) << "\">";
- switch (type.get_type()) {
+ "<Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"" << ACLGranteeType_S3::to_string(grant.type) << "\">";
+ switch (grant.type.get_type()) {
case ACL_TYPE_CANON_USER:
- out << "<ID>" << id << "</ID>";
- if (name.size()) {
- out << "<DisplayName>" << name << "</DisplayName>";
+ out << "<ID>" << grant.id << "</ID>";
+ if (grant.name.size()) {
+ out << "<DisplayName>" << grant.name << "</DisplayName>";
}
break;
case ACL_TYPE_EMAIL_USER:
- out << "<EmailAddress>" << email << "</EmailAddress>";
+ out << "<EmailAddress>" << grant.email << "</EmailAddress>";
break;
case ACL_TYPE_GROUP:
- if (!group_to_uri(group, uri)) {
- ldpp_dout(dpp, 0) << "ERROR: group_to_uri failed with group=" << (int)group << dendl;
+ if (!ACLGrant_S3::group_to_uri(grant.group, uri)) {
break;
}
out << "<URI>" << uri << "</URI>";
break;
}
out << "</Grantee>";
- perm.to_xml(out);
+ to_xml(perm, out);
out << "</Grant>";
}
return true;
}
-void RGWAccessControlList_S3::to_xml(const DoutPrefixProvider* dpp, ostream& out) {
- multimap<string, ACLGrant>::iterator iter;
+void to_xml(const RGWAccessControlList& acl, std::ostream& out)
+{
out << "<AccessControlList>";
- for (iter = grant_map.begin(); iter != grant_map.end(); ++iter) {
- ACLGrant_S3& grant = static_cast<ACLGrant_S3 &>(iter->second);
- grant.to_xml(dpp, out);
+ for (const auto& p : acl.get_grant_map()) {
+ to_xml(p.second, out);
}
out << "</AccessControlList>";
}
return true;
}
-void RGWAccessControlPolicy_S3::to_xml(const DoutPrefixProvider* dpp, ostream& out) {
+void to_xml(const RGWAccessControlPolicy& p, std::ostream& out)
+{
out << "<AccessControlPolicy xmlns=\"" << XMLNS_AWS_S3 << "\">";
- ACLOwner_S3& _owner = static_cast<ACLOwner_S3 &>(owner);
- RGWAccessControlList_S3& _acl = static_cast<RGWAccessControlList_S3 &>(acl);
- _owner.to_xml(out);
- _acl.to_xml(dpp, out);
+ to_xml(p.get_owner(), out);
+ to_xml(p.get_acl(), out);
out << "</AccessControlPolicy>";
}
namespace rgw::s3 {
+void write_policy_xml(const RGWAccessControlPolicy& policy,
+ std::ostream& out)
+{
+ to_xml(policy, out);
+}
+
int create_canned_acl(const ACLOwner& owner,
const ACLOwner& bucket_owner,
const std::string& canned_acl,
virtual ~ACLPermission_S3() override {}
bool xml_end(const char *el) override;
- void to_xml(std::ostream& out);
};
class ACLGrantee_S3 : public XMLObj
ACLGrant_S3() {}
virtual ~ACLGrant_S3() override {}
- void to_xml(const DoutPrefixProvider* dpp, std::ostream& out);
bool xml_end(const char *el) override;
bool xml_start(const char *el, const char **attr);
{
public:
bool xml_end(const char *el) override;
- void to_xml(const DoutPrefixProvider* dpp, std::ostream& out);
};
class ACLOwner_S3 : public ACLOwner, public XMLObj
virtual ~ACLOwner_S3() override {}
bool xml_end(const char *el) override;
- void to_xml(std::ostream& out);
};
class RGWEnv;
public:
bool xml_end(const char *el) override;
- void to_xml(const DoutPrefixProvider* dpp, std::ostream& out);
int rebuild(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver, ACLOwner *owner,
RGWAccessControlPolicy& dest, std::string &err_msg);
};
namespace rgw::s3 {
+/// Write an AccessControlPolicy xml document for the given policy.
+void write_policy_xml(const RGWAccessControlPolicy& policy,
+ std::ostream& out);
+
/// Construct a policy from a s3 canned acl string.
int create_canned_acl(const ACLOwner& owner,
const ACLOwner& bucket_owner,
}
if (cct->_conf->subsys.should_gather<ceph_subsys_rgw, 15>()) {
ldpp_dout(dpp, 15) << __func__ << " Read AccessControlPolicy";
- RGWAccessControlPolicy_S3 *s3policy = static_cast<RGWAccessControlPolicy_S3 *>(policy);
- s3policy->to_xml(dpp, *_dout);
+ rgw::s3::write_policy_xml(*policy, *_dout);
*_dout << dendl;
}
return 0;
return -EIO;
}
if (cct->_conf->subsys.should_gather<ceph_subsys_rgw, 15>()) {
- RGWAccessControlPolicy_S3 *s3policy = static_cast<RGWAccessControlPolicy_S3 *>(policy);
ldpp_dout(dpp, 15) << __func__ << " Read AccessControlPolicy";
- s3policy->to_xml(dpp, *_dout);
+ rgw::s3::write_policy_xml(*policy, *_dout);
*_dout << dendl;
}
return 0;
void RGWGetACLs::execute(optional_yield y)
{
stringstream ss;
- RGWAccessControlPolicy* const acl = \
- (!rgw::sal::Object::empty(s->object.get()) ? s->object_acl.get() : s->bucket_acl.get());
- RGWAccessControlPolicy_S3* const s3policy = \
- static_cast<RGWAccessControlPolicy_S3*>(acl);
- s3policy->to_xml(this, ss);
+ if (rgw::sal::Object::empty(s->object.get())) {
+ rgw::s3::write_policy_xml(*s->bucket_acl, ss);
+ } else {
+ rgw::s3::write_policy_xml(*s->object_acl, ss);
+ }
acls = ss.str();
}
if (s->cct->_conf->subsys.should_gather<ceph_subsys_rgw, 15>()) {
ldpp_dout(this, 15) << "Old AccessControlPolicy";
- policy->to_xml(this, *_dout);
+ rgw::s3::write_policy_xml(*policy, *_dout);
*_dout << dendl;
}
if (s->cct->_conf->subsys.should_gather<ceph_subsys_rgw, 15>()) {
ldpp_dout(this, 15) << "New AccessControlPolicy:";
- new_policy.to_xml(this, *_dout);
+ rgw::s3::write_policy_xml(new_policy, *_dout);
*_dout << dendl;
}
if (r < 0)
return r;
- s3policy.to_xml(this, ss);
+ rgw::s3::write_policy_xml(s3policy, ss);
return 0;
}