1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_RGW_REST_SWIFT_H
5 #define CEPH_RGW_REST_SWIFT_H
6 #define TIME_BUF_SIZE 128
8 #include <boost/optional.hpp>
9 #include <boost/utility/typed_in_place_factory.hpp>
13 #include "rgw_swift_auth.h"
14 #include "rgw_http_errors.h"
16 #include <boost/utility/string_ref.hpp>
18 class RGWGetObj_ObjStore_SWIFT
: public RGWGetObj_ObjStore
{
19 int custom_http_ret
= 0;
21 RGWGetObj_ObjStore_SWIFT() {}
22 ~RGWGetObj_ObjStore_SWIFT() override
{}
24 int verify_permission() override
;
25 int get_params() override
;
26 int send_response_data_error() override
;
27 int send_response_data(bufferlist
& bl
, off_t ofs
, off_t len
) override
;
29 void set_custom_http_response(const int http_ret
) {
30 custom_http_ret
= http_ret
;
33 bool need_object_expiration() override
{
38 class RGWListBuckets_ObjStore_SWIFT
: public RGWListBuckets_ObjStore
{
42 uint64_t get_default_max() const override
{
46 RGWListBuckets_ObjStore_SWIFT() : need_stats(true) {}
47 ~RGWListBuckets_ObjStore_SWIFT() override
{}
49 int get_params() override
;
50 void send_response_begin(bool has_buckets
) override
;
51 void send_response_data(RGWUserBuckets
& buckets
) override
;
52 void send_response_end() override
;
54 bool should_get_stats() override
{ return need_stats
; }
55 bool supports_account_metadata() override
{ return true; }
58 class RGWListBucket_ObjStore_SWIFT
: public RGWListBucket_ObjStore
{
61 RGWListBucket_ObjStore_SWIFT() {
64 ~RGWListBucket_ObjStore_SWIFT() override
{}
66 int get_params() override
;
67 void send_response() override
;
68 bool need_container_stats() override
{ return true; }
71 class RGWStatAccount_ObjStore_SWIFT
: public RGWStatAccount_ObjStore
{
72 map
<string
, bufferlist
> attrs
;
74 RGWStatAccount_ObjStore_SWIFT() {
76 ~RGWStatAccount_ObjStore_SWIFT() override
{}
78 void execute() override
;
79 void send_response() override
;
82 class RGWStatBucket_ObjStore_SWIFT
: public RGWStatBucket_ObjStore
{
84 RGWStatBucket_ObjStore_SWIFT() {}
85 ~RGWStatBucket_ObjStore_SWIFT() override
{}
87 void send_response() override
;
90 class RGWCreateBucket_ObjStore_SWIFT
: public RGWCreateBucket_ObjStore
{
92 bool need_metadata_upload() const override
{ return true; }
94 RGWCreateBucket_ObjStore_SWIFT() {}
95 ~RGWCreateBucket_ObjStore_SWIFT() override
{}
97 int get_params() override
;
98 void send_response() override
;
101 class RGWDeleteBucket_ObjStore_SWIFT
: public RGWDeleteBucket_ObjStore
{
103 RGWDeleteBucket_ObjStore_SWIFT() {}
104 ~RGWDeleteBucket_ObjStore_SWIFT() override
{}
106 void send_response() override
;
109 class RGWPutObj_ObjStore_SWIFT
: public RGWPutObj_ObjStore
{
112 RGWPutObj_ObjStore_SWIFT() {}
113 ~RGWPutObj_ObjStore_SWIFT() override
{}
115 int verify_permission() override
;
116 int get_params() override
;
117 void send_response() override
;
120 class RGWPutMetadataAccount_ObjStore_SWIFT
: public RGWPutMetadataAccount_ObjStore
{
122 RGWPutMetadataAccount_ObjStore_SWIFT() {}
123 ~RGWPutMetadataAccount_ObjStore_SWIFT() override
{}
125 int get_params() override
;
126 void send_response() override
;
129 class RGWPutMetadataBucket_ObjStore_SWIFT
: public RGWPutMetadataBucket_ObjStore
{
131 RGWPutMetadataBucket_ObjStore_SWIFT() {}
132 ~RGWPutMetadataBucket_ObjStore_SWIFT() override
{}
134 int get_params() override
;
135 void send_response() override
;
138 class RGWPutMetadataObject_ObjStore_SWIFT
: public RGWPutMetadataObject_ObjStore
{
140 RGWPutMetadataObject_ObjStore_SWIFT() {}
141 ~RGWPutMetadataObject_ObjStore_SWIFT() override
{}
143 int get_params() override
;
144 void send_response() override
;
145 bool need_object_expiration() override
{ return true; }
148 class RGWDeleteObj_ObjStore_SWIFT
: public RGWDeleteObj_ObjStore
{
150 RGWDeleteObj_ObjStore_SWIFT() {}
151 ~RGWDeleteObj_ObjStore_SWIFT() override
{}
153 int verify_permission() override
;
154 int get_params() override
;
155 bool need_object_expiration() override
{ return true; }
156 void send_response() override
;
159 class RGWCopyObj_ObjStore_SWIFT
: public RGWCopyObj_ObjStore
{
162 void dump_copy_info();
164 RGWCopyObj_ObjStore_SWIFT() : sent_header(false) {}
165 ~RGWCopyObj_ObjStore_SWIFT() override
{}
167 int init_dest_policy() override
;
168 int get_params() override
;
169 void send_response() override
;
170 void send_partial_response(off_t ofs
) override
;
173 class RGWGetACLs_ObjStore_SWIFT
: public RGWGetACLs_ObjStore
{
175 RGWGetACLs_ObjStore_SWIFT() {}
176 ~RGWGetACLs_ObjStore_SWIFT() override
{}
178 void send_response() override
{}
181 class RGWPutACLs_ObjStore_SWIFT
: public RGWPutACLs_ObjStore
{
183 RGWPutACLs_ObjStore_SWIFT() : RGWPutACLs_ObjStore() {}
184 ~RGWPutACLs_ObjStore_SWIFT() override
{}
186 void send_response() override
{}
189 class RGWOptionsCORS_ObjStore_SWIFT
: public RGWOptionsCORS_ObjStore
{
191 RGWOptionsCORS_ObjStore_SWIFT() {}
192 ~RGWOptionsCORS_ObjStore_SWIFT() override
{}
194 void send_response() override
;
197 class RGWBulkDelete_ObjStore_SWIFT
: public RGWBulkDelete_ObjStore
{
199 RGWBulkDelete_ObjStore_SWIFT() {}
200 ~RGWBulkDelete_ObjStore_SWIFT() override
{}
202 int get_data(std::list
<RGWBulkDelete::acct_path_t
>& items
,
203 bool * is_truncated
) override
;
204 void send_response() override
;
207 class RGWBulkUploadOp_ObjStore_SWIFT
: public RGWBulkUploadOp_ObjStore
{
212 RGWBulkUploadOp_ObjStore_SWIFT()
216 ~RGWBulkUploadOp_ObjStore_SWIFT() = default;
218 std::unique_ptr
<StreamGetter
> create_stream() override
;
219 void send_response() override
;
222 class RGWInfo_ObjStore_SWIFT
: public RGWInfo_ObjStore
{
227 function
<void (Formatter
&, const md_config_t
&, RGWRados
&)> list_data
;
230 static const vector
<pair
<string
, struct info
>> swift_info
;
232 RGWInfo_ObjStore_SWIFT() {}
233 ~RGWInfo_ObjStore_SWIFT() override
{}
235 void execute() override
;
236 void send_response() override
;
237 static void list_swift_data(Formatter
& formatter
, const md_config_t
& config
, RGWRados
& store
);
238 static void list_tempauth_data(Formatter
& formatter
, const md_config_t
& config
, RGWRados
& store
);
239 static void list_tempurl_data(Formatter
& formatter
, const md_config_t
& config
, RGWRados
& store
);
240 static void list_slo_data(Formatter
& formatter
, const md_config_t
& config
, RGWRados
& store
);
241 static bool is_expired(const std::string
& expires
, CephContext
* cct
);
245 class RGWFormPost
: public RGWPostObj_ObjStore
{
246 std::string
get_current_filename() const override
;
247 std::string
get_current_content_type() const override
;
248 std::size_t get_max_file_size() /*const*/;
249 bool is_next_file_to_upload() override
;
251 bool is_non_expired();
252 void get_owner_info(const req_state
* s
,
253 RGWUserInfo
& owner_info
) const;
255 parts_collection_t ctrl_parts
;
256 boost::optional
<post_form_part
> current_data_part
;
258 bool stream_done
= false;
260 class SignatureHelper
;
262 RGWFormPost() = default;
263 ~RGWFormPost() = default;
265 void init(RGWRados
* store
,
267 RGWHandler
* dialect_handler
) override
;
269 int get_params() override
;
270 int get_data(ceph::bufferlist
& bl
, bool& again
) override
;
271 void send_response() override
;
273 static bool is_formpost_req(req_state
* const s
);
276 class RGWFormPost::SignatureHelper
279 static constexpr uint32_t output_size
=
280 CEPH_CRYPTO_HMACSHA1_DIGESTSIZE
* 2 + 1;
282 unsigned char dest
[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE
]; // 20
283 char dest_str
[output_size
];
286 SignatureHelper() = default;
288 const char* calc(const std::string
& key
,
289 const boost::string_ref
& path_info
,
290 const boost::string_ref
& redirect
,
291 const boost::string_ref
& max_file_size
,
292 const boost::string_ref
& max_file_count
,
293 const boost::string_ref
& expires
) {
294 using ceph::crypto::HMACSHA1
;
295 using UCHARPTR
= const unsigned char*;
297 HMACSHA1
hmac((UCHARPTR
) key
.data(), key
.size());
299 hmac
.Update((UCHARPTR
) path_info
.data(), path_info
.size());
300 hmac
.Update((UCHARPTR
) "\n", 1);
302 hmac
.Update((UCHARPTR
) redirect
.data(), redirect
.size());
303 hmac
.Update((UCHARPTR
) "\n", 1);
305 hmac
.Update((UCHARPTR
) max_file_size
.data(), max_file_size
.size());
306 hmac
.Update((UCHARPTR
) "\n", 1);
308 hmac
.Update((UCHARPTR
) max_file_count
.data(), max_file_count
.size());
309 hmac
.Update((UCHARPTR
) "\n", 1);
311 hmac
.Update((UCHARPTR
) expires
.data(), expires
.size());
315 buf_to_hex((UCHARPTR
) dest
, sizeof(dest
), dest_str
);
320 const char* get_signature() const {
324 bool is_equal_to(const std::string
& rhs
) const {
325 /* never allow out-of-range exception */
326 if (rhs
.size() < (output_size
- 1)) {
329 return rhs
.compare(0 /* pos */, output_size
, dest_str
) == 0;
332 }; /* RGWFormPost::SignatureHelper */
335 class RGWSwiftWebsiteHandler
{
336 RGWRados
* const store
;
338 RGWHandler_REST
* const handler
;
340 bool is_web_mode() const;
341 bool can_be_website_req() const;
342 bool is_web_dir() const;
343 bool is_index_present(const std::string
& index
);
345 int serve_errordoc(int http_ret
, std::string error_doc
);
347 RGWOp
* get_ws_redirect_op();
348 RGWOp
* get_ws_index_op();
349 RGWOp
* get_ws_listing_op();
351 RGWSwiftWebsiteHandler(RGWRados
* const store
,
353 RGWHandler_REST
* const handler
)
359 int error_handler(const int err_no
,
360 std::string
* const error_content
);
361 int retarget_bucket(RGWOp
* op
, RGWOp
** new_op
);
362 int retarget_object(RGWOp
* op
, RGWOp
** new_op
);
366 class RGWHandler_REST_SWIFT
: public RGWHandler_REST
{
367 friend class RGWRESTMgr_SWIFT
;
368 friend class RGWRESTMgr_SWIFT_Info
;
370 const rgw::auth::Strategy
& auth_strategy
;
372 virtual bool is_acl_op() {
376 static int init_from_header(struct req_state
* s
,
377 const std::string
& frontend_prefix
);
379 RGWHandler_REST_SWIFT(const rgw::auth::Strategy
& auth_strategy
)
380 : auth_strategy(auth_strategy
) {
382 ~RGWHandler_REST_SWIFT() override
= default;
384 static int validate_bucket_name(const string
& bucket
);
386 int init(RGWRados
*store
, struct req_state
*s
, rgw::io::BasicClient
*cio
) override
;
387 int authorize() override
;
388 int postauth_init() override
;
390 RGWAccessControlPolicy
*alloc_policy() { return nullptr; /* return new RGWAccessControlPolicy_SWIFT; */ }
391 void free_policy(RGWAccessControlPolicy
*policy
) { delete policy
; }
394 class RGWHandler_REST_Service_SWIFT
: public RGWHandler_REST_SWIFT
{
396 RGWOp
*op_get() override
;
397 RGWOp
*op_head() override
;
398 RGWOp
*op_put() override
;
399 RGWOp
*op_post() override
;
400 RGWOp
*op_delete() override
;
402 using RGWHandler_REST_SWIFT::RGWHandler_REST_SWIFT
;
403 ~RGWHandler_REST_Service_SWIFT() override
= default;
406 class RGWHandler_REST_Bucket_SWIFT
: public RGWHandler_REST_SWIFT
{
407 /* We need the boost::optional here only because of handler's late
408 * initialization (see the init() method). */
409 boost::optional
<RGWSwiftWebsiteHandler
> website_handler
;
411 bool is_obj_update_op() override
{
412 return s
->op
== OP_POST
;
415 RGWOp
*get_obj_op(bool get_data
);
416 RGWOp
*op_get() override
;
417 RGWOp
*op_head() override
;
418 RGWOp
*op_put() override
;
419 RGWOp
*op_delete() override
;
420 RGWOp
*op_post() override
;
421 RGWOp
*op_options() override
;
423 using RGWHandler_REST_SWIFT::RGWHandler_REST_SWIFT
;
424 ~RGWHandler_REST_Bucket_SWIFT() override
= default;
426 int error_handler(int err_no
, std::string
*error_content
) override
{
427 return website_handler
->error_handler(err_no
, error_content
);
430 int retarget(RGWOp
* op
, RGWOp
** new_op
) override
{
431 return website_handler
->retarget_bucket(op
, new_op
);
434 int init(RGWRados
* const store
,
435 struct req_state
* const s
,
436 rgw::io::BasicClient
* const cio
) override
{
437 website_handler
= boost::in_place
<RGWSwiftWebsiteHandler
>(store
, s
, this);
438 return RGWHandler_REST_SWIFT::init(store
, s
, cio
);
442 class RGWHandler_REST_Obj_SWIFT
: public RGWHandler_REST_SWIFT
{
443 /* We need the boost::optional here only because of handler's late
444 * initialization (see the init() method). */
445 boost::optional
<RGWSwiftWebsiteHandler
> website_handler
;
447 bool is_obj_update_op() override
{
448 return s
->op
== OP_POST
;
451 RGWOp
*get_obj_op(bool get_data
);
452 RGWOp
*op_get() override
;
453 RGWOp
*op_head() override
;
454 RGWOp
*op_put() override
;
455 RGWOp
*op_delete() override
;
456 RGWOp
*op_post() override
;
457 RGWOp
*op_copy() override
;
458 RGWOp
*op_options() override
;
461 using RGWHandler_REST_SWIFT::RGWHandler_REST_SWIFT
;
462 ~RGWHandler_REST_Obj_SWIFT() override
= default;
464 int error_handler(int err_no
, std::string
*error_content
) override
{
465 return website_handler
->error_handler(err_no
, error_content
);
468 int retarget(RGWOp
* op
, RGWOp
** new_op
) override
{
469 return website_handler
->retarget_object(op
, new_op
);
472 int init(RGWRados
* const store
,
473 struct req_state
* const s
,
474 rgw::io::BasicClient
* const cio
) override
{
475 website_handler
= boost::in_place
<RGWSwiftWebsiteHandler
>(store
, s
, this);
476 return RGWHandler_REST_SWIFT::init(store
, s
, cio
);
480 class RGWRESTMgr_SWIFT
: public RGWRESTMgr
{
482 RGWRESTMgr
* get_resource_mgr_as_default(struct req_state
* const s
,
483 const std::string
& uri
,
484 std::string
* const out_uri
) override
{
485 return this->get_resource_mgr(s
, uri
, out_uri
);
489 RGWRESTMgr_SWIFT() = default;
490 ~RGWRESTMgr_SWIFT() override
= default;
492 RGWHandler_REST
*get_handler(struct req_state
*s
,
493 const rgw::auth::StrategyRegistry
& auth_registry
,
494 const std::string
& frontend_prefix
) override
;
498 class RGWGetCrossDomainPolicy_ObjStore_SWIFT
499 : public RGWGetCrossDomainPolicy_ObjStore
{
501 RGWGetCrossDomainPolicy_ObjStore_SWIFT() = default;
502 ~RGWGetCrossDomainPolicy_ObjStore_SWIFT() override
= default;
504 void send_response() override
;
507 class RGWGetHealthCheck_ObjStore_SWIFT
508 : public RGWGetHealthCheck_ObjStore
{
510 RGWGetHealthCheck_ObjStore_SWIFT() = default;
511 ~RGWGetHealthCheck_ObjStore_SWIFT() override
= default;
513 void send_response() override
;
516 class RGWHandler_SWIFT_CrossDomain
: public RGWHandler_REST
{
518 RGWHandler_SWIFT_CrossDomain() = default;
519 ~RGWHandler_SWIFT_CrossDomain() override
= default;
521 RGWOp
*op_get() override
{
522 return new RGWGetCrossDomainPolicy_ObjStore_SWIFT();
525 int init(RGWRados
* const store
,
526 struct req_state
* const state
,
527 rgw::io::BasicClient
* const cio
) override
{
528 state
->dialect
= "swift";
529 state
->formatter
= new JSONFormatter
;
530 state
->format
= RGW_FORMAT_JSON
;
532 return RGWHandler::init(store
, state
, cio
);
535 int authorize() override
{
539 int postauth_init() override
{
543 int read_permissions(RGWOp
*) override
{
547 virtual RGWAccessControlPolicy
*alloc_policy() { return nullptr; }
548 virtual void free_policy(RGWAccessControlPolicy
*policy
) {}
551 class RGWRESTMgr_SWIFT_CrossDomain
: public RGWRESTMgr
{
553 RGWRESTMgr
*get_resource_mgr(struct req_state
* const s
,
554 const std::string
& uri
,
555 std::string
* const out_uri
) override
{
560 RGWRESTMgr_SWIFT_CrossDomain() = default;
561 ~RGWRESTMgr_SWIFT_CrossDomain() override
= default;
563 RGWHandler_REST
* get_handler(struct req_state
* const s
,
564 const rgw::auth::StrategyRegistry
&,
565 const std::string
&) override
{
566 s
->prot_flags
|= RGW_REST_SWIFT
;
567 return new RGWHandler_SWIFT_CrossDomain
;
572 class RGWHandler_SWIFT_HealthCheck
: public RGWHandler_REST
{
574 RGWHandler_SWIFT_HealthCheck() = default;
575 ~RGWHandler_SWIFT_HealthCheck() override
= default;
577 RGWOp
*op_get() override
{
578 return new RGWGetHealthCheck_ObjStore_SWIFT();
581 int init(RGWRados
* const store
,
582 struct req_state
* const state
,
583 rgw::io::BasicClient
* const cio
) override
{
584 state
->dialect
= "swift";
585 state
->formatter
= new JSONFormatter
;
586 state
->format
= RGW_FORMAT_JSON
;
588 return RGWHandler::init(store
, state
, cio
);
591 int authorize() override
{
595 int postauth_init() override
{
599 int read_permissions(RGWOp
*) override
{
603 virtual RGWAccessControlPolicy
*alloc_policy() { return nullptr; }
604 virtual void free_policy(RGWAccessControlPolicy
*policy
) {}
607 class RGWRESTMgr_SWIFT_HealthCheck
: public RGWRESTMgr
{
609 RGWRESTMgr
*get_resource_mgr(struct req_state
* const s
,
610 const std::string
& uri
,
611 std::string
* const out_uri
) override
{
616 RGWRESTMgr_SWIFT_HealthCheck() = default;
617 ~RGWRESTMgr_SWIFT_HealthCheck() override
= default;
619 RGWHandler_REST
* get_handler(struct req_state
* const s
,
620 const rgw::auth::StrategyRegistry
&,
621 const std::string
&) override
{
622 s
->prot_flags
|= RGW_REST_SWIFT
;
623 return new RGWHandler_SWIFT_HealthCheck
;
628 class RGWHandler_REST_SWIFT_Info
: public RGWHandler_REST_SWIFT
{
630 using RGWHandler_REST_SWIFT::RGWHandler_REST_SWIFT
;
631 ~RGWHandler_REST_SWIFT_Info() override
= default;
633 RGWOp
*op_get() override
{
634 return new RGWInfo_ObjStore_SWIFT();
637 int init(RGWRados
* const store
,
638 struct req_state
* const state
,
639 rgw::io::BasicClient
* const cio
) override
{
640 state
->dialect
= "swift";
641 state
->formatter
= new JSONFormatter
;
642 state
->format
= RGW_FORMAT_JSON
;
644 return RGWHandler::init(store
, state
, cio
);
647 int authorize() override
{
651 int postauth_init() override
{
655 int read_permissions(RGWOp
*) override
{
660 class RGWRESTMgr_SWIFT_Info
: public RGWRESTMgr
{
662 RGWRESTMgr_SWIFT_Info() = default;
663 ~RGWRESTMgr_SWIFT_Info() override
= default;
665 RGWHandler_REST
*get_handler(struct req_state
* s
,
666 const rgw::auth::StrategyRegistry
& auth_registry
,
667 const std::string
& frontend_prefix
) override
;