From: Yehuda Sadeh Date: Mon, 25 Nov 2013 21:41:50 +0000 (-0800) Subject: rgw: can set temp url key on user X-Git-Tag: v0.78~333^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2626101f17e16ea370b58cf760dbec1a756fff73;p=ceph.git rgw: can set temp url key on user Either through new through new rest api call, or via radosgw-admin Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index cb6c3022396..17589730ef9 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -743,6 +743,8 @@ int main(int argc, char **argv) int gen_access_key = 0; int gen_secret_key = 0; bool set_perm = false; + bool set_temp_url_key = false; + string temp_url_key; string bucket_id; Formatter *formatter = NULL; int purge_data = false; @@ -886,6 +888,9 @@ int main(int argc, char **argv) access = val; perm_mask = rgw_str_to_perm(access.c_str()); set_perm = true; + } else if (ceph_argparse_witharg(args, i, &val, "--temp-url-key", (char*)NULL)) { + temp_url_key = val; + set_temp_url_key = true; } else if (ceph_argparse_witharg(args, i, &val, "--bucket-id", (char*)NULL)) { bucket_id = val; if (bucket_id.empty()) { @@ -1263,6 +1268,9 @@ int main(int argc, char **argv) if (set_perm) user_op.set_perm(perm_mask); + if (set_temp_url_key) + user_op.set_temp_url_key(temp_url_key); + if (!op_mask_str.empty()) { uint32_t op_mask; int ret = rgw_parse_op_type_list(op_mask_str, &op_mask); diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index aa7c671b2c1..7039f39b743 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -434,11 +434,12 @@ struct RGWUserInfo string default_placement; list placement_tags; RGWQuotaInfo bucket_quota; + string temp_url_key; RGWUserInfo() : auid(0), suspended(0), max_buckets(RGW_DEFAULT_MAX_BUCKETS), op_mask(RGW_OP_TYPE_ALL), system(0) {} void encode(bufferlist& bl) const { - ENCODE_START(14, 9, bl); + ENCODE_START(15, 9, bl); ::encode(auid, bl); string access_key; string secret_key; @@ -474,6 +475,7 @@ struct RGWUserInfo ::encode(default_placement, bl); ::encode(placement_tags, bl); ::encode(bucket_quota, bl); + ::encode(temp_url_key, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { @@ -533,6 +535,9 @@ struct RGWUserInfo if (struct_v >= 14) { ::decode(bucket_quota, bl); } + if (struct_v >= 15) { + ::decode(temp_url_key, bl); + } DECODE_FINISH(bl); } void dump(Formatter *f) const; diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 4d6b25374b9..e55e5fed9ce 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -397,6 +397,7 @@ void RGWUserInfo::dump(Formatter *f) const encode_json("default_placement", default_placement, f); encode_json("placement_tags", placement_tags, f); encode_json("bucket_quota", bucket_quota, f); + encode_json("temp_url_key", temp_url_key, f); } @@ -448,6 +449,7 @@ void RGWUserInfo::decode_json(JSONObj *obj) JSONDecoder::decode_json("default_placement", default_placement, obj); JSONDecoder::decode_json("placement_tags", placement_tags, obj); JSONDecoder::decode_json("bucket_quota", bucket_quota, obj); + JSONDecoder::decode_json("temp_url_key", temp_url_key, obj); } void RGWQuotaInfo::dump(Formatter *f) const diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index dbc30a9c5f4..76a428f8bf4 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1706,6 +1706,19 @@ void RGWPutMetadata::execute() } } +int RGWSetTempUrl::verify_permission() +{ + if (s->perm_mask != RGW_PERM_FULL_CONTROL) + return -EACCES; + + return 0; +} + +void RGWSetTempUrl::execute() +{ +} + + int RGWDeleteObj::verify_permission() { if (!verify_bucket_permission(s, RGW_PERM_WRITE)) diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index ab6f925dbc9..3fa3497ebb7 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -412,6 +412,21 @@ public: virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; +class RGWSetTempUrl : public RGWOp { +protected: + int ret; + string temp_url_key; +public: + RGWSetTempUrl() : ret(0) {} + + int verify_permission(); + void execute(); + + virtual int get_params() = 0; + virtual void send_response() = 0; + virtual const string name() { return "set_temp_url"; } +}; + class RGWDeleteObj : public RGWOp { protected: int ret; diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index 15ac863aa52..1b0d4999f18 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -128,6 +128,12 @@ public: ~RGWPutMetadata_ObjStore() {} }; +class RGWSetTempUrl_ObjStore : public RGWSetTempUrl { +public: + RGWSetTempUrl_ObjStore() {} + ~RGWSetTempUrl_ObjStore() {} +}; + class RGWDeleteObj_ObjStore : public RGWDeleteObj { public: RGWDeleteObj_ObjStore() {} diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index 95d54aef3f9..c958aa3a9e4 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -425,6 +425,29 @@ void RGWPutMetadata_ObjStore_SWIFT::send_response() rgw_flush_formatter_and_reset(s, s->formatter); } +int RGWSetTempUrl_ObjStore_SWIFT::get_params() +{ + const char *temp_url = s->info.env->get("HTTP_X_ACCOUNT_META_TEMP_URL"); + if (temp_url) + return -EINVAL; + + temp_url_key = temp_url; + + return 0; +} + +void RGWSetTempUrl_ObjStore_SWIFT::send_response() +{ + int r = ret; + if (!r) + r = STATUS_NO_CONTENT; + + set_req_state_err(s, r); + dump_errno(s); + end_header(s, this); + rgw_flush_formatter_and_reset(s, s->formatter); +} + void RGWDeleteObj_ObjStore_SWIFT::send_response() { int r = ret; @@ -600,6 +623,15 @@ RGWOp *RGWHandler_ObjStore_Service_SWIFT::op_head() return new RGWStatAccount_ObjStore_SWIFT; } +RGWOp *RGWHandler_ObjStore_Service_SWIFT::op_post() +{ + const char *temp_url = s->info.env->get("HTTP_X_ACCOUNT_META_TEMP_URL"); + if (temp_url) { + return new RGWSetTempUrl_ObjStore_SWIFT; + } + return NULL; +} + RGWOp *RGWHandler_ObjStore_Bucket_SWIFT::get_obj_op(bool get_data) { if (is_acl_op()) { diff --git a/src/rgw/rgw_rest_swift.h b/src/rgw/rgw_rest_swift.h index 1c23ab29204..27a31aaa308 100644 --- a/src/rgw/rgw_rest_swift.h +++ b/src/rgw/rgw_rest_swift.h @@ -91,6 +91,15 @@ public: void send_response(); }; +class RGWSetTempUrl_ObjStore_SWIFT : public RGWSetTempUrl_ObjStore { +public: + RGWSetTempUrl_ObjStore_SWIFT() {} + ~RGWSetTempUrl_ObjStore_SWIFT() {} + + int get_params(); + void send_response(); +}; + class RGWDeleteObj_ObjStore_SWIFT : public RGWDeleteObj_ObjStore { public: RGWDeleteObj_ObjStore_SWIFT() {} @@ -160,6 +169,7 @@ class RGWHandler_ObjStore_Service_SWIFT : public RGWHandler_ObjStore_SWIFT { protected: RGWOp *op_get(); RGWOp *op_head(); + RGWOp *op_post(); public: RGWHandler_ObjStore_Service_SWIFT() {} virtual ~RGWHandler_ObjStore_Service_SWIFT() {} diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index e4462ec11e0..2e0777cbd00 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -1685,6 +1685,9 @@ int RGWUser::execute_add(RGWUserAdminOpState& op_state, std::string *err_msg) if (op_state.has_bucket_quota()) user_info.bucket_quota = op_state.get_bucket_quota(); + if (op_state.temp_url_key_specified) + user_info.temp_url_key = op_state.temp_url_key; + // update the request op_state.set_user_info(user_info); op_state.set_populated(); @@ -1884,6 +1887,9 @@ int RGWUser::execute_modify(RGWUserAdminOpState& op_state, std::string *err_msg) if (op_state.system_specified) user_info.system = op_state.system; + if (op_state.temp_url_key_specified) + user_info.temp_url_key = op_state.temp_url_key; + if (op_state.op_mask_specified) user_info.op_mask = op_state.get_op_mask(); diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index 2749e6c2d51..25b8f287025 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -131,6 +131,7 @@ struct RGWUserAdminOpState { std::string caps; RGWObjVersionTracker objv; uint32_t op_mask; + string temp_url_key; // subuser attributes std::string subuser; @@ -164,6 +165,7 @@ struct RGWUserAdminOpState { bool suspension_op; bool system_specified; bool key_op; + bool temp_url_key_specified; // req parameters bool populated; @@ -245,6 +247,10 @@ struct RGWUserAdminOpState { op_mask = mask; op_mask_specified = true; } + void set_temp_url_key(const string& key) { + temp_url_key = key; + temp_url_key_specified = true; + } void set_key_type(int32_t type) { key_type = type; type_specified = true; @@ -337,6 +343,7 @@ struct RGWUserAdminOpState { std::string get_caps() { return caps; }; std::string get_user_email() { return user_email; }; std::string get_display_name() { return display_name; }; + std::string get_temp_url_key() { return temp_url_key; }; RGWUserInfo& get_user_info() { return info; }; @@ -417,6 +424,7 @@ struct RGWUserAdminOpState { subuser_params_checked = false; user_params_checked = false; bucket_quota_specified = false; + temp_url_key_specified = false; } };