return 0;
}
-int RGWBucket::get_policy(RGWBucketAdminOpState& op_state, ostream& o)
+static int policy_decode(RGWRados *store, bufferlist& bl, RGWAccessControlPolicy& policy)
+{
+ bufferlist::iterator iter = bl.begin();
+ try {
+ policy.decode(iter);
+ } catch (buffer::error& err) {
+ ldout(store->ctx(), 0) << "ERROR: caught buffer::error, could not decode policy" << dendl;
+ return -EIO;
+ }
+ return 0;
+}
+
+int RGWBucket::get_policy(RGWBucketAdminOpState& op_state, RGWAccessControlPolicy& policy)
{
std::string object_name = op_state.get_object_name();
rgw_bucket bucket = op_state.get_bucket();
if (ret < 0)
return ret;
- return policy_bl_to_stream(bl, o);
+ return policy_decode(store, bl, policy);
}
map<string, bufferlist>::iterator aiter = attrs.find(RGW_ATTR_ACL);
return -ENOENT;
}
- return policy_bl_to_stream(aiter->second, o);
+ return policy_decode(store, aiter->second, policy);
}
int RGWBucketAdminOp::get_policy(RGWRados *store, RGWBucketAdminOpState& op_state,
- ostream& os)
+ RGWAccessControlPolicy& policy)
{
RGWBucket bucket;
if (ret < 0)
return ret;
- ret = bucket.get_policy(op_state, os);
+ ret = bucket.get_policy(op_state, policy);
if (ret < 0)
return ret;
int RGWBucketAdminOp::get_policy(RGWRados *store, RGWBucketAdminOpState& op_state,
RGWFormatterFlusher& flusher)
{
- std::ostringstream policy_stream;
+ RGWAccessControlPolicy policy(store->ctx());
- int ret = get_policy(store, op_state, policy_stream);
+ int ret = get_policy(store, op_state, policy);
if (ret < 0)
return ret;
flusher.start(0);
- formatter->dump_string("policy", policy_stream.str());
+ formatter->open_object_section("policy");
+ policy.dump(formatter);
+ formatter->close_section();
flusher.flush();
int remove_object(RGWBucketAdminOpState& op_state, std::string *err_msg = NULL);
int policy_bl_to_stream(bufferlist& bl, ostream& o);
- int get_policy(RGWBucketAdminOpState& op_state, ostream& o);
+ int get_policy(RGWBucketAdminOpState& op_state, RGWAccessControlPolicy& policy);
void clear_failure() { failure = false; }
};
static int get_policy(RGWRados *store, RGWBucketAdminOpState& op_state,
RGWFormatterFlusher& flusher);
static int get_policy(RGWRados *store, RGWBucketAdminOpState& op_state,
- ostream& os);
+ RGWAccessControlPolicy& policy);
static int unlink(RGWRados *store, RGWBucketAdminOpState& op_state);