1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #include <boost/algorithm/string/predicate.hpp>
5 #include <boost/format.hpp>
6 #include <boost/optional.hpp>
7 #include <boost/utility/in_place_factory.hpp>
9 #include "include/ceph_assert.h"
12 #include "common/Formatter.h"
13 #include "common/utf8.h"
14 #include "common/ceph_json.h"
16 #include "rgw_rest_swift.h"
17 #include "rgw_acl_swift.h"
18 #include "rgw_cors_swift.h"
19 #include "rgw_formats.h"
20 #include "rgw_client_io.h"
21 #include "rgw_compression.h"
24 #include "rgw_auth_registry.h"
25 #include "rgw_swift_auth.h"
27 #include "rgw_request.h"
28 #include "rgw_process.h"
33 #include "services/svc_zone.h"
36 #include <string_view>
40 #define dout_context g_ceph_context
41 #define dout_subsys ceph_subsys_rgw
45 int RGWListBuckets_ObjStore_SWIFT::get_params(optional_yield y
)
47 prefix
= s
->info
.args
.get("prefix");
48 marker
= s
->info
.args
.get("marker");
49 end_marker
= s
->info
.args
.get("end_marker");
50 wants_reversed
= s
->info
.args
.exists("reverse");
53 std::swap(marker
, end_marker
);
56 std::string limit_str
= s
->info
.args
.get("limit");
57 if (!limit_str
.empty()) {
59 long l
= strict_strtol(limit_str
.c_str(), 10, &err
);
64 if (l
> (long)limit_max
|| l
< 0) {
65 return -ERR_PRECONDITION_FAILED
;
71 if (s
->cct
->_conf
->rgw_swift_need_stats
) {
73 int r
= s
->info
.args
.get_bool("stats", &stats
, &exists
);
89 static void dump_account_metadata(req_state
* const s
,
90 const RGWUsageStats
& global_stats
,
91 const std::map
<std::string
, RGWUsageStats
> &policies_stats
,
92 /* const */map
<string
, bufferlist
>& attrs
,
93 const RGWQuotaInfo
& quota
,
94 const RGWAccessControlPolicy_SWIFTAcct
&policy
)
96 /* Adding X-Timestamp to keep align with Swift API */
97 dump_header(s
, "X-Timestamp", ceph_clock_now());
99 dump_header(s
, "X-Account-Container-Count", global_stats
.buckets_count
);
100 dump_header(s
, "X-Account-Object-Count", global_stats
.objects_count
);
101 dump_header(s
, "X-Account-Bytes-Used", global_stats
.bytes_used
);
102 dump_header(s
, "X-Account-Bytes-Used-Actual", global_stats
.bytes_used_rounded
);
104 for (const auto& kv
: policies_stats
) {
105 const auto& policy_name
= camelcase_dash_http_attr(kv
.first
);
106 const auto& policy_stats
= kv
.second
;
108 dump_header_infixed(s
, "X-Account-Storage-Policy-", policy_name
,
109 "-Container-Count", policy_stats
.buckets_count
);
110 dump_header_infixed(s
, "X-Account-Storage-Policy-", policy_name
,
111 "-Object-Count", policy_stats
.objects_count
);
112 dump_header_infixed(s
, "X-Account-Storage-Policy-", policy_name
,
113 "-Bytes-Used", policy_stats
.bytes_used
);
114 dump_header_infixed(s
, "X-Account-Storage-Policy-", policy_name
,
115 "-Bytes-Used-Actual", policy_stats
.bytes_used_rounded
);
118 /* Dump TempURL-related stuff */
119 if (s
->perm_mask
== RGW_PERM_FULL_CONTROL
) {
120 auto iter
= s
->user
->get_info().temp_url_keys
.find(0);
121 if (iter
!= std::end(s
->user
->get_info().temp_url_keys
) && ! iter
->second
.empty()) {
122 dump_header(s
, "X-Account-Meta-Temp-Url-Key", iter
->second
);
125 iter
= s
->user
->get_info().temp_url_keys
.find(1);
126 if (iter
!= std::end(s
->user
->get_info().temp_url_keys
) && ! iter
->second
.empty()) {
127 dump_header(s
, "X-Account-Meta-Temp-Url-Key-2", iter
->second
);
131 /* Dump quota headers. */
133 if (quota
.max_size
>= 0) {
134 dump_header(s
, "X-Account-Meta-Quota-Bytes", quota
.max_size
);
137 /* Limit on the number of objects in a given account is a RadosGW's
138 * extension. Swift's account quota WSGI filter doesn't support it. */
139 if (quota
.max_objects
>= 0) {
140 dump_header(s
, "X-Account-Meta-Quota-Count", quota
.max_objects
);
144 /* Dump user-defined metadata items and generic attrs. */
145 const size_t PREFIX_LEN
= sizeof(RGW_ATTR_META_PREFIX
) - 1;
146 map
<string
, bufferlist
>::iterator iter
;
147 for (iter
= attrs
.lower_bound(RGW_ATTR_PREFIX
); iter
!= attrs
.end(); ++iter
) {
148 const char *name
= iter
->first
.c_str();
149 map
<string
, string
>::const_iterator geniter
= rgw_to_http_attrs
.find(name
);
151 if (geniter
!= rgw_to_http_attrs
.end()) {
152 dump_header(s
, geniter
->second
, iter
->second
);
153 } else if (strncmp(name
, RGW_ATTR_META_PREFIX
, PREFIX_LEN
) == 0) {
154 dump_header_prefixed(s
, "X-Account-Meta-",
155 camelcase_dash_http_attr(name
+ PREFIX_LEN
),
160 /* Dump account ACLs */
161 auto account_acls
= policy
.to_str();
163 dump_header(s
, "X-Account-Access-Control", std::move(*account_acls
));
167 void RGWListBuckets_ObjStore_SWIFT::send_response_begin(bool has_buckets
)
170 set_req_state_err(s
, op_ret
);
171 } else if (!has_buckets
&& s
->format
== RGWFormat::PLAIN
) {
172 op_ret
= STATUS_NO_CONTENT
;
173 set_req_state_err(s
, op_ret
);
176 if (! s
->cct
->_conf
->rgw_swift_enforce_content_length
) {
177 /* Adding account stats in the header to keep align with Swift API */
178 dump_account_metadata(s
,
181 s
->user
->get_attrs(),
182 s
->user
->get_info().quota
.user_quota
,
183 static_cast<RGWAccessControlPolicy_SWIFTAcct
&>(*s
->user_acl
));
185 dump_header(s
, "Accept-Ranges", "bytes");
186 end_header(s
, NULL
, NULL
, NO_CONTENT_LENGTH
, true);
191 s
->formatter
->open_array_section_with_attrs("account",
192 FormatterAttrs("name", s
->user
->get_display_name().c_str(), NULL
));
198 void RGWListBuckets_ObjStore_SWIFT::handle_listing_chunk(rgw::sal::BucketList
&& buckets
)
200 if (wants_reversed
) {
201 /* Just store in the reversal buffer. Its content will be handled later,
202 * in send_response_end(). */
203 reverse_buffer
.emplace(std::begin(reverse_buffer
), std::move(buckets
));
205 return send_response_data(buckets
);
209 void RGWListBuckets_ObjStore_SWIFT::send_response_data(rgw::sal::BucketList
& buckets
)
215 /* Take care of the prefix parameter of Swift API. There is no business
216 * in applying the filter earlier as we really need to go through all
217 * entries regardless of it (the headers like X-Account-Container-Count
218 * aren't affected by specifying prefix). */
219 const auto& m
= buckets
.get_buckets();
220 for (auto iter
= m
.lower_bound(prefix
);
221 iter
!= m
.end() && boost::algorithm::starts_with(iter
->first
, prefix
);
223 dump_bucket_entry(*iter
->second
);
227 void RGWListBuckets_ObjStore_SWIFT::dump_bucket_entry(const rgw::sal::Bucket
& bucket
)
229 s
->formatter
->open_object_section("container");
230 s
->formatter
->dump_string("name", bucket
.get_name());
233 s
->formatter
->dump_int("count", bucket
.get_count());
234 s
->formatter
->dump_int("bytes", bucket
.get_size());
237 s
->formatter
->close_section();
239 if (! s
->cct
->_conf
->rgw_swift_enforce_content_length
) {
240 rgw_flush_formatter(s
, s
->formatter
);
244 void RGWListBuckets_ObjStore_SWIFT::send_response_data_reversed(rgw::sal::BucketList
& buckets
)
250 /* Take care of the prefix parameter of Swift API. There is no business
251 * in applying the filter earlier as we really need to go through all
252 * entries regardless of it (the headers like X-Account-Container-Count
253 * aren't affected by specifying prefix). */
254 auto& m
= buckets
.get_buckets();
256 auto iter
= m
.rbegin();
257 for (/* initialized above */;
258 iter
!= m
.rend() && !boost::algorithm::starts_with(iter
->first
, prefix
);
263 for (/* iter carried */;
264 iter
!= m
.rend() && boost::algorithm::starts_with(iter
->first
, prefix
);
266 dump_bucket_entry(*iter
->second
);
270 void RGWListBuckets_ObjStore_SWIFT::send_response_end()
272 if (wants_reversed
) {
273 for (auto& buckets
: reverse_buffer
) {
274 send_response_data_reversed(buckets
);
279 s
->formatter
->close_section();
282 if (s
->cct
->_conf
->rgw_swift_enforce_content_length
) {
283 /* Adding account stats in the header to keep align with Swift API */
284 dump_account_metadata(s
,
287 s
->user
->get_attrs(),
288 s
->user
->get_info().quota
.user_quota
,
289 static_cast<RGWAccessControlPolicy_SWIFTAcct
&>(*s
->user_acl
));
291 end_header(s
, nullptr, nullptr, s
->formatter
->get_len(), true);
294 if (sent_data
|| s
->cct
->_conf
->rgw_swift_enforce_content_length
) {
295 rgw_flush_formatter_and_reset(s
, s
->formatter
);
299 int RGWListBucket_ObjStore_SWIFT::get_params(optional_yield y
)
301 prefix
= s
->info
.args
.get("prefix");
302 marker
= s
->info
.args
.get("marker");
303 end_marker
= s
->info
.args
.get("end_marker");
304 max_keys
= s
->info
.args
.get("limit");
307 s
->info
.args
.get_bool("allow_unordered", &allow_unordered
, false);
309 delimiter
= s
->info
.args
.get("delimiter");
311 op_ret
= parse_max_keys();
315 // S3 behavior is to silently cap the max-keys.
316 // Swift behavior is to abort.
317 if (max
> default_max
)
318 return -ERR_PRECONDITION_FAILED
;
321 if (s
->info
.args
.exists("path")) { // should handle empty path
322 path_args
= s
->info
.args
.get("path");
323 if (!delimiter
.empty() || !prefix
.empty()) {
330 if (path
.size() && path
[path
.size() - 1] != '/')
333 int len
= prefix
.size();
334 int delim_size
= delimiter
.size();
336 if (len
>= delim_size
) {
337 if (prefix
.substr(len
- delim_size
).compare(delimiter
) != 0)
338 prefix
.append(delimiter
);
345 static void dump_container_metadata(req_state
*,
346 const rgw::sal::Bucket
*,
348 const RGWBucketWebsiteConf
&);
350 void RGWListBucket_ObjStore_SWIFT::send_response()
352 vector
<rgw_bucket_dir_entry
>::iterator iter
= objs
.begin();
353 map
<string
, bool>::iterator pref_iter
= common_prefixes
.begin();
356 dump_container_metadata(s
, s
->bucket
.get(), quota
.bucket_quota
,
357 s
->bucket
->get_info().website_conf
);
359 s
->formatter
->open_array_section_with_attrs("container",
360 FormatterAttrs("name",
361 s
->bucket
->get_name().c_str(),
364 while (iter
!= objs
.end() || pref_iter
!= common_prefixes
.end()) {
365 bool do_pref
= false;
366 bool do_objs
= false;
368 if (iter
!= objs
.end()) {
371 if (pref_iter
== common_prefixes
.end())
373 else if (iter
== objs
.end())
375 else if (!key
.empty() && key
.name
.compare(pref_iter
->first
) == 0) {
378 } else if (!key
.empty() && key
.name
.compare(pref_iter
->first
) <= 0)
383 if (do_objs
&& (allow_unordered
|| marker
.empty() || marker
< key
)) {
384 if (key
.name
.compare(path
) == 0)
387 s
->formatter
->open_object_section("object");
388 s
->formatter
->dump_string("name", key
.name
);
389 s
->formatter
->dump_string("hash", iter
->meta
.etag
);
390 s
->formatter
->dump_int("bytes", iter
->meta
.accounted_size
);
391 if (!iter
->meta
.user_data
.empty())
392 s
->formatter
->dump_string("user_custom_data", iter
->meta
.user_data
);
393 string single_content_type
= iter
->meta
.content_type
;
394 if (iter
->meta
.content_type
.size()) {
395 // content type might hold multiple values, just dump the last one
396 ssize_t pos
= iter
->meta
.content_type
.rfind(',');
399 while (single_content_type
[pos
] == ' ')
401 single_content_type
= single_content_type
.substr(pos
);
403 s
->formatter
->dump_string("content_type", single_content_type
);
405 dump_time(s
, "last_modified", iter
->meta
.mtime
);
406 s
->formatter
->close_section();
409 if (do_pref
&& (marker
.empty() || pref_iter
->first
.compare(marker
.name
) > 0)) {
410 const string
& name
= pref_iter
->first
;
411 if (name
.compare(delimiter
) == 0)
414 s
->formatter
->open_object_section_with_attrs("subdir", FormatterAttrs("name", name
.c_str(), NULL
));
416 /* swift is a bit inconsistent here */
419 s
->formatter
->dump_string("name", name
);
422 s
->formatter
->dump_string("subdir", name
);
424 s
->formatter
->close_section();
433 s
->formatter
->close_section();
435 int64_t content_len
= 0;
437 content_len
= s
->formatter
->get_len();
438 if (content_len
== 0) {
439 op_ret
= STATUS_NO_CONTENT
;
441 } else if (op_ret
> 0) {
445 set_req_state_err(s
, op_ret
);
447 end_header(s
, this, NULL
, content_len
);
452 rgw_flush_formatter_and_reset(s
, s
->formatter
);
453 } // RGWListBucket_ObjStore_SWIFT::send_response
455 static void dump_container_metadata(req_state
*s
,
456 const rgw::sal::Bucket
* bucket
,
457 const RGWQuotaInfo
& quota
,
458 const RGWBucketWebsiteConf
& ws_conf
)
460 /* Adding X-Timestamp to keep align with Swift API */
461 dump_header(s
, "X-Timestamp", utime_t(s
->bucket
->get_info().creation_time
));
463 dump_header(s
, "X-Container-Object-Count", bucket
->get_count());
464 dump_header(s
, "X-Container-Bytes-Used", bucket
->get_size());
465 dump_header(s
, "X-Container-Bytes-Used-Actual", bucket
->get_size_rounded());
467 if (rgw::sal::Object::empty(s
->object
.get())) {
468 auto swift_policy
= \
469 static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
.get());
470 std::string read_acl
, write_acl
;
471 swift_policy
->to_str(read_acl
, write_acl
);
473 if (read_acl
.size()) {
474 dump_header(s
, "X-Container-Read", read_acl
);
476 if (write_acl
.size()) {
477 dump_header(s
, "X-Container-Write", write_acl
);
479 if (!s
->bucket
->get_placement_rule().name
.empty()) {
480 dump_header(s
, "X-Storage-Policy", s
->bucket
->get_placement_rule().name
);
482 dump_header(s
, "X-Storage-Class", s
->bucket
->get_placement_rule().get_storage_class());
484 /* Dump user-defined metadata items and generic attrs. */
485 const size_t PREFIX_LEN
= sizeof(RGW_ATTR_META_PREFIX
) - 1;
486 map
<string
, bufferlist
>::iterator iter
;
487 for (iter
= s
->bucket_attrs
.lower_bound(RGW_ATTR_PREFIX
);
488 iter
!= s
->bucket_attrs
.end();
490 const char *name
= iter
->first
.c_str();
491 map
<string
, string
>::const_iterator geniter
= rgw_to_http_attrs
.find(name
);
493 if (geniter
!= rgw_to_http_attrs
.end()) {
494 dump_header(s
, geniter
->second
, iter
->second
);
495 } else if (strncmp(name
, RGW_ATTR_META_PREFIX
, PREFIX_LEN
) == 0) {
496 dump_header_prefixed(s
, "X-Container-Meta-",
497 camelcase_dash_http_attr(name
+ PREFIX_LEN
),
503 /* Dump container versioning info. */
504 if (! s
->bucket
->get_info().swift_ver_location
.empty()) {
505 dump_header(s
, "X-Versions-Location",
506 url_encode(s
->bucket
->get_info().swift_ver_location
));
509 /* Dump quota headers. */
511 if (quota
.max_size
>= 0) {
512 dump_header(s
, "X-Container-Meta-Quota-Bytes", quota
.max_size
);
515 if (quota
.max_objects
>= 0) {
516 dump_header(s
, "X-Container-Meta-Quota-Count", quota
.max_objects
);
520 /* Dump Static Website headers. */
521 if (! ws_conf
.index_doc_suffix
.empty()) {
522 dump_header(s
, "X-Container-Meta-Web-Index", ws_conf
.index_doc_suffix
);
525 if (! ws_conf
.error_doc
.empty()) {
526 dump_header(s
, "X-Container-Meta-Web-Error", ws_conf
.error_doc
);
529 if (! ws_conf
.subdir_marker
.empty()) {
530 dump_header(s
, "X-Container-Meta-Web-Directory-Type",
531 ws_conf
.subdir_marker
);
534 if (! ws_conf
.listing_css_doc
.empty()) {
535 dump_header(s
, "X-Container-Meta-Web-Listings-CSS",
536 ws_conf
.listing_css_doc
);
539 if (ws_conf
.listing_enabled
) {
540 dump_header(s
, "X-Container-Meta-Web-Listings", "true");
543 /* Dump bucket's modification time. Compliance with the Swift API really
545 dump_last_modified(s
, s
->bucket_mtime
);
548 void RGWStatAccount_ObjStore_SWIFT::execute(optional_yield y
)
550 RGWStatAccount_ObjStore::execute(y
);
551 op_ret
= s
->user
->read_attrs(s
, s
->yield
);
552 attrs
= s
->user
->get_attrs();
555 void RGWStatAccount_ObjStore_SWIFT::send_response()
558 op_ret
= STATUS_NO_CONTENT
;
559 dump_account_metadata(s
,
563 s
->user
->get_info().quota
.user_quota
,
564 static_cast<RGWAccessControlPolicy_SWIFTAcct
&>(*s
->user_acl
));
567 set_req_state_err(s
, op_ret
);
570 end_header(s
, NULL
, NULL
, 0, true);
575 void RGWStatBucket_ObjStore_SWIFT::send_response()
578 op_ret
= STATUS_NO_CONTENT
;
579 dump_container_metadata(s
, bucket
.get(), quota
.bucket_quota
,
580 s
->bucket
->get_info().website_conf
);
583 set_req_state_err(s
, op_ret
);
586 end_header(s
, this, NULL
, 0, true);
590 static int get_swift_container_settings(req_state
* const s
,
591 rgw::sal::Driver
* const driver
,
592 RGWAccessControlPolicy
* const policy
,
593 bool * const has_policy
,
595 RGWCORSConfiguration
* const cors_config
,
596 bool * const has_cors
)
598 const char * const read_list
= s
->info
.env
->get("HTTP_X_CONTAINER_READ");
599 const char * const write_list
= s
->info
.env
->get("HTTP_X_CONTAINER_WRITE");
603 if (read_list
|| write_list
) {
604 RGWAccessControlPolicy_SWIFT
swift_policy(s
->cct
);
605 const auto r
= swift_policy
.create(s
, driver
,
607 s
->user
->get_display_name(),
615 *policy
= swift_policy
;
621 /*Check and update CORS configuration*/
622 const char *allow_origins
= s
->info
.env
->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_ALLOW_ORIGIN");
623 const char *allow_headers
= s
->info
.env
->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_ALLOW_HEADERS");
624 const char *expose_headers
= s
->info
.env
->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_EXPOSE_HEADERS");
625 const char *max_age
= s
->info
.env
->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_MAX_AGE");
627 RGWCORSConfiguration_SWIFT
*swift_cors
= new RGWCORSConfiguration_SWIFT
;
628 int r
= swift_cors
->create_update(allow_origins
, allow_headers
, expose_headers
, max_age
);
630 ldpp_dout(s
, 0) << "Error creating/updating the cors configuration" << dendl
;
635 *cors_config
= *swift_cors
;
643 #define ACCT_REMOVE_ATTR_PREFIX "HTTP_X_REMOVE_ACCOUNT_META_"
644 #define ACCT_PUT_ATTR_PREFIX "HTTP_X_ACCOUNT_META_"
645 #define CONT_REMOVE_ATTR_PREFIX "HTTP_X_REMOVE_CONTAINER_META_"
646 #define CONT_PUT_ATTR_PREFIX "HTTP_X_CONTAINER_META_"
648 static void get_rmattrs_from_headers(const req_state
* const s
,
649 const char * const put_prefix
,
650 const char * const del_prefix
,
651 set
<string
>& rmattr_names
)
653 const size_t put_prefix_len
= strlen(put_prefix
);
654 const size_t del_prefix_len
= strlen(del_prefix
);
656 for (const auto& kv
: s
->info
.env
->get_map()) {
657 size_t prefix_len
= 0;
658 const char * const p
= kv
.first
.c_str();
660 if (strncasecmp(p
, del_prefix
, del_prefix_len
) == 0) {
661 /* Explicitly requested removal. */
662 prefix_len
= del_prefix_len
;
663 } else if ((strncasecmp(p
, put_prefix
, put_prefix_len
) == 0)
664 && kv
.second
.empty()) {
665 /* Removal requested by putting an empty value. */
666 prefix_len
= put_prefix_len
;
669 if (prefix_len
> 0) {
670 string
name(RGW_ATTR_META_PREFIX
);
671 name
.append(lowercase_dash_http_attr(p
+ prefix_len
));
672 rmattr_names
.insert(name
);
677 static int get_swift_versioning_settings(
679 boost::optional
<std::string
>& swift_ver_location
)
681 /* Removing the Swift's versions location has lower priority than setting
682 * a new one. That's the reason why we're handling it first. */
683 const std::string vlocdel
=
684 s
->info
.env
->get("HTTP_X_REMOVE_VERSIONS_LOCATION", "");
685 if (vlocdel
.size()) {
686 swift_ver_location
= boost::in_place(std::string());
689 if (s
->info
.env
->exists("HTTP_X_VERSIONS_LOCATION")) {
690 /* If the Swift's versioning is globally disabled but someone wants to
691 * enable it for a given container, new version of Swift will generate
692 * the precondition failed error. */
693 if (! s
->cct
->_conf
->rgw_swift_versioning_enabled
) {
694 return -ERR_PRECONDITION_FAILED
;
697 swift_ver_location
= s
->info
.env
->get("HTTP_X_VERSIONS_LOCATION", "");
703 int RGWCreateBucket_ObjStore_SWIFT::get_params(optional_yield y
)
706 uint32_t policy_rw_mask
= 0;
708 int r
= get_swift_container_settings(s
, driver
, &policy
, &has_policy
,
709 &policy_rw_mask
, &cors_config
, &has_cors
);
715 policy
.create_default(s
->user
->get_id(), s
->user
->get_display_name());
718 location_constraint
= driver
->get_zone()->get_zonegroup().get_api_name();
719 get_rmattrs_from_headers(s
, CONT_PUT_ATTR_PREFIX
,
720 CONT_REMOVE_ATTR_PREFIX
, rmattr_names
);
721 placement_rule
.init(s
->info
.env
->get("HTTP_X_STORAGE_POLICY", ""), s
->info
.storage_class
);
723 return get_swift_versioning_settings(s
, swift_ver_location
);
726 static inline int handle_metadata_errors(req_state
* const s
, const int op_ret
)
728 if (op_ret
== -EFBIG
) {
729 /* Handle the custom error message of exceeding maximum custom attribute
730 * (stored as xattr) size. */
731 const auto error_message
= boost::str(
732 boost::format("Metadata value longer than %lld")
733 % s
->cct
->_conf
.get_val
<Option::size_t>("rgw_max_attr_size"));
734 set_req_state_err(s
, EINVAL
, error_message
);
736 } else if (op_ret
== -E2BIG
) {
737 const auto error_message
= boost::str(
738 boost::format("Too many metadata items; max %lld")
739 % s
->cct
->_conf
.get_val
<uint64_t>("rgw_max_attrs_num_in_req"));
740 set_req_state_err(s
, EINVAL
, error_message
);
747 void RGWCreateBucket_ObjStore_SWIFT::send_response()
749 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
750 if (meta_ret
!= op_ret
) {
754 op_ret
= STATUS_CREATED
;
755 } else if (op_ret
== -ERR_BUCKET_EXISTS
) {
756 op_ret
= STATUS_ACCEPTED
;
758 set_req_state_err(s
, op_ret
);
762 /* Propose ending HTTP header with 0 Content-Length header. */
763 end_header(s
, NULL
, NULL
, 0);
764 rgw_flush_formatter_and_reset(s
, s
->formatter
);
767 void RGWDeleteBucket_ObjStore_SWIFT::send_response()
771 r
= STATUS_NO_CONTENT
;
773 set_req_state_err(s
, r
);
775 end_header(s
, this, NULL
, 0);
776 rgw_flush_formatter_and_reset(s
, s
->formatter
);
779 static int get_delete_at_param(req_state
*s
, boost::optional
<real_time
> &delete_at
)
781 /* Handle Swift object expiration. */
782 real_time delat_proposal
;
783 string x_delete
= s
->info
.env
->get("HTTP_X_DELETE_AFTER", "");
785 if (x_delete
.empty()) {
786 x_delete
= s
->info
.env
->get("HTTP_X_DELETE_AT", "");
788 /* X-Delete-After HTTP is present. It means we need add its value
789 * to the current time. */
790 delat_proposal
= real_clock::now();
793 if (x_delete
.empty()) {
794 delete_at
= boost::none
;
795 if (s
->info
.env
->exists("HTTP_X_REMOVE_DELETE_AT")) {
796 delete_at
= boost::in_place(real_time());
801 long ts
= strict_strtoll(x_delete
.c_str(), 10, &err
);
807 delat_proposal
+= make_timespan(ts
);
808 if (delat_proposal
< real_clock::now()) {
812 delete_at
= delat_proposal
;
817 int RGWPutObj_ObjStore_SWIFT::verify_permission(optional_yield y
)
819 op_ret
= RGWPutObj_ObjStore::verify_permission(y
);
821 /* We have to differentiate error codes depending on whether user is
822 * anonymous (401 Unauthorized) or he doesn't have necessary permissions
823 * (403 Forbidden). */
824 if (s
->auth
.identity
->is_anonymous() && op_ret
== -EACCES
) {
831 int RGWPutObj_ObjStore_SWIFT::update_slo_segment_size(rgw_slo_entry
& entry
) {
834 const string
& path
= entry
.path
;
836 /* If the path starts with slashes, strip them all. */
837 const size_t pos_init
= path
.find_first_not_of('/');
839 if (pos_init
== string::npos
) {
843 const size_t pos_sep
= path
.find('/', pos_init
);
844 if (pos_sep
== string::npos
) {
848 string bucket_name
= path
.substr(pos_init
, pos_sep
- pos_init
);
849 string obj_name
= path
.substr(pos_sep
+ 1);
851 std::unique_ptr
<rgw::sal::Bucket
> bucket
;
853 if (bucket_name
.compare(s
->bucket
->get_name()) != 0) {
854 r
= driver
->get_bucket(s
, s
->user
.get(), s
->user
->get_id().tenant
, bucket_name
, &bucket
, s
->yield
);
856 ldpp_dout(this, 0) << "could not get bucket info for bucket="
857 << bucket_name
<< dendl
;
861 bucket
= s
->bucket
->clone();
864 /* fetch the stored size of the seg (or error if not valid) */
865 std::unique_ptr
<rgw::sal::Object
> slo_seg
= bucket
->get_object(rgw_obj_key(obj_name
));
868 slo_seg
->set_atomic();
871 RGWCompressionInfo cs_info
;
872 uint64_t size_bytes
{0};
874 r
= slo_seg
->get_obj_attrs(s
->yield
, s
);
879 size_bytes
= slo_seg
->get_obj_size();
881 r
= rgw_compression_info_from_attrset(slo_seg
->get_attrs(), compressed
, cs_info
);
887 size_bytes
= cs_info
.orig_size
;
890 /* "When the PUT operation sees the multipart-manifest=put query
891 * parameter, it reads the request body and verifies that each
892 * segment object exists and that the sizes and ETags match. If
893 * there is a mismatch, the PUT operation fails."
895 if (entry
.size_bytes
&&
896 (entry
.size_bytes
!= size_bytes
)) {
900 entry
.size_bytes
= size_bytes
;
903 } /* RGWPutObj_ObjStore_SWIFT::update_slo_segment_sizes */
905 int RGWPutObj_ObjStore_SWIFT::get_params(optional_yield y
)
907 if (s
->has_bad_meta
) {
912 const char *encoding
= s
->info
.env
->get("HTTP_TRANSFER_ENCODING");
913 if (!encoding
|| strcmp(encoding
, "chunked") != 0) {
914 ldpp_dout(this, 20) << "neither length nor chunked encoding" << dendl
;
915 return -ERR_LENGTH_REQUIRED
;
918 chunked_upload
= true;
921 supplied_etag
= s
->info
.env
->get("HTTP_ETAG");
923 if (!s
->generic_attrs
.count(RGW_ATTR_CONTENT_TYPE
)) {
924 ldpp_dout(this, 5) << "content type wasn't provided, trying to guess" << dendl
;
925 const char *suffix
= strrchr(s
->object
->get_name().c_str(), '.');
929 string
suffix_str(suffix
);
930 const char *mime
= rgw_find_mime_by_ext(suffix_str
);
932 s
->generic_attrs
[RGW_ATTR_CONTENT_TYPE
] = mime
;
938 policy
.create_default(s
->user
->get_id(), s
->user
->get_display_name());
940 int r
= get_delete_at_param(s
, delete_at
);
942 ldpp_dout(this, 5) << "ERROR: failed to get Delete-At param" << dendl
;
946 if (!s
->cct
->_conf
->rgw_swift_custom_header
.empty()) {
947 string custom_header
= s
->cct
->_conf
->rgw_swift_custom_header
;
948 auto data
= s
->info
.env
->get_optional(custom_header
);
954 dlo_manifest
= s
->info
.env
->get("HTTP_X_OBJECT_MANIFEST");
956 string multipart_manifest
= s
->info
.args
.get("multipart-manifest", &exists
);
958 if (multipart_manifest
!= "put") {
959 ldpp_dout(this, 5) << "invalid multipart-manifest http param: " << multipart_manifest
<< dendl
;
963 #define MAX_SLO_ENTRY_SIZE (1024 + 128) // 1024 - max obj name, 128 - enough extra for other info
964 uint64_t max_len
= s
->cct
->_conf
->rgw_max_slo_entries
* MAX_SLO_ENTRY_SIZE
;
966 slo_info
= new RGWSLOInfo
;
969 std::tie(r
, slo_info
->raw_data
) = rgw_rest_get_json_input_keep_data(s
->cct
, s
, slo_info
->entries
, max_len
);
971 ldpp_dout(this, 5) << "failed to read input for slo r=" << r
<< dendl
;
975 if ((int64_t)slo_info
->entries
.size() > s
->cct
->_conf
->rgw_max_slo_entries
) {
976 ldpp_dout(this, 5) << "too many entries in slo request: " << slo_info
->entries
.size() << dendl
;
981 // Allow use of MD5 digest in FIPS mode for non-cryptographic purposes
982 etag_sum
.SetFlags(EVP_MD_CTX_FLAG_NON_FIPS_ALLOW
);
983 uint64_t total_size
= 0;
984 for (auto& entry
: slo_info
->entries
) {
985 etag_sum
.Update((const unsigned char *)entry
.etag
.c_str(),
986 entry
.etag
.length());
988 /* if size_bytes == 0, it should be replaced with the
989 * real segment size (which could be 0); this follows from the
990 * fact that Swift requires all segments to exist, but permits
991 * the size_bytes element to be omitted from the SLO manifest, see
992 * https://docs.openstack.org/swift/latest/api/large_objects.html
994 r
= update_slo_segment_size(entry
);
999 total_size
+= entry
.size_bytes
;
1001 ldpp_dout(this, 20) << "slo_part: " << entry
.path
1002 << " size=" << entry
.size_bytes
1003 << " etag=" << entry
.etag
1006 complete_etag(etag_sum
, &lo_etag
);
1007 slo_info
->total_size
= total_size
;
1009 ofs
= slo_info
->raw_data
.length();
1012 return RGWPutObj_ObjStore::get_params(y
);
1015 void RGWPutObj_ObjStore_SWIFT::send_response()
1017 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
1022 op_ret
= STATUS_CREATED
;
1024 set_req_state_err(s
, op_ret
);
1027 if (! lo_etag
.empty()) {
1028 /* Static Large Object of Swift API has two etags represented by
1029 * following members:
1030 * - etag - for the manifest itself (it will be stored in xattrs),
1031 * - lo_etag - for the content composited from SLO's segments.
1032 * The value is calculated basing on segments' etags.
1033 * In response for PUT request we have to expose the second one.
1034 * The first one may be obtained by GET with "multipart-manifest=get"
1035 * in query string on a given SLO. */
1036 dump_etag(s
, lo_etag
, true /* quoted */);
1041 dump_last_modified(s
, mtime
);
1042 set_req_state_err(s
, op_ret
);
1044 end_header(s
, this);
1045 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1048 static int get_swift_account_settings(req_state
* const s
,
1049 rgw::sal::Driver
* const driver
,
1050 RGWAccessControlPolicy_SWIFTAcct
* const policy
,
1051 bool * const has_policy
)
1053 *has_policy
= false;
1055 const char * const acl_attr
= s
->info
.env
->get("HTTP_X_ACCOUNT_ACCESS_CONTROL");
1057 RGWAccessControlPolicy_SWIFTAcct
swift_acct_policy(s
->cct
);
1058 const bool r
= swift_acct_policy
.create(s
, driver
,
1060 s
->user
->get_display_name(),
1066 *policy
= swift_acct_policy
;
1073 int RGWPutMetadataAccount_ObjStore_SWIFT::get_params(optional_yield y
)
1075 if (s
->has_bad_meta
) {
1079 int ret
= get_swift_account_settings(s
,
1081 // FIXME: we need to carry unique_ptr in generic class
1082 // and allocate appropriate ACL class in the ctor
1083 static_cast<RGWAccessControlPolicy_SWIFTAcct
*>(&policy
),
1089 get_rmattrs_from_headers(s
, ACCT_PUT_ATTR_PREFIX
, ACCT_REMOVE_ATTR_PREFIX
,
1094 void RGWPutMetadataAccount_ObjStore_SWIFT::send_response()
1096 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
1097 if (meta_ret
!= op_ret
) {
1101 op_ret
= STATUS_NO_CONTENT
;
1103 set_req_state_err(s
, op_ret
);
1107 end_header(s
, this);
1108 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1111 int RGWPutMetadataBucket_ObjStore_SWIFT::get_params(optional_yield y
)
1113 if (s
->has_bad_meta
) {
1117 int r
= get_swift_container_settings(s
, driver
, &policy
, &has_policy
,
1118 &policy_rw_mask
, &cors_config
, &has_cors
);
1123 get_rmattrs_from_headers(s
, CONT_PUT_ATTR_PREFIX
, CONT_REMOVE_ATTR_PREFIX
,
1125 placement_rule
.init(s
->info
.env
->get("HTTP_X_STORAGE_POLICY", ""), s
->info
.storage_class
);
1127 return get_swift_versioning_settings(s
, swift_ver_location
);
1130 void RGWPutMetadataBucket_ObjStore_SWIFT::send_response()
1132 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
1133 if (meta_ret
!= op_ret
) {
1136 if (!op_ret
&& (op_ret
!= -EINVAL
)) {
1137 op_ret
= STATUS_NO_CONTENT
;
1139 set_req_state_err(s
, op_ret
);
1143 end_header(s
, this);
1144 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1147 int RGWPutMetadataObject_ObjStore_SWIFT::get_params(optional_yield y
)
1149 if (s
->has_bad_meta
) {
1153 /* Handle Swift object expiration. */
1154 int r
= get_delete_at_param(s
, delete_at
);
1156 ldpp_dout(this, 5) << "ERROR: failed to get Delete-At param" << dendl
;
1160 dlo_manifest
= s
->info
.env
->get("HTTP_X_OBJECT_MANIFEST");
1165 void RGWPutMetadataObject_ObjStore_SWIFT::send_response()
1167 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
1168 if (meta_ret
!= op_ret
) {
1172 op_ret
= STATUS_ACCEPTED
;
1174 set_req_state_err(s
, op_ret
);
1178 dump_content_length(s
, 0);
1182 end_header(s
, this);
1183 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1186 static void bulkdelete_respond(const unsigned num_deleted
,
1187 const unsigned int num_unfound
,
1188 const std::list
<RGWBulkDelete::fail_desc_t
>& failures
,
1189 const int prot_flags
, /* in */
1190 ceph::Formatter
& formatter
) /* out */
1192 formatter
.open_object_section("delete");
1197 if (!failures
.empty()) {
1198 int reason
= ERR_INVALID_REQUEST
;
1199 for (const auto& fail_desc
: failures
) {
1200 if (-ENOENT
!= fail_desc
.err
&& -EACCES
!= fail_desc
.err
) {
1201 reason
= fail_desc
.err
;
1205 set_req_state_err(err
, reason
, prot_flags
);
1206 dump_errno(err
, resp_status
);
1207 } else if (0 == num_deleted
&& 0 == num_unfound
) {
1208 /* 400 Bad Request */
1209 dump_errno(400, resp_status
);
1210 resp_body
= "Invalid bulk delete.";
1213 dump_errno(200, resp_status
);
1216 encode_json("Number Deleted", num_deleted
, &formatter
);
1217 encode_json("Number Not Found", num_unfound
, &formatter
);
1218 encode_json("Response Body", resp_body
, &formatter
);
1219 encode_json("Response Status", resp_status
, &formatter
);
1221 formatter
.open_array_section("Errors");
1222 for (const auto& fail_desc
: failures
) {
1223 formatter
.open_array_section("object");
1225 stringstream ss_name
;
1226 ss_name
<< fail_desc
.path
;
1227 encode_json("Name", ss_name
.str(), &formatter
);
1230 set_req_state_err(err
, fail_desc
.err
, prot_flags
);
1232 dump_errno(err
, status
);
1233 encode_json("Status", status
, &formatter
);
1234 formatter
.close_section();
1236 formatter
.close_section();
1238 formatter
.close_section();
1241 int RGWDeleteObj_ObjStore_SWIFT::verify_permission(optional_yield y
)
1243 op_ret
= RGWDeleteObj_ObjStore::verify_permission(y
);
1245 /* We have to differentiate error codes depending on whether user is
1246 * anonymous (401 Unauthorized) or he doesn't have necessary permissions
1247 * (403 Forbidden). */
1248 if (s
->auth
.identity
->is_anonymous() && op_ret
== -EACCES
) {
1255 int RGWDeleteObj_ObjStore_SWIFT::get_params(optional_yield y
)
1257 const string
& mm
= s
->info
.args
.get("multipart-manifest");
1258 multipart_delete
= (mm
.compare("delete") == 0);
1260 return RGWDeleteObj_ObjStore::get_params(y
);
1263 void RGWDeleteObj_ObjStore_SWIFT::send_response()
1267 if (multipart_delete
) {
1270 r
= STATUS_NO_CONTENT
;
1273 set_req_state_err(s
, r
);
1276 if (multipart_delete
) {
1277 end_header(s
, this /* RGWOp */, nullptr /* contype */,
1278 CHUNKED_TRANSFER_ENCODING
);
1281 bulkdelete_respond(deleter
->get_num_deleted(),
1282 deleter
->get_num_unfound(),
1283 deleter
->get_failures(),
1286 } else if (-ENOENT
== op_ret
) {
1287 bulkdelete_respond(0, 1, {}, s
->prot_flags
, *s
->formatter
);
1289 RGWBulkDelete::acct_path_t path
;
1290 path
.bucket_name
= s
->bucket_name
;
1291 path
.obj_key
= s
->object
->get_key();
1293 RGWBulkDelete::fail_desc_t fail_desc
;
1294 fail_desc
.err
= op_ret
;
1295 fail_desc
.path
= path
;
1297 bulkdelete_respond(0, 0, { fail_desc
}, s
->prot_flags
, *s
->formatter
);
1300 end_header(s
, this);
1303 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1307 static void get_contype_from_attrs(map
<string
, bufferlist
>& attrs
,
1308 string
& content_type
)
1310 map
<string
, bufferlist
>::iterator iter
= attrs
.find(RGW_ATTR_CONTENT_TYPE
);
1311 if (iter
!= attrs
.end()) {
1312 content_type
= rgw_bl_str(iter
->second
);
1316 static void dump_object_metadata(const DoutPrefixProvider
* dpp
, req_state
* const s
,
1317 const map
<string
, bufferlist
>& attrs
)
1319 map
<string
, string
> response_attrs
;
1321 for (auto kv
: attrs
) {
1322 const char * name
= kv
.first
.c_str();
1323 const auto aiter
= rgw_to_http_attrs
.find(name
);
1325 if (aiter
!= std::end(rgw_to_http_attrs
)) {
1326 response_attrs
[aiter
->second
] = rgw_bl_str(kv
.second
);
1327 } else if (strcmp(name
, RGW_ATTR_SLO_UINDICATOR
) == 0) {
1328 // this attr has an extra length prefix from encode() in prior versions
1329 dump_header(s
, "X-Object-Meta-Static-Large-Object", "True");
1330 } else if (strncmp(name
, RGW_ATTR_META_PREFIX
,
1331 sizeof(RGW_ATTR_META_PREFIX
)-1) == 0) {
1332 name
+= sizeof(RGW_ATTR_META_PREFIX
) - 1;
1333 dump_header_prefixed(s
, "X-Object-Meta-",
1334 camelcase_dash_http_attr(name
), kv
.second
);
1338 /* Handle override and fallback for Content-Disposition HTTP header.
1339 * At the moment this will be used only by TempURL of the Swift API. */
1340 const auto cditer
= rgw_to_http_attrs
.find(RGW_ATTR_CONTENT_DISP
);
1341 if (cditer
!= std::end(rgw_to_http_attrs
)) {
1342 const auto& name
= cditer
->second
;
1344 if (!s
->content_disp
.override
.empty()) {
1345 response_attrs
[name
] = s
->content_disp
.override
;
1346 } else if (!s
->content_disp
.fallback
.empty()
1347 && response_attrs
.find(name
) == std::end(response_attrs
)) {
1348 response_attrs
[name
] = s
->content_disp
.fallback
;
1352 for (const auto& kv
: response_attrs
) {
1353 dump_header(s
, kv
.first
, kv
.second
);
1356 const auto iter
= attrs
.find(RGW_ATTR_DELETE_AT
);
1357 if (iter
!= std::end(attrs
)) {
1360 decode(delete_at
, iter
->second
);
1361 if (!delete_at
.is_zero()) {
1362 dump_header(s
, "X-Delete-At", delete_at
.sec());
1364 } catch (buffer::error
& err
) {
1365 ldpp_dout(dpp
, 0) << "ERROR: cannot decode object's " RGW_ATTR_DELETE_AT
1372 int RGWCopyObj_ObjStore_SWIFT::init_dest_policy()
1374 dest_policy
.create_default(s
->user
->get_id(), s
->user
->get_display_name());
1379 int RGWCopyObj_ObjStore_SWIFT::get_params(optional_yield y
)
1381 if_mod
= s
->info
.env
->get("HTTP_IF_MODIFIED_SINCE");
1382 if_unmod
= s
->info
.env
->get("HTTP_IF_UNMODIFIED_SINCE");
1383 if_match
= s
->info
.env
->get("HTTP_COPY_IF_MATCH");
1384 if_nomatch
= s
->info
.env
->get("HTTP_COPY_IF_NONE_MATCH");
1386 const char * const fresh_meta
= s
->info
.env
->get("HTTP_X_FRESH_METADATA");
1387 if (fresh_meta
&& strcasecmp(fresh_meta
, "TRUE") == 0) {
1388 attrs_mod
= rgw::sal::ATTRSMOD_REPLACE
;
1390 attrs_mod
= rgw::sal::ATTRSMOD_MERGE
;
1393 int r
= get_delete_at_param(s
, delete_at
);
1395 ldpp_dout(this, 5) << "ERROR: failed to get Delete-At param" << dendl
;
1402 void RGWCopyObj_ObjStore_SWIFT::send_partial_response(off_t ofs
)
1404 if (! sent_header
) {
1406 op_ret
= STATUS_CREATED
;
1407 set_req_state_err(s
, op_ret
);
1409 end_header(s
, this);
1411 /* Send progress information. Note that this diverge from the original swift
1412 * spec. We do this in order to keep connection alive.
1415 s
->formatter
->open_array_section("progress");
1419 s
->formatter
->dump_int("ofs", (uint64_t)ofs
);
1421 rgw_flush_formatter(s
, s
->formatter
);
1424 void RGWCopyObj_ObjStore_SWIFT::dump_copy_info()
1426 /* Dump X-Copied-From. */
1427 dump_header(s
, "X-Copied-From", url_encode(src_bucket
->get_name()) +
1428 "/" + url_encode(s
->src_object
->get_name()));
1430 /* Dump X-Copied-From-Account. */
1432 dump_header(s
, "X-Copied-From-Account", url_encode(s
->user
->get_id().id
));
1434 /* Dump X-Copied-From-Last-Modified. */
1435 dump_time_header(s
, "X-Copied-From-Last-Modified", src_mtime
);
1438 void RGWCopyObj_ObjStore_SWIFT::send_response()
1440 if (! sent_header
) {
1441 string content_type
;
1443 op_ret
= STATUS_CREATED
;
1444 set_req_state_err(s
, op_ret
);
1447 dump_last_modified(s
, mtime
);
1449 get_contype_from_attrs(attrs
, content_type
);
1450 dump_object_metadata(this, s
, attrs
);
1451 end_header(s
, this, !content_type
.empty() ? content_type
.c_str()
1452 : "binary/octet-stream");
1454 s
->formatter
->close_section();
1455 rgw_flush_formatter(s
, s
->formatter
);
1459 int RGWGetObj_ObjStore_SWIFT::verify_permission(optional_yield y
)
1461 op_ret
= RGWGetObj_ObjStore::verify_permission(y
);
1463 /* We have to differentiate error codes depending on whether user is
1464 * anonymous (401 Unauthorized) or he doesn't have necessary permissions
1465 * (403 Forbidden). */
1466 if (s
->auth
.identity
->is_anonymous() && op_ret
== -EACCES
) {
1473 int RGWGetObj_ObjStore_SWIFT::get_params(optional_yield y
)
1475 const string
& mm
= s
->info
.args
.get("multipart-manifest");
1476 skip_manifest
= (mm
.compare("get") == 0);
1478 return RGWGetObj_ObjStore::get_params(y
);
1481 int RGWGetObj_ObjStore_SWIFT::send_response_data_error(optional_yield y
)
1483 std::string error_content
;
1484 op_ret
= error_handler(op_ret
, &error_content
, y
);
1486 /* The error handler has taken care of the error. */
1490 bufferlist error_bl
;
1491 error_bl
.append(error_content
);
1492 return send_response_data(error_bl
, 0, error_bl
.length());
1495 int RGWGetObj_ObjStore_SWIFT::send_response_data(bufferlist
& bl
,
1499 string content_type
;
1505 if (custom_http_ret
) {
1506 set_req_state_err(s
, 0);
1507 dump_errno(s
, custom_http_ret
);
1509 set_req_state_err(s
, (partial_content
&& !op_ret
) ? STATUS_PARTIAL_CONTENT
1514 end_header(s
, NULL
);
1520 dump_range(s
, ofs
, end
, s
->obj_size
);
1524 end_header(s
, NULL
);
1528 dump_content_length(s
, total_len
);
1529 dump_last_modified(s
, lastmod
);
1530 dump_header(s
, "X-Timestamp", utime_t(lastmod
));
1532 dump_header(s
, "X-Static-Large-Object", "True");
1536 if (! lo_etag
.empty()) {
1537 dump_etag(s
, lo_etag
, true /* quoted */);
1539 auto iter
= attrs
.find(RGW_ATTR_ETAG
);
1540 if (iter
!= attrs
.end()) {
1541 dump_etag(s
, iter
->second
.to_str());
1545 get_contype_from_attrs(attrs
, content_type
);
1546 dump_object_metadata(this, s
, attrs
);
1549 end_header(s
, this, !content_type
.empty() ? content_type
.c_str()
1550 : "binary/octet-stream");
1555 if (get_data
&& !op_ret
) {
1556 const auto r
= dump_body(s
, bl
.c_str() + bl_ofs
, bl_len
);
1561 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1566 void RGWOptionsCORS_ObjStore_SWIFT::send_response()
1568 string hdrs
, exp_hdrs
;
1569 uint32_t max_age
= CORS_MAX_AGE_INVALID
;
1570 /*EACCES means, there is no CORS registered yet for the bucket
1571 *ENOENT means, there is no match of the Origin in the list of CORSRule
1573 if (op_ret
== -ENOENT
)
1576 set_req_state_err(s
, op_ret
);
1578 end_header(s
, NULL
);
1581 get_response_params(hdrs
, exp_hdrs
, &max_age
);
1583 dump_access_control(s
, origin
, req_meth
, hdrs
.c_str(), exp_hdrs
.c_str(),
1585 end_header(s
, NULL
);
1588 int RGWBulkDelete_ObjStore_SWIFT::get_data(
1589 list
<RGWBulkDelete::acct_path_t
>& items
, bool * const is_truncated
)
1591 constexpr size_t MAX_LINE_SIZE
= 2048;
1593 RGWClientIOStreamBuf
ciosb(static_cast<RGWRestfulIO
&>(*(s
->cio
)),
1594 size_t(s
->cct
->_conf
->rgw_max_chunk_size
));
1595 istream
cioin(&ciosb
);
1597 char buf
[MAX_LINE_SIZE
];
1598 while (cioin
.getline(buf
, sizeof(buf
))) {
1599 string
path_str(buf
);
1601 ldpp_dout(this, 20) << "extracted Bulk Delete entry: " << path_str
<< dendl
;
1603 RGWBulkDelete::acct_path_t path
;
1605 /* We need to skip all slashes at the beginning in order to preserve
1606 * compliance with Swift. */
1607 const size_t start_pos
= path_str
.find_first_not_of('/');
1609 if (string::npos
!= start_pos
) {
1610 /* Seperator is the first slash after the leading ones. */
1611 const size_t sep_pos
= path_str
.find('/', start_pos
);
1613 if (string::npos
!= sep_pos
) {
1614 path
.bucket_name
= url_decode(path_str
.substr(start_pos
,
1615 sep_pos
- start_pos
));
1616 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
1618 /* It's guaranteed here that bucket name is at least one character
1619 * long and is different than slash. */
1620 path
.bucket_name
= url_decode(path_str
.substr(start_pos
));
1623 items
.push_back(path
);
1626 if (items
.size() == MAX_CHUNK_ENTRIES
) {
1627 *is_truncated
= true;
1632 *is_truncated
= false;
1636 void RGWBulkDelete_ObjStore_SWIFT::send_response()
1638 set_req_state_err(s
, op_ret
);
1640 end_header(s
, this /* RGWOp */, nullptr /* contype */,
1641 CHUNKED_TRANSFER_ENCODING
);
1643 bulkdelete_respond(deleter
->get_num_deleted(),
1644 deleter
->get_num_unfound(),
1645 deleter
->get_failures(),
1648 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1652 std::unique_ptr
<RGWBulkUploadOp::StreamGetter
>
1653 RGWBulkUploadOp_ObjStore_SWIFT::create_stream()
1655 class SwiftStreamGetter
: public StreamGetter
{
1656 const DoutPrefixProvider
* dpp
;
1657 const size_t conlen
;
1662 SwiftStreamGetter(const DoutPrefixProvider
* dpp
, req_state
* const s
, const size_t conlen
)
1669 ssize_t
get_at_most(size_t want
, ceph::bufferlist
& dst
) override
{
1670 /* maximum requested by a caller */
1671 /* data provided by client */
1672 /* RadosGW's limit. */
1673 const size_t max_chunk_size
= \
1674 static_cast<size_t>(s
->cct
->_conf
->rgw_max_chunk_size
);
1675 const size_t max_to_read
= std::min({ want
, conlen
- curpos
, max_chunk_size
});
1677 ldpp_dout(dpp
, 20) << "bulk_upload: get_at_most max_to_read="
1679 << ", dst.c_str()=" << reinterpret_cast<intptr_t>(dst
.c_str()) << dendl
;
1681 bufferptr
bp(max_to_read
);
1682 const auto read_len
= recv_body(s
, bp
.c_str(), max_to_read
);
1683 dst
.append(bp
, 0, read_len
);
1684 //const auto read_len = recv_body(s, dst.c_str(), max_to_read);
1690 return curpos
> s
->cct
->_conf
->rgw_max_put_size
? -ERR_TOO_LARGE
1694 ssize_t
get_exactly(size_t want
, ceph::bufferlist
& dst
) override
{
1695 ldpp_dout(dpp
, 20) << "bulk_upload: get_exactly want=" << want
<< dendl
;
1697 /* FIXME: do this in a loop. */
1698 const auto ret
= get_at_most(want
, dst
);
1699 ldpp_dout(dpp
, 20) << "bulk_upload: get_exactly ret=" << ret
<< dendl
;
1702 } else if (static_cast<size_t>(ret
) != want
) {
1714 ldpp_dout(this, 20) << "bulk upload: create_stream for length="
1715 << s
->length
<< dendl
;
1717 const size_t conlen
= atoll(s
->length
);
1718 return std::unique_ptr
<SwiftStreamGetter
>(new SwiftStreamGetter(this, s
, conlen
));
1722 void RGWBulkUploadOp_ObjStore_SWIFT::send_response()
1724 set_req_state_err(s
, op_ret
);
1726 end_header(s
, this /* RGWOp */, nullptr /* contype */,
1727 CHUNKED_TRANSFER_ENCODING
);
1728 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1730 s
->formatter
->open_object_section("delete");
1732 std::string resp_status
;
1733 std::string resp_body
;
1735 if (! failures
.empty()) {
1738 const auto last_err
= { failures
.back().err
};
1739 if (boost::algorithm::contains(last_err
, terminal_errors
)) {
1740 /* The terminal errors are affecting the status of the whole upload. */
1741 set_req_state_err(err
, failures
.back().err
, s
->prot_flags
);
1743 set_req_state_err(err
, ERR_INVALID_REQUEST
, s
->prot_flags
);
1746 dump_errno(err
, resp_status
);
1747 } else if (0 == num_created
&& failures
.empty()) {
1748 /* Nothing created, nothing failed. This means the archive contained no
1749 * entity we could understand (regular file or directory). We need to
1750 * send 400 Bad Request to an HTTP client in the internal status field. */
1751 dump_errno(400, resp_status
);
1752 resp_body
= "Invalid Tar File: No Valid Files";
1755 dump_errno(201, resp_status
);
1758 encode_json("Number Files Created", num_created
, s
->formatter
);
1759 encode_json("Response Body", resp_body
, s
->formatter
);
1760 encode_json("Response Status", resp_status
, s
->formatter
);
1762 s
->formatter
->open_array_section("Errors");
1763 for (const auto& fail_desc
: failures
) {
1764 s
->formatter
->open_array_section("object");
1766 encode_json("Name", fail_desc
.path
, s
->formatter
);
1769 set_req_state_err(err
, fail_desc
.err
, s
->prot_flags
);
1771 dump_errno(err
, status
);
1772 encode_json("Status", status
, s
->formatter
);
1774 s
->formatter
->close_section();
1776 s
->formatter
->close_section();
1778 s
->formatter
->close_section();
1779 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1783 void RGWGetCrossDomainPolicy_ObjStore_SWIFT::send_response()
1785 set_req_state_err(s
, op_ret
);
1787 end_header(s
, this, "application/xml");
1789 std::stringstream ss
;
1791 ss
<< R
"(<?xml version="1.0"?>)" << "\n"
1792 << R
"(<!DOCTYPE cross-domain-policy SYSTEM )"
1793 << R
"("http
://www.adobe.com/xml/dtds/cross-domain-policy.dtd" >)" << "\n"
1794 << R
"(<cross-domain-policy>)" << "\n"
1795 << g_conf()->rgw_cross_domain_policy
<< "\n"
1796 << R
"(</cross-domain-policy>)";
1798 dump_body(s
, ss
.str());
1801 void RGWGetHealthCheck_ObjStore_SWIFT::send_response()
1803 set_req_state_err(s
, op_ret
);
1805 end_header(s
, this, "application/xml");
1808 static constexpr char DISABLED
[] = "DISABLED BY FILE";
1809 dump_body(s
, DISABLED
, strlen(DISABLED
));
1813 const vector
<pair
<string
, RGWInfo_ObjStore_SWIFT::info
>> RGWInfo_ObjStore_SWIFT::swift_info
=
1815 {"bulk_delete", {false, nullptr}},
1816 {"container_quotas", {false, nullptr}},
1817 {"swift", {false, RGWInfo_ObjStore_SWIFT::list_swift_data
}},
1818 {"tempurl", { false, RGWInfo_ObjStore_SWIFT::list_tempurl_data
}},
1819 {"slo", {false, RGWInfo_ObjStore_SWIFT::list_slo_data
}},
1820 {"account_quotas", {false, nullptr}},
1821 {"staticweb", {false, nullptr}},
1822 {"tempauth", {false, RGWInfo_ObjStore_SWIFT::list_tempauth_data
}},
1825 void RGWInfo_ObjStore_SWIFT::execute(optional_yield y
)
1827 bool is_admin_info_enabled
= false;
1829 const string
& swiftinfo_sig
= s
->info
.args
.get("swiftinfo_sig");
1830 const string
& swiftinfo_expires
= s
->info
.args
.get("swiftinfo_expires");
1832 if (!swiftinfo_sig
.empty() &&
1833 !swiftinfo_expires
.empty() &&
1834 !is_expired(swiftinfo_expires
, this)) {
1835 is_admin_info_enabled
= true;
1838 s
->formatter
->open_object_section("info");
1840 for (const auto& pair
: swift_info
) {
1841 if(!is_admin_info_enabled
&& pair
.second
.is_admin_info
)
1844 if (!pair
.second
.list_data
) {
1845 s
->formatter
->open_object_section((pair
.first
).c_str());
1846 s
->formatter
->close_section();
1849 pair
.second
.list_data(*(s
->formatter
), s
->cct
->_conf
, driver
);
1853 s
->formatter
->close_section();
1856 void RGWInfo_ObjStore_SWIFT::send_response()
1859 op_ret
= STATUS_NO_CONTENT
;
1861 set_req_state_err(s
, op_ret
);
1863 end_header(s
, this);
1864 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1867 void RGWInfo_ObjStore_SWIFT::list_swift_data(Formatter
& formatter
,
1868 const ConfigProxy
& config
,
1869 rgw::sal::Driver
* driver
)
1871 formatter
.open_object_section("swift");
1872 formatter
.dump_int("max_file_size", config
->rgw_max_put_size
);
1873 formatter
.dump_int("container_listing_limit", RGW_LIST_BUCKETS_LIMIT_MAX
);
1875 string
ceph_version(CEPH_GIT_NICE_VER
);
1876 formatter
.dump_string("version", ceph_version
);
1878 const size_t max_attr_name_len
= \
1879 g_conf().get_val
<Option::size_t>("rgw_max_attr_name_len");
1880 if (max_attr_name_len
) {
1881 const size_t meta_name_limit
= \
1882 max_attr_name_len
- strlen(RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX
);
1883 formatter
.dump_int("max_meta_name_length", meta_name_limit
);
1886 const size_t meta_value_limit
= g_conf().get_val
<Option::size_t>("rgw_max_attr_size");
1887 if (meta_value_limit
) {
1888 formatter
.dump_int("max_meta_value_length", meta_value_limit
);
1891 const size_t meta_num_limit
= \
1892 g_conf().get_val
<uint64_t>("rgw_max_attrs_num_in_req");
1893 if (meta_num_limit
) {
1894 formatter
.dump_int("max_meta_count", meta_num_limit
);
1897 formatter
.open_array_section("policies");
1898 const rgw::sal::ZoneGroup
& zonegroup
= driver
->get_zone()->get_zonegroup();
1900 std::set
<std::string
> targets
;
1901 zonegroup
.get_placement_target_names(targets
);
1902 for (const auto& placement_targets
: targets
) {
1903 formatter
.open_object_section("policy");
1904 if (placement_targets
.compare(zonegroup
.get_default_placement_name()) == 0)
1905 formatter
.dump_bool("default", true);
1906 formatter
.dump_string("name", placement_targets
.c_str());
1907 formatter
.close_section();
1909 formatter
.close_section();
1911 formatter
.dump_int("max_object_name_size", RGWHandler_REST::MAX_OBJ_NAME_LEN
);
1912 formatter
.dump_bool("strict_cors_mode", true);
1913 formatter
.dump_int("max_container_name_length", RGWHandler_REST::MAX_BUCKET_NAME_LEN
);
1914 formatter
.close_section();
1917 void RGWInfo_ObjStore_SWIFT::list_tempauth_data(Formatter
& formatter
,
1918 const ConfigProxy
& config
,
1919 rgw::sal::Driver
* driver
)
1921 formatter
.open_object_section("tempauth");
1922 formatter
.dump_bool("account_acls", true);
1923 formatter
.close_section();
1925 void RGWInfo_ObjStore_SWIFT::list_tempurl_data(Formatter
& formatter
,
1926 const ConfigProxy
& config
,
1927 rgw::sal::Driver
* driver
)
1929 formatter
.open_object_section("tempurl");
1930 formatter
.open_array_section("methods");
1931 formatter
.dump_string("methodname", "GET");
1932 formatter
.dump_string("methodname", "HEAD");
1933 formatter
.dump_string("methodname", "PUT");
1934 formatter
.dump_string("methodname", "POST");
1935 formatter
.dump_string("methodname", "DELETE");
1936 formatter
.close_section();
1937 formatter
.close_section();
1940 void RGWInfo_ObjStore_SWIFT::list_slo_data(Formatter
& formatter
,
1941 const ConfigProxy
& config
,
1942 rgw::sal::Driver
* driver
)
1944 formatter
.open_object_section("slo");
1945 formatter
.dump_int("max_manifest_segments", config
->rgw_max_slo_entries
);
1946 formatter
.close_section();
1949 bool RGWInfo_ObjStore_SWIFT::is_expired(const std::string
& expires
, const DoutPrefixProvider
*dpp
)
1952 const utime_t now
= ceph_clock_now();
1953 const uint64_t expiration
= (uint64_t)strict_strtoll(expires
.c_str(),
1956 ldpp_dout(dpp
, 5) << "failed to parse siginfo_expires: " << err
<< dendl
;
1960 if (expiration
<= (uint64_t)now
.sec()) {
1961 ldpp_dout(dpp
, 5) << "siginfo expired: " << expiration
<< " <= " << now
.sec() << dendl
;
1969 void RGWFormPost::init(rgw::sal::Driver
* const driver
,
1971 RGWHandler
* const dialect_handler
)
1973 if (!rgw::sal::Object::empty(s
->object
)) {
1974 prefix
= std::move(s
->object
->get_name());
1975 s
->object
->set_key(rgw_obj_key());
1978 return RGWPostObj_ObjStore::init(driver
, s
, dialect_handler
);
1981 std::size_t RGWFormPost::get_max_file_size() /*const*/
1983 std::string max_str
= get_part_str(ctrl_parts
, "max_file_size", "0");
1986 const std::size_t max_file_size
=
1987 static_cast<uint64_t>(strict_strtoll(max_str
.c_str(), 10, &err
));
1989 if (! err
.empty()) {
1990 ldpp_dout(this, 5) << "failed to parse FormPost's max_file_size: " << err
1995 return max_file_size
;
1998 bool RGWFormPost::is_non_expired()
2000 std::string expires
= get_part_str(ctrl_parts
, "expires", "0");
2003 const uint64_t expires_timestamp
=
2004 static_cast<uint64_t>(strict_strtoll(expires
.c_str(), 10, &err
));
2006 if (! err
.empty()) {
2007 ldpp_dout(this, 5) << "failed to parse FormPost's expires: " << err
<< dendl
;
2011 const utime_t now
= ceph_clock_now();
2012 if (std::cmp_less_equal(expires_timestamp
, now
.sec())) {
2013 ldpp_dout(this, 5) << "FormPost form expired: "
2014 << expires_timestamp
<< " <= " << now
.sec() << dendl
;
2021 bool RGWFormPost::is_integral()
2023 const std::string form_signature
= get_part_str(ctrl_parts
, "signature");
2026 get_owner_info(s
, s
->user
->get_info());
2027 s
->auth
.identity
= rgw::auth::transform_old_authinfo(s
);
2029 ldpp_dout(this, 5) << "cannot get user_info of account's owner" << dendl
;
2033 for (const auto& kv
: s
->user
->get_info().temp_url_keys
) {
2034 const int temp_url_key_num
= kv
.first
;
2035 const string
& temp_url_key
= kv
.second
;
2037 if (temp_url_key
.empty()) {
2041 SignatureHelper sig_helper
;
2042 sig_helper
.calc(temp_url_key
,
2043 s
->info
.request_uri
,
2044 get_part_str(ctrl_parts
, "redirect"),
2045 get_part_str(ctrl_parts
, "max_file_size", "0"),
2046 get_part_str(ctrl_parts
, "max_file_count", "0"),
2047 get_part_str(ctrl_parts
, "expires", "0"));
2049 const auto local_sig
= sig_helper
.get_signature();
2051 ldpp_dout(this, 20) << "FormPost signature [" << temp_url_key_num
<< "]"
2052 << " (calculated): " << local_sig
<< dendl
;
2054 if (sig_helper
.is_equal_to(form_signature
)) {
2057 ldpp_dout(this, 5) << "FormPost's signature mismatch: "
2058 << local_sig
<< " != " << form_signature
<< dendl
;
2065 void RGWFormPost::get_owner_info(const req_state
* const s
,
2066 RGWUserInfo
& owner_info
) const
2068 /* We cannot use req_state::bucket_name because it isn't available
2069 * now. It will be initialized in RGWHandler_REST_SWIFT::postauth_init(). */
2070 const string
& bucket_name
= s
->init_state
.url_bucket
;
2072 std::unique_ptr
<rgw::sal::User
> user
;
2074 /* TempURL in Formpost only requires that bucket name is specified. */
2075 if (bucket_name
.empty()) {
2079 if (!s
->account_name
.empty()) {
2083 const rgw_user
uid(s
->account_name
);
2084 if (uid
.tenant
.empty()) {
2085 const rgw_user
tenanted_uid(uid
.id
, uid
.id
);
2086 user
= driver
->get_user(tenanted_uid
);
2088 if (user
->load_user(s
, s
->yield
) >= 0) {
2095 user
= driver
->get_user(uid
);
2096 if (user
->load_user(s
, s
->yield
) < 0) {
2102 /* Need to get user info of bucket owner. */
2103 std::unique_ptr
<rgw::sal::Bucket
> bucket
;
2104 int ret
= driver
->get_bucket(s
, user
.get(), user
->get_tenant(), bucket_name
, &bucket
, s
->yield
);
2109 ldpp_dout(this, 20) << "temp url user (bucket owner): " << bucket
->get_info().owner
2112 user
= driver
->get_user(bucket
->get_info().owner
);
2113 if (user
->load_user(s
, s
->yield
) < 0) {
2117 owner_info
= user
->get_info();
2120 int RGWFormPost::get_params(optional_yield y
)
2122 /* The parentt class extracts boundary info from the Content-Type. */
2123 int ret
= RGWPostObj_ObjStore::get_params(y
);
2128 policy
.create_default(s
->user
->get_id(), s
->user
->get_display_name());
2130 /* Let's start parsing the HTTP body by parsing each form part step-
2131 * by-step till encountering the first part with file data. */
2133 struct post_form_part part
;
2134 ret
= read_form_part_header(&part
, stream_done
);
2139 if (s
->cct
->_conf
->subsys
.should_gather
<ceph_subsys_rgw
, 20>()) {
2140 ldpp_dout(this, 20) << "read part header -- part.name="
2141 << part
.name
<< dendl
;
2143 for (const auto& pair
: part
.fields
) {
2144 ldpp_dout(this, 20) << "field.name=" << pair
.first
<< dendl
;
2145 ldpp_dout(this, 20) << "field.val=" << pair
.second
.val
<< dendl
;
2146 ldpp_dout(this, 20) << "field.params:" << dendl
;
2148 for (const auto& param_pair
: pair
.second
.params
) {
2149 ldpp_dout(this, 20) << " " << param_pair
.first
2150 << " -> " << param_pair
.second
<< dendl
;
2156 /* Unexpected here. */
2157 err_msg
= "Malformed request";
2161 const auto field_iter
= part
.fields
.find("Content-Disposition");
2162 if (std::end(part
.fields
) != field_iter
&&
2163 std::end(field_iter
->second
.params
) != field_iter
->second
.params
.find("filename")) {
2164 /* First data part ahead. */
2165 current_data_part
= std::move(part
);
2167 /* Stop the iteration. We can assume that all control parts have been
2168 * already parsed. The rest of HTTP body should contain data parts
2169 * only. They will be picked up by ::get_data(). */
2172 /* Control part ahead. Receive, parse and driver for later usage. */
2174 ret
= read_data(part
.data
, s
->cct
->_conf
->rgw_max_chunk_size
,
2175 boundary
, stream_done
);
2178 } else if (! boundary
) {
2179 err_msg
= "Couldn't find boundary";
2183 ctrl_parts
[part
.name
] = std::move(part
);
2185 } while (! stream_done
);
2188 max_len
= get_max_file_size();
2190 if (! current_data_part
) {
2191 err_msg
= "FormPost: no files to process";
2195 if (! is_non_expired()) {
2196 err_msg
= "FormPost: Form Expired";
2200 if (! is_integral()) {
2201 err_msg
= "FormPost: Invalid Signature";
2208 std::string
RGWFormPost::get_current_filename() const
2211 const auto& field
= current_data_part
->fields
.at("Content-Disposition");
2212 const auto iter
= field
.params
.find("filename");
2214 if (std::end(field
.params
) != iter
) {
2215 return prefix
+ iter
->second
;
2217 } catch (std::out_of_range
&) {
2224 std::string
RGWFormPost::get_current_content_type() const
2227 const auto& field
= current_data_part
->fields
.at("Content-Type");
2229 } catch (std::out_of_range
&) {
2233 return std::string();
2236 bool RGWFormPost::is_next_file_to_upload()
2238 if (! stream_done
) {
2239 /* We have at least one additional part in the body. */
2240 struct post_form_part part
;
2241 int r
= read_form_part_header(&part
, stream_done
);
2246 const auto field_iter
= part
.fields
.find("Content-Disposition");
2247 if (std::end(part
.fields
) != field_iter
) {
2248 const auto& params
= field_iter
->second
.params
;
2249 const auto& filename_iter
= params
.find("filename");
2251 if (std::end(params
) != filename_iter
&& ! filename_iter
->second
.empty()) {
2252 current_data_part
= std::move(part
);
2261 int RGWFormPost::get_data(ceph::bufferlist
& bl
, bool& again
)
2265 int r
= read_data(bl
, s
->cct
->_conf
->rgw_max_chunk_size
,
2266 boundary
, stream_done
);
2271 /* Tell RGWPostObj::execute(optional_yield y) that it has some data to put. */
2277 void RGWFormPost::send_response()
2279 std::string redirect
= get_part_str(ctrl_parts
, "redirect");
2280 if (! redirect
.empty()) {
2281 op_ret
= STATUS_REDIRECT
;
2284 set_req_state_err(s
, op_ret
);
2285 s
->err
.err_code
= err_msg
;
2287 if (! redirect
.empty()) {
2288 dump_redirect(s
, redirect
);
2290 end_header(s
, this);
2293 bool RGWFormPost::is_formpost_req(req_state
* const s
)
2295 std::string content_type
;
2296 std::map
<std::string
, std::string
> params
;
2298 parse_boundary_params(s
->info
.env
->get("CONTENT_TYPE", ""),
2299 content_type
, params
);
2301 return boost::algorithm::iequals(content_type
, "multipart/form-data") &&
2302 params
.count("boundary") > 0;
2306 RGWOp
*RGWHandler_REST_Service_SWIFT::op_get()
2308 return new RGWListBuckets_ObjStore_SWIFT
;
2311 RGWOp
*RGWHandler_REST_Service_SWIFT::op_head()
2313 return new RGWStatAccount_ObjStore_SWIFT
;
2316 RGWOp
*RGWHandler_REST_Service_SWIFT::op_put()
2318 if (s
->info
.args
.exists("extract-archive")) {
2319 return new RGWBulkUploadOp_ObjStore_SWIFT
;
2324 RGWOp
*RGWHandler_REST_Service_SWIFT::op_post()
2326 if (s
->info
.args
.exists("bulk-delete")) {
2327 return new RGWBulkDelete_ObjStore_SWIFT
;
2329 return new RGWPutMetadataAccount_ObjStore_SWIFT
;
2332 RGWOp
*RGWHandler_REST_Service_SWIFT::op_delete()
2334 if (s
->info
.args
.exists("bulk-delete")) {
2335 return new RGWBulkDelete_ObjStore_SWIFT
;
2340 int RGWSwiftWebsiteHandler::serve_errordoc(const int http_ret
,
2341 const std::string error_doc
,
2344 /* Try to throw it all away. */
2345 s
->formatter
->reset();
2347 class RGWGetErrorPage
: public RGWGetObj_ObjStore_SWIFT
{
2349 RGWGetErrorPage(rgw::sal::Driver
* const driver
,
2350 RGWHandler_REST
* const handler
,
2352 const int http_ret
) {
2353 /* Calling a virtual from the base class is safe as the subobject should
2354 * be properly initialized and we haven't overridden the init method. */
2355 init(driver
, s
, handler
);
2357 set_custom_http_response(http_ret
);
2360 int error_handler(const int err_no
,
2361 std::string
* const error_content
, optional_yield y
) override
{
2362 /* Enforce that any error generated while getting the error page will
2363 * not be send to a client. This allows us to recover from the double
2364 * fault situation by sending the original message. */
2367 } get_errpage_op(driver
, handler
, s
, http_ret
);
2369 /* This is okay. It's an error, so nothing will run after this, and it can be
2370 * called by abort_early(), which can be called before s->object or s->bucket
2372 if (!rgw::sal::Bucket::empty(s
->bucket
.get())) {
2373 s
->object
= s
->bucket
->get_object(rgw_obj_key(std::to_string(http_ret
) + error_doc
));
2375 s
->object
= driver
->get_object(rgw_obj_key(std::to_string(http_ret
) + error_doc
));
2378 RGWOp
* newop
= &get_errpage_op
;
2380 return rgw_process_authenticated(handler
, newop
, &req
, s
, y
, driver
, true);
2383 int RGWSwiftWebsiteHandler::error_handler(const int err_no
,
2384 std::string
* const error_content
,
2387 if (!s
->bucket
.get()) {
2388 /* No bucket, default no-op handler */
2392 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2394 if (can_be_website_req() && ! ws_conf
.error_doc
.empty()) {
2395 set_req_state_err(s
, err_no
);
2396 return serve_errordoc(s
->err
.http_ret
, ws_conf
.error_doc
, y
);
2399 /* Let's go to the default, no-op handler. */
2403 bool RGWSwiftWebsiteHandler::is_web_mode() const
2405 const std::string_view webmode
= s
->info
.env
->get("HTTP_X_WEB_MODE", "");
2406 return boost::algorithm::iequals(webmode
, "true");
2409 bool RGWSwiftWebsiteHandler::can_be_website_req() const
2411 /* Static website works only with the GET or HEAD method. Nothing more. */
2412 static const std::set
<std::string_view
> ws_methods
= { "GET", "HEAD" };
2413 if (ws_methods
.count(s
->info
.method
) == 0) {
2417 /* We also need to handle early failures from the auth system. In such cases
2418 * req_state::auth.identity may be empty. Let's treat that the same way as
2419 * the anonymous access. */
2420 if (! s
->auth
.identity
) {
2424 /* Swift serves websites only for anonymous requests unless client explicitly
2425 * requested this behaviour by supplying X-Web-Mode HTTP header set to true. */
2426 if (s
->auth
.identity
->is_anonymous() || is_web_mode()) {
2433 RGWOp
* RGWSwiftWebsiteHandler::get_ws_redirect_op()
2435 class RGWMovedPermanently
: public RGWOp
{
2436 const std::string location
;
2438 explicit RGWMovedPermanently(const std::string
& location
)
2439 : location(location
) {
2442 int verify_permission(optional_yield
) override
{
2446 void execute(optional_yield
) override
{
2447 op_ret
= -ERR_PERMANENT_REDIRECT
;
2451 void send_response() override
{
2452 set_req_state_err(s
, op_ret
);
2454 dump_content_length(s
, 0);
2455 dump_redirect(s
, location
);
2456 end_header(s
, this);
2459 const char* name() const override
{
2460 return "RGWMovedPermanently";
2464 return new RGWMovedPermanently(s
->info
.request_uri
+ '/');
2467 RGWOp
* RGWSwiftWebsiteHandler::get_ws_index_op()
2469 /* Retarget to get obj on requested index file. */
2470 if (! s
->object
->empty()) {
2471 s
->object
->set_name(s
->object
->get_name() +
2472 s
->bucket
->get_info().website_conf
.get_index_doc());
2474 s
->object
->set_name(s
->bucket
->get_info().website_conf
.get_index_doc());
2477 auto getop
= new RGWGetObj_ObjStore_SWIFT
;
2478 getop
->set_get_data(boost::algorithm::equals("GET", s
->info
.method
));
2483 RGWOp
* RGWSwiftWebsiteHandler::get_ws_listing_op()
2485 class RGWWebsiteListing
: public RGWListBucket_ObjStore_SWIFT
{
2486 const std::string prefix_override
;
2488 int get_params(optional_yield
) override
{
2489 prefix
= prefix_override
;
2495 void send_response() override
{
2496 /* Generate the header now. */
2497 set_req_state_err(s
, op_ret
);
2499 dump_container_metadata(s
, s
->bucket
.get(), quota
.bucket_quota
,
2500 s
->bucket
->get_info().website_conf
);
2501 end_header(s
, this, "text/html");
2506 /* Now it's the time to start generating HTML bucket listing.
2507 * All the crazy stuff with crafting tags will be delegated to
2508 * RGWSwiftWebsiteListingFormatter. */
2509 std::stringstream ss
;
2510 RGWSwiftWebsiteListingFormatter
htmler(ss
, prefix
);
2512 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2513 htmler
.generate_header(s
->decoded_uri
,
2514 ws_conf
.listing_css_doc
);
2516 for (const auto& pair
: common_prefixes
) {
2517 std::string subdir_name
= pair
.first
;
2518 if (! subdir_name
.empty()) {
2519 /* To be compliant with Swift we need to remove the trailing
2521 subdir_name
.pop_back();
2524 htmler
.dump_subdir(subdir_name
);
2527 for (const rgw_bucket_dir_entry
& obj
: objs
) {
2528 if (! common_prefixes
.count(obj
.key
.name
+ '/')) {
2529 htmler
.dump_object(obj
);
2533 htmler
.generate_footer();
2534 dump_body(s
, ss
.str());
2537 /* Taking prefix_override by value to leverage std::string r-value ref
2538 * ctor and thus avoid extra memory copying/increasing ref counter. */
2539 explicit RGWWebsiteListing(std::string prefix_override
)
2540 : prefix_override(std::move(prefix_override
)) {
2544 std::string prefix
= std::move(s
->object
->get_name());
2545 s
->object
->set_key(rgw_obj_key());
2547 return new RGWWebsiteListing(std::move(prefix
));
2550 bool RGWSwiftWebsiteHandler::is_web_dir() const
2552 std::string subdir_name
= url_decode(s
->object
->get_name());
2554 /* Remove character from the subdir name if it is "/". */
2555 if (subdir_name
.empty()) {
2557 } else if (subdir_name
.back() == '/') {
2558 subdir_name
.pop_back();
2559 if (subdir_name
.empty()) {
2564 std::unique_ptr
<rgw::sal::Object
> obj
= s
->bucket
->get_object(rgw_obj_key(std::move(subdir_name
)));
2566 /* First, get attrset of the object we'll try to retrieve. */
2568 obj
->set_prefetch_data();
2570 RGWObjState
* state
= nullptr;
2571 if (obj
->get_obj_state(s
, &state
, s
->yield
, false)) {
2575 /* A nonexistent object cannot be a considered as a marker representing
2576 * the emulation of catalog in FS hierarchy. */
2577 if (! state
->exists
) {
2581 /* Decode the content type. */
2582 std::string content_type
;
2583 get_contype_from_attrs(state
->attrset
, content_type
);
2585 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2586 const std::string subdir_marker
= ws_conf
.subdir_marker
.empty()
2587 ? "application/directory"
2588 : ws_conf
.subdir_marker
;
2589 return subdir_marker
== content_type
&& state
->size
<= 1;
2592 bool RGWSwiftWebsiteHandler::is_index_present(const std::string
& index
) const
2594 std::unique_ptr
<rgw::sal::Object
> obj
= s
->bucket
->get_object(rgw_obj_key(index
));
2597 obj
->set_prefetch_data();
2599 RGWObjState
* state
= nullptr;
2600 if (obj
->get_obj_state(s
, &state
, s
->yield
, false)) {
2604 /* A nonexistent object cannot be a considered as a viable index. We will
2605 * try to list the bucket or - if this is impossible - return an error. */
2606 return state
->exists
;
2609 int RGWSwiftWebsiteHandler::retarget_bucket(RGWOp
* op
, RGWOp
** new_op
)
2611 ldpp_dout(s
, 10) << "Starting retarget" << dendl
;
2612 RGWOp
* op_override
= nullptr;
2614 /* In Swift static web content is served if the request is anonymous or
2615 * has X-Web-Mode HTTP header specified to true. */
2616 if (can_be_website_req()) {
2617 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2618 const auto& index
= s
->bucket
->get_info().website_conf
.get_index_doc();
2620 if (s
->decoded_uri
.back() != '/') {
2621 op_override
= get_ws_redirect_op();
2622 } else if (! index
.empty() && is_index_present(index
)) {
2623 op_override
= get_ws_index_op();
2624 } else if (ws_conf
.listing_enabled
) {
2625 op_override
= get_ws_listing_op();
2630 handler
->put_op(op
);
2631 op_override
->init(driver
, s
, handler
);
2633 *new_op
= op_override
;
2638 /* Return 404 Not Found is the request has web mode enforced but we static web
2639 * wasn't able to serve it accordingly. */
2640 return ! op_override
&& is_web_mode() ? -ENOENT
: 0;
2643 int RGWSwiftWebsiteHandler::retarget_object(RGWOp
* op
, RGWOp
** new_op
)
2645 ldpp_dout(s
, 10) << "Starting object retarget" << dendl
;
2646 RGWOp
* op_override
= nullptr;
2648 /* In Swift static web content is served if the request is anonymous or
2649 * has X-Web-Mode HTTP header specified to true. */
2650 if (can_be_website_req() && is_web_dir()) {
2651 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2652 const auto& index
= s
->bucket
->get_info().website_conf
.get_index_doc();
2654 if (s
->decoded_uri
.back() != '/') {
2655 op_override
= get_ws_redirect_op();
2656 } else if (! index
.empty() && is_index_present(index
)) {
2657 op_override
= get_ws_index_op();
2658 } else if (ws_conf
.listing_enabled
) {
2659 op_override
= get_ws_listing_op();
2662 /* A regular request or the specified object isn't a subdirectory marker.
2663 * We don't need any re-targeting. Error handling (like sending a custom
2664 * error page) will be performed by error_handler of the actual RGWOp. */
2669 handler
->put_op(op
);
2670 op_override
->init(driver
, s
, handler
);
2672 *new_op
= op_override
;
2677 /* Return 404 Not Found if we aren't able to re-target for subdir marker. */
2678 return ! op_override
? -ENOENT
: 0;
2682 RGWOp
*RGWHandler_REST_Bucket_SWIFT::get_obj_op(bool get_data
)
2685 return new RGWGetACLs_ObjStore_SWIFT
;
2689 return new RGWListBucket_ObjStore_SWIFT
;
2691 return new RGWStatBucket_ObjStore_SWIFT
;
2694 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_get()
2696 return get_obj_op(true);
2699 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_head()
2701 return get_obj_op(false);
2704 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_put()
2707 return new RGWPutACLs_ObjStore_SWIFT
;
2709 if(s
->info
.args
.exists("extract-archive")) {
2710 return new RGWBulkUploadOp_ObjStore_SWIFT
;
2712 return new RGWCreateBucket_ObjStore_SWIFT
;
2715 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_delete()
2717 return new RGWDeleteBucket_ObjStore_SWIFT
;
2720 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_post()
2722 if (RGWFormPost::is_formpost_req(s
)) {
2723 return new RGWFormPost
;
2725 return new RGWPutMetadataBucket_ObjStore_SWIFT
;
2729 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_options()
2731 return new RGWOptionsCORS_ObjStore_SWIFT
;
2735 RGWOp
*RGWHandler_REST_Obj_SWIFT::get_obj_op(bool get_data
)
2738 return new RGWGetACLs_ObjStore_SWIFT
;
2741 RGWGetObj_ObjStore_SWIFT
*get_obj_op
= new RGWGetObj_ObjStore_SWIFT
;
2742 get_obj_op
->set_get_data(get_data
);
2746 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_get()
2748 return get_obj_op(true);
2751 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_head()
2753 return get_obj_op(false);
2756 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_put()
2759 return new RGWPutACLs_ObjStore_SWIFT
;
2761 if(s
->info
.args
.exists("extract-archive")) {
2762 return new RGWBulkUploadOp_ObjStore_SWIFT
;
2764 if (s
->init_state
.src_bucket
.empty())
2765 return new RGWPutObj_ObjStore_SWIFT
;
2767 return new RGWCopyObj_ObjStore_SWIFT
;
2770 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_delete()
2772 return new RGWDeleteObj_ObjStore_SWIFT
;
2775 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_post()
2777 if (RGWFormPost::is_formpost_req(s
)) {
2778 return new RGWFormPost
;
2780 return new RGWPutMetadataObject_ObjStore_SWIFT
;
2784 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_copy()
2786 return new RGWCopyObj_ObjStore_SWIFT
;
2789 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_options()
2791 return new RGWOptionsCORS_ObjStore_SWIFT
;
2795 int RGWHandler_REST_SWIFT::authorize(const DoutPrefixProvider
*dpp
, optional_yield y
)
2797 return rgw::auth::Strategy::apply(dpp
, auth_strategy
, s
, y
);
2800 int RGWHandler_REST_SWIFT::postauth_init(optional_yield y
)
2802 struct req_init_state
* t
= &s
->init_state
;
2804 /* XXX Stub this until Swift Auth sets account into URL. */
2805 if (g_conf()->rgw_swift_account_in_url
2806 && s
->user
->get_id().id
== RGW_USER_ANON_ID
) {
2807 s
->bucket_tenant
= s
->account_name
;
2809 s
->bucket_tenant
= s
->user
->get_tenant();
2811 s
->bucket_name
= t
->url_bucket
;
2814 /* Need an object, even an empty one */
2815 s
->object
= driver
->get_object(rgw_obj_key());
2818 ldpp_dout(s
, 10) << "s->object=" <<
2819 (!s
->object
->empty() ? s
->object
->get_key() : rgw_obj_key("<NULL>"))
2821 << rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
)
2825 ret
= rgw_validate_tenant_name(s
->bucket_tenant
);
2828 ret
= validate_bucket_name(s
->bucket_name
);
2831 ret
= validate_object_name(s
->object
->get_name());
2835 if (!t
->src_bucket
.empty()) {
2837 * We don't allow cross-tenant copy at present. It requires account
2838 * names in the URL for Swift.
2840 s
->src_tenant_name
= s
->user
->get_tenant();
2841 s
->src_bucket_name
= t
->src_bucket
;
2843 ret
= validate_bucket_name(s
->src_bucket_name
);
2847 ret
= validate_object_name(s
->src_object
->get_name());
2856 int RGWHandler_REST_SWIFT::validate_bucket_name(const string
& bucket
)
2858 const size_t len
= bucket
.size();
2860 if (len
> MAX_BUCKET_NAME_LEN
) {
2861 /* Bucket Name too long. Generate custom error message and bind it
2862 * to an R-value reference. */
2863 const auto msg
= boost::str(
2864 boost::format("Container name length of %lld longer than %lld")
2865 % len
% int(MAX_BUCKET_NAME_LEN
));
2866 set_req_state_err(s
, ERR_INVALID_BUCKET_NAME
, msg
);
2867 return -ERR_INVALID_BUCKET_NAME
;
2874 if (bucket
[0] == '.')
2875 return -ERR_INVALID_BUCKET_NAME
;
2877 if (check_utf8(bucket
.c_str(), len
))
2878 return -ERR_INVALID_UTF8
;
2880 const char *s
= bucket
.c_str();
2882 for (size_t i
= 0; i
< len
; ++i
, ++s
) {
2883 if (*(unsigned char *)s
== 0xff)
2884 return -ERR_INVALID_BUCKET_NAME
;
2885 if (*(unsigned char *)s
== '/')
2886 return -ERR_INVALID_BUCKET_NAME
;
2892 static void next_tok(string
& str
, string
& tok
, char delim
)
2894 if (str
.size() == 0) {
2899 int pos
= str
.find(delim
);
2901 tok
= str
.substr(0, pos
);
2902 str
= str
.substr(pos
+ 1);
2908 int RGWHandler_REST_SWIFT::init_from_header(rgw::sal::Driver
* driver
,
2910 const std::string
& frontend_prefix
)
2915 s
->prot_flags
|= RGW_REST_SWIFT
;
2917 char reqbuf
[frontend_prefix
.length() + s
->decoded_uri
.length() + 1];
2918 sprintf(reqbuf
, "%s%s", frontend_prefix
.c_str(), s
->decoded_uri
.c_str());
2919 const char *req_name
= reqbuf
;
2923 if (*req_name
== '?') {
2926 p
= s
->info
.request_params
.c_str();
2929 s
->info
.args
.set(p
);
2930 s
->info
.args
.parse(s
);
2932 /* Skip the leading slash of URL hierarchy. */
2933 if (req_name
[0] != '/') {
2939 if ('\0' == req_name
[0]) {
2940 return g_conf()->rgw_swift_url_prefix
== "/" ? -ERR_BAD_URL
: 0;
2945 size_t pos
= req
.find('/');
2946 if (std::string::npos
!= pos
&& g_conf()->rgw_swift_url_prefix
!= "/") {
2947 bool cut_url
= g_conf()->rgw_swift_url_prefix
.length();
2948 first
= req
.substr(0, pos
);
2950 if (first
.compare(g_conf()->rgw_swift_url_prefix
) == 0) {
2952 /* Rewind to the "v1/..." part. */
2953 next_tok(req
, first
, '/');
2956 } else if (req
.compare(g_conf()->rgw_swift_url_prefix
) == 0) {
2957 s
->formatter
= new RGWFormatter_Plain
;
2958 return -ERR_BAD_URL
;
2963 std::string tenant_path
;
2964 if (! g_conf()->rgw_swift_tenant_name
.empty()) {
2965 tenant_path
= "/AUTH_";
2966 tenant_path
.append(g_conf()->rgw_swift_tenant_name
);
2969 /* verify that the request_uri conforms with what's expected */
2970 char buf
[g_conf()->rgw_swift_url_prefix
.length() + 16 + tenant_path
.length()];
2972 if (g_conf()->rgw_swift_url_prefix
== "/") {
2973 blen
= sprintf(buf
, "/v1%s", tenant_path
.c_str());
2975 blen
= sprintf(buf
, "/%s/v1%s",
2976 g_conf()->rgw_swift_url_prefix
.c_str(), tenant_path
.c_str());
2979 if (strncmp(reqbuf
, buf
, blen
) != 0) {
2983 int ret
= allocate_formatter(s
, RGWFormat::PLAIN
, true);
2989 next_tok(req
, ver
, '/');
2991 if (!tenant_path
.empty() || g_conf()->rgw_swift_account_in_url
) {
2992 string account_name
;
2993 next_tok(req
, account_name
, '/');
2995 /* Erase all pre-defined prefixes like "AUTH_" or "KEY_". */
2996 const vector
<string
> skipped_prefixes
= { "AUTH_", "KEY_" };
2998 for (const auto& pfx
: skipped_prefixes
) {
2999 const size_t comp_len
= min(account_name
.length(), pfx
.length());
3000 if (account_name
.compare(0, comp_len
, pfx
) == 0) {
3001 /* Prefix is present. Drop it. */
3002 account_name
= account_name
.substr(comp_len
);
3007 if (account_name
.empty()) {
3008 return -ERR_PRECONDITION_FAILED
;
3010 s
->account_name
= account_name
;
3014 next_tok(req
, first
, '/');
3016 ldpp_dout(s
, 10) << "ver=" << ver
<< " first=" << first
<< " req=" << req
<< dendl
;
3017 if (first
.size() == 0)
3020 s
->info
.effective_uri
= "/" + first
;
3022 // Save bucket to tide us over until token is parsed.
3023 s
->init_state
.url_bucket
= first
;
3026 s
->object
= driver
->get_object(
3027 rgw_obj_key(req
, s
->info
.env
->get("HTTP_X_OBJECT_VERSION_ID", ""))); /* rgw swift extension */
3028 s
->info
.effective_uri
.append("/" + s
->object
->get_name());
3034 int RGWHandler_REST_SWIFT::init(rgw::sal::Driver
* driver
, req_state
* s
,
3035 rgw::io::BasicClient
*cio
)
3037 struct req_init_state
*t
= &s
->init_state
;
3039 s
->dialect
= "swift";
3041 std::string copy_source
= s
->info
.env
->get("HTTP_X_COPY_FROM", "");
3042 if (! copy_source
.empty()) {
3044 bool result
= RGWCopyObj::parse_copy_location(copy_source
, t
->src_bucket
, key
, s
);
3046 return -ERR_BAD_URL
;
3047 s
->src_object
= driver
->get_object(key
);
3049 return -ERR_BAD_URL
;
3052 if (s
->op
== OP_COPY
) {
3053 std::string req_dest
= s
->info
.env
->get("HTTP_DESTINATION", "");
3054 if (req_dest
.empty())
3055 return -ERR_BAD_URL
;
3057 std::string dest_bucket_name
;
3058 rgw_obj_key dest_obj_key
;
3060 RGWCopyObj::parse_copy_location(req_dest
, dest_bucket_name
,
3063 return -ERR_BAD_URL
;
3065 std::string dest_object_name
= dest_obj_key
.name
;
3067 /* convert COPY operation into PUT */
3068 t
->src_bucket
= t
->url_bucket
;
3069 s
->src_object
= s
->object
->clone();
3070 t
->url_bucket
= dest_bucket_name
;
3071 s
->object
->set_name(dest_object_name
);
3075 s
->info
.storage_class
= s
->info
.env
->get("HTTP_X_OBJECT_STORAGE_CLASS", "");
3077 return RGWHandler_REST::init(driver
, s
, cio
);
3081 RGWRESTMgr_SWIFT::get_handler(rgw::sal::Driver
* driver
,
3083 const rgw::auth::StrategyRegistry
& auth_registry
,
3084 const std::string
& frontend_prefix
)
3086 int ret
= RGWHandler_REST_SWIFT::init_from_header(driver
, s
, frontend_prefix
);
3088 ldpp_dout(s
, 10) << "init_from_header returned err=" << ret
<< dendl
;
3092 const auto& auth_strategy
= auth_registry
.get_swift();
3094 if (s
->init_state
.url_bucket
.empty()) {
3095 return new RGWHandler_REST_Service_SWIFT(auth_strategy
);
3098 if (rgw::sal::Object::empty(s
->object
.get())) {
3099 return new RGWHandler_REST_Bucket_SWIFT(auth_strategy
);
3102 return new RGWHandler_REST_Obj_SWIFT(auth_strategy
);
3105 RGWHandler_REST
* RGWRESTMgr_SWIFT_Info::get_handler(
3106 rgw::sal::Driver
* driver
,
3108 const rgw::auth::StrategyRegistry
& auth_registry
,
3109 const std::string
& frontend_prefix
)
3111 s
->prot_flags
|= RGW_REST_SWIFT
;
3112 const auto& auth_strategy
= auth_registry
.get_swift();
3113 return new RGWHandler_REST_SWIFT_Info(auth_strategy
);