@@ -3451,6 +3451,106 @@ int RGWPostObj_ObjStore_S3::get_encrypt_filter(
34513451 return res;
34523452}
34533453
3454+ struct RestoreObjectRequest {
3455+ std::optional<uint64_t > days;
3456+
3457+ void decode_xml (XMLObj *obj) {
3458+ RGWXMLDecoder::decode_xml (" Days" , days, obj);
3459+ }
3460+
3461+ void dump_xml (Formatter *f) const {
3462+ encode_xml (" Days" , days, f);
3463+ }
3464+ };
3465+
3466+ int RGWRestoreObj_ObjStore_S3::get_params (optional_yield y)
3467+ {
3468+ std::string expected_bucket_owner;
3469+
3470+ if (s->info .env ->get (" x-amz-expected-bucket-owner" ) != nullptr ) {
3471+ expected_bucket_owner = s->info .env ->get (" x-amz-expected-bucket-owner" );
3472+ }
3473+
3474+ const auto max_size = s->cct ->_conf ->rgw_max_put_param_size ;
3475+
3476+ RGWXMLDecoder::XMLParser parser;
3477+ int r = 0 ;
3478+ bufferlist data;
3479+ std::tie (r, data) = read_all_input (s, max_size, false );
3480+
3481+ if (r < 0 ) {
3482+ return r;
3483+ }
3484+
3485+ if (!parser.init ()) {
3486+ return -EINVAL;
3487+ }
3488+
3489+ if (!parser.parse (data.c_str (), data.length (), 1 )) {
3490+ return -ERR_MALFORMED_XML;
3491+ }
3492+
3493+ RestoreObjectRequest request;
3494+
3495+ try {
3496+ RGWXMLDecoder::decode_xml (" RestoreRequest" , request, &parser);
3497+ }
3498+ catch (RGWXMLDecoder::err &err) {
3499+ ldpp_dout (this , 5 ) << " Malformed restore request: " << err << dendl;
3500+ return -EINVAL;
3501+ }
3502+
3503+ if (request.days ) {
3504+ expiry_days = request.days .value ();
3505+ ldpp_dout (this , 10 ) << " expiry_days=" << expiry_days << dendl;
3506+ } else {
3507+ expiry_days=nullopt ;
3508+ ldpp_dout (this , 10 ) << " expiry_days=" << expiry_days << dendl;
3509+ }
3510+
3511+ return 0 ;
3512+ }
3513+
3514+ void RGWRestoreObj_ObjStore_S3::send_response ()
3515+ {
3516+ if (op_ret < 0 )
3517+ {
3518+ set_req_state_err (s, op_ret);
3519+ dump_errno (s);
3520+ end_header (s, this );
3521+ dump_start (s);
3522+ return ;
3523+ }
3524+
3525+ rgw::sal::Attrs attrs = s->object ->get_attrs ();
3526+ auto attr_iter = attrs.find (RGW_ATTR_RESTORE_STATUS);
3527+ rgw::sal::RGWRestoreStatus restore_status;
3528+ if (attr_iter != attrs.end ()) {
3529+ bufferlist bl = attr_iter->second ;
3530+ auto iter = bl.cbegin ();
3531+ decode (restore_status, iter);
3532+ }
3533+ ldpp_dout (this , 10 ) << " restore_status=" << restore_status << dendl;
3534+
3535+ if (attr_iter == attrs.end () || restore_status != rgw::sal::RGWRestoreStatus::None) {
3536+ s->err .http_ret = 202 ; // Accepted
3537+ dump_header (s, " x-amz-restore" , rgw_bl_str (restore_status));
3538+ } else if (restore_status != rgw::sal::RGWRestoreStatus::RestoreAlreadyInProgress) {
3539+ s->err .http_ret = 409 ; // Conflict
3540+ dump_header_if_nonempty (s, " x-amz-restore" , rgw_bl_str (restore_status));
3541+ } else if (restore_status != rgw::sal::RGWRestoreStatus::CloudRestored) {
3542+ s->err .http_ret = 200 ; // OK
3543+ dump_header_if_nonempty (s, " x-amz-restore" , rgw_bl_str (restore_status));
3544+ } else {
3545+ s->err .http_ret = 202 ; // Accepted
3546+ dump_header_if_nonempty (s, " x-amz-restore" , rgw_bl_str (restore_status));
3547+ }
3548+
3549+ dump_errno (s);
3550+ end_header (s, this );
3551+ dump_start (s);
3552+ }
3553+
34543554int RGWDeleteObj_ObjStore_S3::get_params (optional_yield y)
34553555{
34563556 const char *if_unmod = s->info .env ->get (" HTTP_X_AMZ_DELETE_IF_UNMODIFIED_SINCE" );
@@ -4910,6 +5010,9 @@ RGWOp *RGWHandler_REST_Obj_S3::op_post()
49105010 if (s->info .args .exists (" uploads" ))
49115011 return new RGWInitMultipart_ObjStore_S3;
49125012
5013+ if (s->info .args .exists (" restore" ))
5014+ return new RGWRestoreObj_ObjStore_S3;
5015+
49135016 if (is_select_op ())
49145017 return rgw::s3select::create_s3select_op ();
49155018
@@ -5961,6 +6064,7 @@ AWSGeneralAbstractor::get_auth_data_v4(const req_state* const s,
59616064 case RGW_OP_PUT_BUCKET_TAGGING:
59626065 case RGW_OP_PUT_BUCKET_REPLICATION:
59636066 case RGW_OP_PUT_LC:
6067+ case RGW_OP_RESTORE_OBJ:
59646068 case RGW_OP_SET_REQUEST_PAYMENT:
59656069 case RGW_OP_PUBSUB_NOTIF_CREATE:
59666070 case RGW_OP_PUBSUB_NOTIF_DELETE:
0 commit comments