mirror of
https://github.com/ceph/ceph
synced 2025-03-11 02:39:05 +00:00
rgw: support json format for admin policy API
Fixes: #14090, #14091 - before this patch: $ curl -s -X GET http://radosrgw:9090/admin/bucket?format=json&policy&bucket=m8x | xmllint --format - got XML response with error format - after this patch: got correct response with json format Signed-off-by: Dunrong Huang <riegamaths@gmail.com>
This commit is contained in:
parent
c812bbae47
commit
a1333f547e
@ -923,7 +923,19 @@ int RGWBucket::policy_bl_to_stream(bufferlist& bl, ostream& o)
|
||||
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();
|
||||
@ -947,7 +959,7 @@ int RGWBucket::get_policy(RGWBucketAdminOpState& op_state, ostream& o)
|
||||
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);
|
||||
@ -955,12 +967,12 @@ int RGWBucket::get_policy(RGWBucketAdminOpState& op_state, ostream& o)
|
||||
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;
|
||||
|
||||
@ -968,7 +980,7 @@ int RGWBucketAdminOp::get_policy(RGWRados *store, RGWBucketAdminOpState& op_stat
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = bucket.get_policy(op_state, os);
|
||||
ret = bucket.get_policy(op_state, policy);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@ -981,9 +993,9 @@ int RGWBucketAdminOp::get_policy(RGWRados *store, RGWBucketAdminOpState& op_stat
|
||||
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;
|
||||
|
||||
@ -991,7 +1003,9 @@ int RGWBucketAdminOp::get_policy(RGWRados *store, RGWBucketAdminOpState& op_stat
|
||||
|
||||
flusher.start(0);
|
||||
|
||||
formatter->dump_string("policy", policy_stream.str());
|
||||
formatter->open_object_section("policy");
|
||||
policy.dump(formatter);
|
||||
formatter->close_section();
|
||||
|
||||
flusher.flush();
|
||||
|
||||
|
@ -280,7 +280,7 @@ public:
|
||||
|
||||
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; }
|
||||
};
|
||||
@ -291,7 +291,7 @@ public:
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user