Merge pull request #9263 from rzarzynski/wip-rgw-15976

rgw: fix CORS/ACLs metadata processing in Swift API
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
This commit is contained in:
Orit Wasserman 2016-05-26 12:55:41 +02:00
commit a34704a7fa

View File

@ -1849,6 +1849,14 @@ static void prepare_add_del_attrs(const map<string, bufferlist>& orig_attrs,
}
}
/* Fuse resource metadata basing on original attributes in @orig_attrs, set
* of _custom_ attribute names to remove in @rmattr_names and attributes in
* @out_attrs. Place results in @out_attrs.
*
* NOTE: it's supposed that all special attrs already present in @out_attrs
* will be preserved without any change. Special attributes are those which
* names start with RGW_ATTR_META_PREFIX. They're complement to custom ones
* used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */
static void prepare_add_del_attrs(const map<string, bufferlist>& orig_attrs,
const set<string>& rmattr_names,
map<string, bufferlist>& out_attrs)
@ -1982,12 +1990,9 @@ void RGWCreateBucket::execute()
}
}
if (need_metadata_upload()) {
rgw_get_request_metadata(s->cct, s->info, attrs, false);
prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs);
populate_with_generic_attrs(s, attrs);
}
/* Encode special metadata first as we're using std::map::emplace under
* the hood. This method will add the new items only if the map doesn't
* contain such keys yet. */
policy.encode(aclbl);
emplace_attr(RGW_ATTR_ACL, std::move(aclbl));
@ -1995,6 +2000,15 @@ void RGWCreateBucket::execute()
cors_config.encode(corsbl);
emplace_attr(RGW_ATTR_CORS, std::move(corsbl));
}
if (need_metadata_upload()) {
/* It's supposed that following functions WILL NOT change any special
* attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
rgw_get_request_metadata(s->cct, s->info, attrs, false);
prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs);
populate_with_generic_attrs(s, attrs);
}
s->bucket.tenant = s->bucket_tenant; /* ignored if bucket exists */
s->bucket.name = s->bucket_name;
op_ret = store->create_bucket(*(s->user), s->bucket, zonegroup_id,
@ -2847,8 +2861,6 @@ void RGWPutMetadataBucket::pre_exec()
void RGWPutMetadataBucket::execute()
{
map<string, buffer::list> orig_attrs;
op_ret = get_params();
if (op_ret < 0) {
return;
@ -2862,10 +2874,9 @@ void RGWPutMetadataBucket::execute()
return;
}
orig_attrs = s->bucket_attrs; /* XXX map copy */
prepare_add_del_attrs(orig_attrs, rmattr_names, attrs);
populate_with_generic_attrs(s, attrs);
/* Encode special metadata first as we're using std::map::emplace under
* the hood. This method will add the new items only if the map doesn't
* contain such keys yet. */
if (has_policy) {
buffer::list bl;
policy.encode(bl);
@ -2878,6 +2889,11 @@ void RGWPutMetadataBucket::execute()
emplace_attr(RGW_ATTR_CORS, std::move(bl));
}
/* It's supposed that following functions WILL NOT change any special
* attributes (like RGW_ATTR_ACL) if they are already present in attrs. */
prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs);
populate_with_generic_attrs(s, attrs);
s->bucket_info.swift_ver_location = swift_ver_location;
s->bucket_info.swift_versioning = (!swift_ver_location.empty());