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_swift_auth.h"
26 #include "rgw_request.h"
27 #include "rgw_process.h"
32 #include "services/svc_zone.h"
35 #include <string_view>
39 #define dout_context g_ceph_context
40 #define dout_subsys ceph_subsys_rgw
44 int RGWListBuckets_ObjStore_SWIFT::get_params(optional_yield y
)
46 prefix
= s
->info
.args
.get("prefix");
47 marker
= s
->info
.args
.get("marker");
48 end_marker
= s
->info
.args
.get("end_marker");
49 wants_reversed
= s
->info
.args
.exists("reverse");
52 std::swap(marker
, end_marker
);
55 std::string limit_str
= s
->info
.args
.get("limit");
56 if (!limit_str
.empty()) {
58 long l
= strict_strtol(limit_str
.c_str(), 10, &err
);
63 if (l
> (long)limit_max
|| l
< 0) {
64 return -ERR_PRECONDITION_FAILED
;
70 if (s
->cct
->_conf
->rgw_swift_need_stats
) {
72 int r
= s
->info
.args
.get_bool("stats", &stats
, &exists
);
88 static void dump_account_metadata(struct req_state
* const s
,
89 const RGWUsageStats
& global_stats
,
90 const std::map
<std::string
, RGWUsageStats
> &policies_stats
,
91 /* const */map
<string
, bufferlist
>& attrs
,
92 const RGWQuotaInfo
& quota
,
93 const RGWAccessControlPolicy_SWIFTAcct
&policy
)
95 /* Adding X-Timestamp to keep align with Swift API */
96 dump_header(s
, "X-Timestamp", ceph_clock_now());
98 dump_header(s
, "X-Account-Container-Count", global_stats
.buckets_count
);
99 dump_header(s
, "X-Account-Object-Count", global_stats
.objects_count
);
100 dump_header(s
, "X-Account-Bytes-Used", global_stats
.bytes_used
);
101 dump_header(s
, "X-Account-Bytes-Used-Actual", global_stats
.bytes_used_rounded
);
103 for (const auto& kv
: policies_stats
) {
104 const auto& policy_name
= camelcase_dash_http_attr(kv
.first
);
105 const auto& policy_stats
= kv
.second
;
107 dump_header_infixed(s
, "X-Account-Storage-Policy-", policy_name
,
108 "-Container-Count", policy_stats
.buckets_count
);
109 dump_header_infixed(s
, "X-Account-Storage-Policy-", policy_name
,
110 "-Object-Count", policy_stats
.objects_count
);
111 dump_header_infixed(s
, "X-Account-Storage-Policy-", policy_name
,
112 "-Bytes-Used", policy_stats
.bytes_used
);
113 dump_header_infixed(s
, "X-Account-Storage-Policy-", policy_name
,
114 "-Bytes-Used-Actual", policy_stats
.bytes_used_rounded
);
117 /* Dump TempURL-related stuff */
118 if (s
->perm_mask
== RGW_PERM_FULL_CONTROL
) {
119 auto iter
= s
->user
->get_info().temp_url_keys
.find(0);
120 if (iter
!= std::end(s
->user
->get_info().temp_url_keys
) && ! iter
->second
.empty()) {
121 dump_header(s
, "X-Account-Meta-Temp-Url-Key", iter
->second
);
124 iter
= s
->user
->get_info().temp_url_keys
.find(1);
125 if (iter
!= std::end(s
->user
->get_info().temp_url_keys
) && ! iter
->second
.empty()) {
126 dump_header(s
, "X-Account-Meta-Temp-Url-Key-2", iter
->second
);
130 /* Dump quota headers. */
132 if (quota
.max_size
>= 0) {
133 dump_header(s
, "X-Account-Meta-Quota-Bytes", quota
.max_size
);
136 /* Limit on the number of objects in a given account is a RadosGW's
137 * extension. Swift's account quota WSGI filter doesn't support it. */
138 if (quota
.max_objects
>= 0) {
139 dump_header(s
, "X-Account-Meta-Quota-Count", quota
.max_objects
);
143 /* Dump user-defined metadata items and generic attrs. */
144 const size_t PREFIX_LEN
= sizeof(RGW_ATTR_META_PREFIX
) - 1;
145 map
<string
, bufferlist
>::iterator iter
;
146 for (iter
= attrs
.lower_bound(RGW_ATTR_PREFIX
); iter
!= attrs
.end(); ++iter
) {
147 const char *name
= iter
->first
.c_str();
148 map
<string
, string
>::const_iterator geniter
= rgw_to_http_attrs
.find(name
);
150 if (geniter
!= rgw_to_http_attrs
.end()) {
151 dump_header(s
, geniter
->second
, iter
->second
);
152 } else if (strncmp(name
, RGW_ATTR_META_PREFIX
, PREFIX_LEN
) == 0) {
153 dump_header_prefixed(s
, "X-Account-Meta-",
154 camelcase_dash_http_attr(name
+ PREFIX_LEN
),
159 /* Dump account ACLs */
160 auto account_acls
= policy
.to_str();
162 dump_header(s
, "X-Account-Access-Control", std::move(*account_acls
));
166 void RGWListBuckets_ObjStore_SWIFT::send_response_begin(bool has_buckets
)
169 set_req_state_err(s
, op_ret
);
170 } else if (!has_buckets
&& s
->format
== RGW_FORMAT_PLAIN
) {
171 op_ret
= STATUS_NO_CONTENT
;
172 set_req_state_err(s
, op_ret
);
175 if (! s
->cct
->_conf
->rgw_swift_enforce_content_length
) {
176 /* Adding account stats in the header to keep align with Swift API */
177 dump_account_metadata(s
,
180 s
->user
->get_attrs(),
181 s
->user
->get_info().user_quota
,
182 static_cast<RGWAccessControlPolicy_SWIFTAcct
&>(*s
->user_acl
));
184 dump_header(s
, "Accept-Ranges", "bytes");
185 end_header(s
, NULL
, NULL
, NO_CONTENT_LENGTH
, true);
190 s
->formatter
->open_array_section_with_attrs("account",
191 FormatterAttrs("name", s
->user
->get_display_name().c_str(), NULL
));
197 void RGWListBuckets_ObjStore_SWIFT::handle_listing_chunk(rgw::sal::BucketList
&& buckets
)
199 if (wants_reversed
) {
200 /* Just store in the reversal buffer. Its content will be handled later,
201 * in send_response_end(). */
202 reverse_buffer
.emplace(std::begin(reverse_buffer
), std::move(buckets
));
204 return send_response_data(buckets
);
208 void RGWListBuckets_ObjStore_SWIFT::send_response_data(rgw::sal::BucketList
& buckets
)
214 /* Take care of the prefix parameter of Swift API. There is no business
215 * in applying the filter earlier as we really need to go through all
216 * entries regardless of it (the headers like X-Account-Container-Count
217 * aren't affected by specifying prefix). */
218 const auto& m
= buckets
.get_buckets();
219 for (auto iter
= m
.lower_bound(prefix
);
220 iter
!= m
.end() && boost::algorithm::starts_with(iter
->first
, prefix
);
222 dump_bucket_entry(*iter
->second
);
226 void RGWListBuckets_ObjStore_SWIFT::dump_bucket_entry(const rgw::sal::Bucket
& bucket
)
228 s
->formatter
->open_object_section("container");
229 s
->formatter
->dump_string("name", bucket
.get_name());
232 s
->formatter
->dump_int("count", bucket
.get_count());
233 s
->formatter
->dump_int("bytes", bucket
.get_size());
236 s
->formatter
->close_section();
238 if (! s
->cct
->_conf
->rgw_swift_enforce_content_length
) {
239 rgw_flush_formatter(s
, s
->formatter
);
243 void RGWListBuckets_ObjStore_SWIFT::send_response_data_reversed(rgw::sal::BucketList
& buckets
)
249 /* Take care of the prefix parameter of Swift API. There is no business
250 * in applying the filter earlier as we really need to go through all
251 * entries regardless of it (the headers like X-Account-Container-Count
252 * aren't affected by specifying prefix). */
253 auto& m
= buckets
.get_buckets();
255 auto iter
= m
.rbegin();
256 for (/* initialized above */;
257 iter
!= m
.rend() && !boost::algorithm::starts_with(iter
->first
, prefix
);
262 for (/* iter carried */;
263 iter
!= m
.rend() && boost::algorithm::starts_with(iter
->first
, prefix
);
265 dump_bucket_entry(*iter
->second
);
269 void RGWListBuckets_ObjStore_SWIFT::send_response_end()
271 if (wants_reversed
) {
272 for (auto& buckets
: reverse_buffer
) {
273 send_response_data_reversed(buckets
);
278 s
->formatter
->close_section();
281 if (s
->cct
->_conf
->rgw_swift_enforce_content_length
) {
282 /* Adding account stats in the header to keep align with Swift API */
283 dump_account_metadata(s
,
286 s
->user
->get_attrs(),
287 s
->user
->get_info().user_quota
,
288 static_cast<RGWAccessControlPolicy_SWIFTAcct
&>(*s
->user_acl
));
290 end_header(s
, nullptr, nullptr, s
->formatter
->get_len(), true);
293 if (sent_data
|| s
->cct
->_conf
->rgw_swift_enforce_content_length
) {
294 rgw_flush_formatter_and_reset(s
, s
->formatter
);
298 int RGWListBucket_ObjStore_SWIFT::get_params(optional_yield y
)
300 prefix
= s
->info
.args
.get("prefix");
301 marker
= s
->info
.args
.get("marker");
302 end_marker
= s
->info
.args
.get("end_marker");
303 max_keys
= s
->info
.args
.get("limit");
306 s
->info
.args
.get_bool("allow_unordered", &allow_unordered
, false);
308 delimiter
= s
->info
.args
.get("delimiter");
310 op_ret
= parse_max_keys();
314 // S3 behavior is to silently cap the max-keys.
315 // Swift behavior is to abort.
316 if (max
> default_max
)
317 return -ERR_PRECONDITION_FAILED
;
320 if (s
->info
.args
.exists("path")) { // should handle empty path
321 path_args
= s
->info
.args
.get("path");
322 if (!delimiter
.empty() || !prefix
.empty()) {
329 if (path
.size() && path
[path
.size() - 1] != '/')
332 int len
= prefix
.size();
333 int delim_size
= delimiter
.size();
335 if (len
>= delim_size
) {
336 if (prefix
.substr(len
- delim_size
).compare(delimiter
) != 0)
337 prefix
.append(delimiter
);
344 static void dump_container_metadata(struct req_state
*,
345 const rgw::sal::Bucket
*,
347 const RGWBucketWebsiteConf
&);
349 void RGWListBucket_ObjStore_SWIFT::send_response()
351 vector
<rgw_bucket_dir_entry
>::iterator iter
= objs
.begin();
352 map
<string
, bool>::iterator pref_iter
= common_prefixes
.begin();
355 dump_container_metadata(s
, s
->bucket
.get(), bucket_quota
,
356 s
->bucket
->get_info().website_conf
);
358 s
->formatter
->open_array_section_with_attrs("container",
359 FormatterAttrs("name",
360 s
->bucket
->get_name().c_str(),
363 while (iter
!= objs
.end() || pref_iter
!= common_prefixes
.end()) {
364 bool do_pref
= false;
365 bool do_objs
= false;
367 if (iter
!= objs
.end()) {
370 if (pref_iter
== common_prefixes
.end())
372 else if (iter
== objs
.end())
374 else if (!key
.empty() && key
.name
.compare(pref_iter
->first
) == 0) {
377 } else if (!key
.empty() && key
.name
.compare(pref_iter
->first
) <= 0)
382 if (do_objs
&& (allow_unordered
|| marker
.empty() || marker
< key
)) {
383 if (key
.name
.compare(path
) == 0)
386 s
->formatter
->open_object_section("object");
387 s
->formatter
->dump_string("name", key
.name
);
388 s
->formatter
->dump_string("hash", iter
->meta
.etag
);
389 s
->formatter
->dump_int("bytes", iter
->meta
.accounted_size
);
390 if (!iter
->meta
.user_data
.empty())
391 s
->formatter
->dump_string("user_custom_data", iter
->meta
.user_data
);
392 string single_content_type
= iter
->meta
.content_type
;
393 if (iter
->meta
.content_type
.size()) {
394 // content type might hold multiple values, just dump the last one
395 ssize_t pos
= iter
->meta
.content_type
.rfind(',');
398 while (single_content_type
[pos
] == ' ')
400 single_content_type
= single_content_type
.substr(pos
);
402 s
->formatter
->dump_string("content_type", single_content_type
);
404 dump_time(s
, "last_modified", iter
->meta
.mtime
);
405 s
->formatter
->close_section();
408 if (do_pref
&& (marker
.empty() || pref_iter
->first
.compare(marker
.name
) > 0)) {
409 const string
& name
= pref_iter
->first
;
410 if (name
.compare(delimiter
) == 0)
413 s
->formatter
->open_object_section_with_attrs("subdir", FormatterAttrs("name", name
.c_str(), NULL
));
415 /* swift is a bit inconsistent here */
418 s
->formatter
->dump_string("name", name
);
421 s
->formatter
->dump_string("subdir", name
);
423 s
->formatter
->close_section();
432 s
->formatter
->close_section();
434 int64_t content_len
= 0;
436 content_len
= s
->formatter
->get_len();
437 if (content_len
== 0) {
438 op_ret
= STATUS_NO_CONTENT
;
440 } else if (op_ret
> 0) {
444 set_req_state_err(s
, op_ret
);
446 end_header(s
, this, NULL
, content_len
);
451 rgw_flush_formatter_and_reset(s
, s
->formatter
);
452 } // RGWListBucket_ObjStore_SWIFT::send_response
454 static void dump_container_metadata(struct req_state
*s
,
455 const rgw::sal::Bucket
* bucket
,
456 const RGWQuotaInfo
& quota
,
457 const RGWBucketWebsiteConf
& ws_conf
)
459 /* Adding X-Timestamp to keep align with Swift API */
460 dump_header(s
, "X-Timestamp", utime_t(s
->bucket
->get_info().creation_time
));
462 dump_header(s
, "X-Container-Object-Count", bucket
->get_count());
463 dump_header(s
, "X-Container-Bytes-Used", bucket
->get_size());
464 dump_header(s
, "X-Container-Bytes-Used-Actual", bucket
->get_size_rounded());
466 if (rgw::sal::Object::empty(s
->object
.get())) {
467 auto swift_policy
= \
468 static_cast<RGWAccessControlPolicy_SWIFT
*>(s
->bucket_acl
.get());
469 std::string read_acl
, write_acl
;
470 swift_policy
->to_str(read_acl
, write_acl
);
472 if (read_acl
.size()) {
473 dump_header(s
, "X-Container-Read", read_acl
);
475 if (write_acl
.size()) {
476 dump_header(s
, "X-Container-Write", write_acl
);
478 if (!s
->bucket
->get_placement_rule().name
.empty()) {
479 dump_header(s
, "X-Storage-Policy", s
->bucket
->get_placement_rule().name
);
481 dump_header(s
, "X-Storage-Class", s
->bucket
->get_placement_rule().get_storage_class());
483 /* Dump user-defined metadata items and generic attrs. */
484 const size_t PREFIX_LEN
= sizeof(RGW_ATTR_META_PREFIX
) - 1;
485 map
<string
, bufferlist
>::iterator iter
;
486 for (iter
= s
->bucket_attrs
.lower_bound(RGW_ATTR_PREFIX
);
487 iter
!= s
->bucket_attrs
.end();
489 const char *name
= iter
->first
.c_str();
490 map
<string
, string
>::const_iterator geniter
= rgw_to_http_attrs
.find(name
);
492 if (geniter
!= rgw_to_http_attrs
.end()) {
493 dump_header(s
, geniter
->second
, iter
->second
);
494 } else if (strncmp(name
, RGW_ATTR_META_PREFIX
, PREFIX_LEN
) == 0) {
495 dump_header_prefixed(s
, "X-Container-Meta-",
496 camelcase_dash_http_attr(name
+ PREFIX_LEN
),
502 /* Dump container versioning info. */
503 if (! s
->bucket
->get_info().swift_ver_location
.empty()) {
504 dump_header(s
, "X-Versions-Location",
505 url_encode(s
->bucket
->get_info().swift_ver_location
));
508 /* Dump quota headers. */
510 if (quota
.max_size
>= 0) {
511 dump_header(s
, "X-Container-Meta-Quota-Bytes", quota
.max_size
);
514 if (quota
.max_objects
>= 0) {
515 dump_header(s
, "X-Container-Meta-Quota-Count", quota
.max_objects
);
519 /* Dump Static Website headers. */
520 if (! ws_conf
.index_doc_suffix
.empty()) {
521 dump_header(s
, "X-Container-Meta-Web-Index", ws_conf
.index_doc_suffix
);
524 if (! ws_conf
.error_doc
.empty()) {
525 dump_header(s
, "X-Container-Meta-Web-Error", ws_conf
.error_doc
);
528 if (! ws_conf
.subdir_marker
.empty()) {
529 dump_header(s
, "X-Container-Meta-Web-Directory-Type",
530 ws_conf
.subdir_marker
);
533 if (! ws_conf
.listing_css_doc
.empty()) {
534 dump_header(s
, "X-Container-Meta-Web-Listings-CSS",
535 ws_conf
.listing_css_doc
);
538 if (ws_conf
.listing_enabled
) {
539 dump_header(s
, "X-Container-Meta-Web-Listings", "true");
542 /* Dump bucket's modification time. Compliance with the Swift API really
544 dump_last_modified(s
, s
->bucket_mtime
);
547 void RGWStatAccount_ObjStore_SWIFT::execute(optional_yield y
)
549 RGWStatAccount_ObjStore::execute(y
);
550 op_ret
= s
->user
->read_attrs(s
, s
->yield
);
551 attrs
= s
->user
->get_attrs();
554 void RGWStatAccount_ObjStore_SWIFT::send_response()
557 op_ret
= STATUS_NO_CONTENT
;
558 dump_account_metadata(s
,
562 s
->user
->get_info().user_quota
,
563 static_cast<RGWAccessControlPolicy_SWIFTAcct
&>(*s
->user_acl
));
566 set_req_state_err(s
, op_ret
);
569 end_header(s
, NULL
, NULL
, 0, true);
574 void RGWStatBucket_ObjStore_SWIFT::send_response()
577 op_ret
= STATUS_NO_CONTENT
;
578 dump_container_metadata(s
, bucket
.get(), bucket_quota
,
579 s
->bucket
->get_info().website_conf
);
582 set_req_state_err(s
, op_ret
);
585 end_header(s
, this, NULL
, 0, true);
589 static int get_swift_container_settings(req_state
* const s
,
590 rgw::sal::Store
* const store
,
591 RGWAccessControlPolicy
* const policy
,
592 bool * const has_policy
,
594 RGWCORSConfiguration
* const cors_config
,
595 bool * const has_cors
)
597 const char * const read_list
= s
->info
.env
->get("HTTP_X_CONTAINER_READ");
598 const char * const write_list
= s
->info
.env
->get("HTTP_X_CONTAINER_WRITE");
602 if (read_list
|| write_list
) {
603 RGWAccessControlPolicy_SWIFT
swift_policy(s
->cct
);
604 const auto r
= swift_policy
.create(s
, store
,
606 s
->user
->get_display_name(),
614 *policy
= swift_policy
;
620 /*Check and update CORS configuration*/
621 const char *allow_origins
= s
->info
.env
->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_ALLOW_ORIGIN");
622 const char *allow_headers
= s
->info
.env
->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_ALLOW_HEADERS");
623 const char *expose_headers
= s
->info
.env
->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_EXPOSE_HEADERS");
624 const char *max_age
= s
->info
.env
->get("HTTP_X_CONTAINER_META_ACCESS_CONTROL_MAX_AGE");
626 RGWCORSConfiguration_SWIFT
*swift_cors
= new RGWCORSConfiguration_SWIFT
;
627 int r
= swift_cors
->create_update(allow_origins
, allow_headers
, expose_headers
, max_age
);
629 ldpp_dout(s
, 0) << "Error creating/updating the cors configuration" << dendl
;
634 *cors_config
= *swift_cors
;
642 #define ACCT_REMOVE_ATTR_PREFIX "HTTP_X_REMOVE_ACCOUNT_META_"
643 #define ACCT_PUT_ATTR_PREFIX "HTTP_X_ACCOUNT_META_"
644 #define CONT_REMOVE_ATTR_PREFIX "HTTP_X_REMOVE_CONTAINER_META_"
645 #define CONT_PUT_ATTR_PREFIX "HTTP_X_CONTAINER_META_"
647 static void get_rmattrs_from_headers(const req_state
* const s
,
648 const char * const put_prefix
,
649 const char * const del_prefix
,
650 set
<string
>& rmattr_names
)
652 const size_t put_prefix_len
= strlen(put_prefix
);
653 const size_t del_prefix_len
= strlen(del_prefix
);
655 for (const auto& kv
: s
->info
.env
->get_map()) {
656 size_t prefix_len
= 0;
657 const char * const p
= kv
.first
.c_str();
659 if (strncasecmp(p
, del_prefix
, del_prefix_len
) == 0) {
660 /* Explicitly requested removal. */
661 prefix_len
= del_prefix_len
;
662 } else if ((strncasecmp(p
, put_prefix
, put_prefix_len
) == 0)
663 && kv
.second
.empty()) {
664 /* Removal requested by putting an empty value. */
665 prefix_len
= put_prefix_len
;
668 if (prefix_len
> 0) {
669 string
name(RGW_ATTR_META_PREFIX
);
670 name
.append(lowercase_dash_http_attr(p
+ prefix_len
));
671 rmattr_names
.insert(name
);
676 static int get_swift_versioning_settings(
678 boost::optional
<std::string
>& swift_ver_location
)
680 /* Removing the Swift's versions location has lower priority than setting
681 * a new one. That's the reason why we're handling it first. */
682 const std::string vlocdel
=
683 s
->info
.env
->get("HTTP_X_REMOVE_VERSIONS_LOCATION", "");
684 if (vlocdel
.size()) {
685 swift_ver_location
= boost::in_place(std::string());
688 if (s
->info
.env
->exists("HTTP_X_VERSIONS_LOCATION")) {
689 /* If the Swift's versioning is globally disabled but someone wants to
690 * enable it for a given container, new version of Swift will generate
691 * the precondition failed error. */
692 if (! s
->cct
->_conf
->rgw_swift_versioning_enabled
) {
693 return -ERR_PRECONDITION_FAILED
;
696 swift_ver_location
= s
->info
.env
->get("HTTP_X_VERSIONS_LOCATION", "");
702 int RGWCreateBucket_ObjStore_SWIFT::get_params(optional_yield y
)
705 uint32_t policy_rw_mask
= 0;
707 int r
= get_swift_container_settings(s
, store
, &policy
, &has_policy
,
708 &policy_rw_mask
, &cors_config
, &has_cors
);
714 policy
.create_default(s
->user
->get_id(), s
->user
->get_display_name());
717 location_constraint
= store
->get_zone()->get_zonegroup().api_name
;
718 get_rmattrs_from_headers(s
, CONT_PUT_ATTR_PREFIX
,
719 CONT_REMOVE_ATTR_PREFIX
, rmattr_names
);
720 placement_rule
.init(s
->info
.env
->get("HTTP_X_STORAGE_POLICY", ""), s
->info
.storage_class
);
722 return get_swift_versioning_settings(s
, swift_ver_location
);
725 static inline int handle_metadata_errors(req_state
* const s
, const int op_ret
)
727 if (op_ret
== -EFBIG
) {
728 /* Handle the custom error message of exceeding maximum custom attribute
729 * (stored as xattr) size. */
730 const auto error_message
= boost::str(
731 boost::format("Metadata value longer than %lld")
732 % s
->cct
->_conf
.get_val
<Option::size_t>("rgw_max_attr_size"));
733 set_req_state_err(s
, EINVAL
, error_message
);
735 } else if (op_ret
== -E2BIG
) {
736 const auto error_message
= boost::str(
737 boost::format("Too many metadata items; max %lld")
738 % s
->cct
->_conf
.get_val
<uint64_t>("rgw_max_attrs_num_in_req"));
739 set_req_state_err(s
, EINVAL
, error_message
);
746 void RGWCreateBucket_ObjStore_SWIFT::send_response()
748 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
749 if (meta_ret
!= op_ret
) {
753 op_ret
= STATUS_CREATED
;
754 } else if (op_ret
== -ERR_BUCKET_EXISTS
) {
755 op_ret
= STATUS_ACCEPTED
;
757 set_req_state_err(s
, op_ret
);
761 /* Propose ending HTTP header with 0 Content-Length header. */
762 end_header(s
, NULL
, NULL
, 0);
763 rgw_flush_formatter_and_reset(s
, s
->formatter
);
766 void RGWDeleteBucket_ObjStore_SWIFT::send_response()
770 r
= STATUS_NO_CONTENT
;
772 set_req_state_err(s
, r
);
774 end_header(s
, this, NULL
, 0);
775 rgw_flush_formatter_and_reset(s
, s
->formatter
);
778 static int get_delete_at_param(req_state
*s
, boost::optional
<real_time
> &delete_at
)
780 /* Handle Swift object expiration. */
781 real_time delat_proposal
;
782 string x_delete
= s
->info
.env
->get("HTTP_X_DELETE_AFTER", "");
784 if (x_delete
.empty()) {
785 x_delete
= s
->info
.env
->get("HTTP_X_DELETE_AT", "");
787 /* X-Delete-After HTTP is present. It means we need add its value
788 * to the current time. */
789 delat_proposal
= real_clock::now();
792 if (x_delete
.empty()) {
793 delete_at
= boost::none
;
794 if (s
->info
.env
->exists("HTTP_X_REMOVE_DELETE_AT")) {
795 delete_at
= boost::in_place(real_time());
800 long ts
= strict_strtoll(x_delete
.c_str(), 10, &err
);
806 delat_proposal
+= make_timespan(ts
);
807 if (delat_proposal
< real_clock::now()) {
811 delete_at
= delat_proposal
;
816 int RGWPutObj_ObjStore_SWIFT::verify_permission(optional_yield y
)
818 op_ret
= RGWPutObj_ObjStore::verify_permission(y
);
820 /* We have to differentiate error codes depending on whether user is
821 * anonymous (401 Unauthorized) or he doesn't have necessary permissions
822 * (403 Forbidden). */
823 if (s
->auth
.identity
->is_anonymous() && op_ret
== -EACCES
) {
830 int RGWPutObj_ObjStore_SWIFT::update_slo_segment_size(rgw_slo_entry
& entry
) {
833 const string
& path
= entry
.path
;
835 /* If the path starts with slashes, strip them all. */
836 const size_t pos_init
= path
.find_first_not_of('/');
838 if (pos_init
== string::npos
) {
842 const size_t pos_sep
= path
.find('/', pos_init
);
843 if (pos_sep
== string::npos
) {
847 string bucket_name
= path
.substr(pos_init
, pos_sep
- pos_init
);
848 string obj_name
= path
.substr(pos_sep
+ 1);
850 std::unique_ptr
<rgw::sal::Bucket
> bucket
;
852 if (bucket_name
.compare(s
->bucket
->get_name()) != 0) {
853 r
= store
->get_bucket(s
, s
->user
.get(), s
->user
->get_id().tenant
, bucket_name
, &bucket
, s
->yield
);
855 ldpp_dout(this, 0) << "could not get bucket info for bucket="
856 << bucket_name
<< dendl
;
860 bucket
= s
->bucket
->clone();
863 /* fetch the stored size of the seg (or error if not valid) */
864 std::unique_ptr
<rgw::sal::Object
> slo_seg
= bucket
->get_object(rgw_obj_key(obj_name
));
867 RGWObjectCtx
obj_ctx(store
);
868 slo_seg
->set_atomic(&obj_ctx
);
871 RGWCompressionInfo cs_info
;
872 uint64_t size_bytes
{0};
874 r
= slo_seg
->get_obj_attrs(&obj_ctx
, 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 if (s
->info
.env
->exists(custom_header
.c_str())) {
949 user_data
= s
->info
.env
->get(custom_header
.c_str());
953 dlo_manifest
= s
->info
.env
->get("HTTP_X_OBJECT_MANIFEST");
955 string multipart_manifest
= s
->info
.args
.get("multipart-manifest", &exists
);
957 if (multipart_manifest
!= "put") {
958 ldpp_dout(this, 5) << "invalid multipart-manifest http param: " << multipart_manifest
<< dendl
;
962 #define MAX_SLO_ENTRY_SIZE (1024 + 128) // 1024 - max obj name, 128 - enough extra for other info
963 uint64_t max_len
= s
->cct
->_conf
->rgw_max_slo_entries
* MAX_SLO_ENTRY_SIZE
;
965 slo_info
= new RGWSLOInfo
;
968 std::tie(r
, slo_info
->raw_data
) = rgw_rest_get_json_input_keep_data(s
->cct
, s
, slo_info
->entries
, max_len
);
970 ldpp_dout(this, 5) << "failed to read input for slo r=" << r
<< dendl
;
974 if ((int64_t)slo_info
->entries
.size() > s
->cct
->_conf
->rgw_max_slo_entries
) {
975 ldpp_dout(this, 5) << "too many entries in slo request: " << slo_info
->entries
.size() << dendl
;
980 // Allow use of MD5 digest in FIPS mode for non-cryptographic purposes
981 etag_sum
.SetFlags(EVP_MD_CTX_FLAG_NON_FIPS_ALLOW
);
982 uint64_t total_size
= 0;
983 for (auto& entry
: slo_info
->entries
) {
984 etag_sum
.Update((const unsigned char *)entry
.etag
.c_str(),
985 entry
.etag
.length());
987 /* if size_bytes == 0, it should be replaced with the
988 * real segment size (which could be 0); this follows from the
989 * fact that Swift requires all segments to exist, but permits
990 * the size_bytes element to be omitted from the SLO manifest, see
991 * https://docs.openstack.org/swift/latest/api/large_objects.html
993 r
= update_slo_segment_size(entry
);
998 total_size
+= entry
.size_bytes
;
1000 ldpp_dout(this, 20) << "slo_part: " << entry
.path
1001 << " size=" << entry
.size_bytes
1002 << " etag=" << entry
.etag
1005 complete_etag(etag_sum
, &lo_etag
);
1006 slo_info
->total_size
= total_size
;
1008 ofs
= slo_info
->raw_data
.length();
1011 return RGWPutObj_ObjStore::get_params(y
);
1014 void RGWPutObj_ObjStore_SWIFT::send_response()
1016 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
1021 op_ret
= STATUS_CREATED
;
1023 set_req_state_err(s
, op_ret
);
1026 if (! lo_etag
.empty()) {
1027 /* Static Large Object of Swift API has two etags represented by
1028 * following members:
1029 * - etag - for the manifest itself (it will be stored in xattrs),
1030 * - lo_etag - for the content composited from SLO's segments.
1031 * The value is calculated basing on segments' etags.
1032 * In response for PUT request we have to expose the second one.
1033 * The first one may be obtained by GET with "multipart-manifest=get"
1034 * in query string on a given SLO. */
1035 dump_etag(s
, lo_etag
, true /* quoted */);
1040 dump_last_modified(s
, mtime
);
1041 set_req_state_err(s
, op_ret
);
1043 end_header(s
, this);
1044 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1047 static int get_swift_account_settings(req_state
* const s
,
1048 rgw::sal::Store
* const store
,
1049 RGWAccessControlPolicy_SWIFTAcct
* const policy
,
1050 bool * const has_policy
)
1052 *has_policy
= false;
1054 const char * const acl_attr
= s
->info
.env
->get("HTTP_X_ACCOUNT_ACCESS_CONTROL");
1056 RGWAccessControlPolicy_SWIFTAcct
swift_acct_policy(s
->cct
);
1057 const bool r
= swift_acct_policy
.create(s
, store
,
1059 s
->user
->get_display_name(),
1065 *policy
= swift_acct_policy
;
1072 int RGWPutMetadataAccount_ObjStore_SWIFT::get_params(optional_yield y
)
1074 if (s
->has_bad_meta
) {
1078 int ret
= get_swift_account_settings(s
,
1080 // FIXME: we need to carry unique_ptr in generic class
1081 // and allocate appropriate ACL class in the ctor
1082 static_cast<RGWAccessControlPolicy_SWIFTAcct
*>(&policy
),
1088 get_rmattrs_from_headers(s
, ACCT_PUT_ATTR_PREFIX
, ACCT_REMOVE_ATTR_PREFIX
,
1093 void RGWPutMetadataAccount_ObjStore_SWIFT::send_response()
1095 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
1096 if (meta_ret
!= op_ret
) {
1100 op_ret
= STATUS_NO_CONTENT
;
1102 set_req_state_err(s
, op_ret
);
1106 end_header(s
, this);
1107 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1110 int RGWPutMetadataBucket_ObjStore_SWIFT::get_params(optional_yield y
)
1112 if (s
->has_bad_meta
) {
1116 int r
= get_swift_container_settings(s
, store
, &policy
, &has_policy
,
1117 &policy_rw_mask
, &cors_config
, &has_cors
);
1122 get_rmattrs_from_headers(s
, CONT_PUT_ATTR_PREFIX
, CONT_REMOVE_ATTR_PREFIX
,
1124 placement_rule
.init(s
->info
.env
->get("HTTP_X_STORAGE_POLICY", ""), s
->info
.storage_class
);
1126 return get_swift_versioning_settings(s
, swift_ver_location
);
1129 void RGWPutMetadataBucket_ObjStore_SWIFT::send_response()
1131 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
1132 if (meta_ret
!= op_ret
) {
1135 if (!op_ret
&& (op_ret
!= -EINVAL
)) {
1136 op_ret
= STATUS_NO_CONTENT
;
1138 set_req_state_err(s
, op_ret
);
1142 end_header(s
, this);
1143 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1146 int RGWPutMetadataObject_ObjStore_SWIFT::get_params(optional_yield y
)
1148 if (s
->has_bad_meta
) {
1152 /* Handle Swift object expiration. */
1153 int r
= get_delete_at_param(s
, delete_at
);
1155 ldpp_dout(this, 5) << "ERROR: failed to get Delete-At param" << dendl
;
1159 dlo_manifest
= s
->info
.env
->get("HTTP_X_OBJECT_MANIFEST");
1164 void RGWPutMetadataObject_ObjStore_SWIFT::send_response()
1166 const auto meta_ret
= handle_metadata_errors(s
, op_ret
);
1167 if (meta_ret
!= op_ret
) {
1171 op_ret
= STATUS_ACCEPTED
;
1173 set_req_state_err(s
, op_ret
);
1177 dump_content_length(s
, 0);
1181 end_header(s
, this);
1182 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1185 static void bulkdelete_respond(const unsigned num_deleted
,
1186 const unsigned int num_unfound
,
1187 const std::list
<RGWBulkDelete::fail_desc_t
>& failures
,
1188 const int prot_flags
, /* in */
1189 ceph::Formatter
& formatter
) /* out */
1191 formatter
.open_object_section("delete");
1196 if (!failures
.empty()) {
1197 int reason
= ERR_INVALID_REQUEST
;
1198 for (const auto& fail_desc
: failures
) {
1199 if (-ENOENT
!= fail_desc
.err
&& -EACCES
!= fail_desc
.err
) {
1200 reason
= fail_desc
.err
;
1204 set_req_state_err(err
, reason
, prot_flags
);
1205 dump_errno(err
, resp_status
);
1206 } else if (0 == num_deleted
&& 0 == num_unfound
) {
1207 /* 400 Bad Request */
1208 dump_errno(400, resp_status
);
1209 resp_body
= "Invalid bulk delete.";
1212 dump_errno(200, resp_status
);
1215 encode_json("Number Deleted", num_deleted
, &formatter
);
1216 encode_json("Number Not Found", num_unfound
, &formatter
);
1217 encode_json("Response Body", resp_body
, &formatter
);
1218 encode_json("Response Status", resp_status
, &formatter
);
1220 formatter
.open_array_section("Errors");
1221 for (const auto& fail_desc
: failures
) {
1222 formatter
.open_array_section("object");
1224 stringstream ss_name
;
1225 ss_name
<< fail_desc
.path
;
1226 encode_json("Name", ss_name
.str(), &formatter
);
1229 set_req_state_err(err
, fail_desc
.err
, prot_flags
);
1231 dump_errno(err
, status
);
1232 encode_json("Status", status
, &formatter
);
1233 formatter
.close_section();
1235 formatter
.close_section();
1237 formatter
.close_section();
1240 int RGWDeleteObj_ObjStore_SWIFT::verify_permission(optional_yield y
)
1242 op_ret
= RGWDeleteObj_ObjStore::verify_permission(y
);
1244 /* We have to differentiate error codes depending on whether user is
1245 * anonymous (401 Unauthorized) or he doesn't have necessary permissions
1246 * (403 Forbidden). */
1247 if (s
->auth
.identity
->is_anonymous() && op_ret
== -EACCES
) {
1254 int RGWDeleteObj_ObjStore_SWIFT::get_params(optional_yield y
)
1256 const string
& mm
= s
->info
.args
.get("multipart-manifest");
1257 multipart_delete
= (mm
.compare("delete") == 0);
1259 return RGWDeleteObj_ObjStore::get_params(y
);
1262 void RGWDeleteObj_ObjStore_SWIFT::send_response()
1266 if (multipart_delete
) {
1269 r
= STATUS_NO_CONTENT
;
1272 set_req_state_err(s
, r
);
1275 if (multipart_delete
) {
1276 end_header(s
, this /* RGWOp */, nullptr /* contype */,
1277 CHUNKED_TRANSFER_ENCODING
);
1280 bulkdelete_respond(deleter
->get_num_deleted(),
1281 deleter
->get_num_unfound(),
1282 deleter
->get_failures(),
1285 } else if (-ENOENT
== op_ret
) {
1286 bulkdelete_respond(0, 1, {}, s
->prot_flags
, *s
->formatter
);
1288 RGWBulkDelete::acct_path_t path
;
1289 path
.bucket_name
= s
->bucket_name
;
1290 path
.obj_key
= s
->object
->get_key();
1292 RGWBulkDelete::fail_desc_t fail_desc
;
1293 fail_desc
.err
= op_ret
;
1294 fail_desc
.path
= path
;
1296 bulkdelete_respond(0, 0, { fail_desc
}, s
->prot_flags
, *s
->formatter
);
1299 end_header(s
, this);
1302 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1306 static void get_contype_from_attrs(map
<string
, bufferlist
>& attrs
,
1307 string
& content_type
)
1309 map
<string
, bufferlist
>::iterator iter
= attrs
.find(RGW_ATTR_CONTENT_TYPE
);
1310 if (iter
!= attrs
.end()) {
1311 content_type
= rgw_bl_str(iter
->second
);
1315 static void dump_object_metadata(const DoutPrefixProvider
* dpp
, struct req_state
* const s
,
1316 const map
<string
, bufferlist
>& attrs
)
1318 map
<string
, string
> response_attrs
;
1320 for (auto kv
: attrs
) {
1321 const char * name
= kv
.first
.c_str();
1322 const auto aiter
= rgw_to_http_attrs
.find(name
);
1324 if (aiter
!= std::end(rgw_to_http_attrs
)) {
1325 response_attrs
[aiter
->second
] = rgw_bl_str(kv
.second
);
1326 } else if (strcmp(name
, RGW_ATTR_SLO_UINDICATOR
) == 0) {
1327 // this attr has an extra length prefix from encode() in prior versions
1328 dump_header(s
, "X-Object-Meta-Static-Large-Object", "True");
1329 } else if (strncmp(name
, RGW_ATTR_META_PREFIX
,
1330 sizeof(RGW_ATTR_META_PREFIX
)-1) == 0) {
1331 name
+= sizeof(RGW_ATTR_META_PREFIX
) - 1;
1332 dump_header_prefixed(s
, "X-Object-Meta-",
1333 camelcase_dash_http_attr(name
), kv
.second
);
1337 /* Handle override and fallback for Content-Disposition HTTP header.
1338 * At the moment this will be used only by TempURL of the Swift API. */
1339 const auto cditer
= rgw_to_http_attrs
.find(RGW_ATTR_CONTENT_DISP
);
1340 if (cditer
!= std::end(rgw_to_http_attrs
)) {
1341 const auto& name
= cditer
->second
;
1343 if (!s
->content_disp
.override
.empty()) {
1344 response_attrs
[name
] = s
->content_disp
.override
;
1345 } else if (!s
->content_disp
.fallback
.empty()
1346 && response_attrs
.find(name
) == std::end(response_attrs
)) {
1347 response_attrs
[name
] = s
->content_disp
.fallback
;
1351 for (const auto& kv
: response_attrs
) {
1352 dump_header(s
, kv
.first
, kv
.second
);
1355 const auto iter
= attrs
.find(RGW_ATTR_DELETE_AT
);
1356 if (iter
!= std::end(attrs
)) {
1359 decode(delete_at
, iter
->second
);
1360 if (!delete_at
.is_zero()) {
1361 dump_header(s
, "X-Delete-At", delete_at
.sec());
1363 } catch (buffer::error
& err
) {
1364 ldpp_dout(dpp
, 0) << "ERROR: cannot decode object's " RGW_ATTR_DELETE_AT
1371 int RGWCopyObj_ObjStore_SWIFT::init_dest_policy()
1373 dest_policy
.create_default(s
->user
->get_id(), s
->user
->get_display_name());
1378 int RGWCopyObj_ObjStore_SWIFT::get_params(optional_yield y
)
1380 if_mod
= s
->info
.env
->get("HTTP_IF_MODIFIED_SINCE");
1381 if_unmod
= s
->info
.env
->get("HTTP_IF_UNMODIFIED_SINCE");
1382 if_match
= s
->info
.env
->get("HTTP_COPY_IF_MATCH");
1383 if_nomatch
= s
->info
.env
->get("HTTP_COPY_IF_NONE_MATCH");
1385 src_tenant_name
= s
->src_tenant_name
;
1386 src_bucket_name
= s
->src_bucket_name
;
1387 dest_tenant_name
= s
->bucket_tenant
;
1388 dest_bucket_name
= s
->bucket_name
;
1389 dest_obj_name
= s
->object
->get_name();
1391 const char * const fresh_meta
= s
->info
.env
->get("HTTP_X_FRESH_METADATA");
1392 if (fresh_meta
&& strcasecmp(fresh_meta
, "TRUE") == 0) {
1393 attrs_mod
= rgw::sal::ATTRSMOD_REPLACE
;
1395 attrs_mod
= rgw::sal::ATTRSMOD_MERGE
;
1398 int r
= get_delete_at_param(s
, delete_at
);
1400 ldpp_dout(this, 5) << "ERROR: failed to get Delete-At param" << dendl
;
1407 void RGWCopyObj_ObjStore_SWIFT::send_partial_response(off_t ofs
)
1409 if (! sent_header
) {
1411 op_ret
= STATUS_CREATED
;
1412 set_req_state_err(s
, op_ret
);
1414 end_header(s
, this);
1416 /* Send progress information. Note that this diverge from the original swift
1417 * spec. We do this in order to keep connection alive.
1420 s
->formatter
->open_array_section("progress");
1424 s
->formatter
->dump_int("ofs", (uint64_t)ofs
);
1426 rgw_flush_formatter(s
, s
->formatter
);
1429 void RGWCopyObj_ObjStore_SWIFT::dump_copy_info()
1431 /* Dump X-Copied-From. */
1432 dump_header(s
, "X-Copied-From", url_encode(src_bucket
->get_name()) +
1433 "/" + url_encode(s
->src_object
->get_name()));
1435 /* Dump X-Copied-From-Account. */
1437 dump_header(s
, "X-Copied-From-Account", url_encode(s
->user
->get_id().id
));
1439 /* Dump X-Copied-From-Last-Modified. */
1440 dump_time_header(s
, "X-Copied-From-Last-Modified", src_mtime
);
1443 void RGWCopyObj_ObjStore_SWIFT::send_response()
1445 if (! sent_header
) {
1446 string content_type
;
1448 op_ret
= STATUS_CREATED
;
1449 set_req_state_err(s
, op_ret
);
1452 dump_last_modified(s
, mtime
);
1454 get_contype_from_attrs(attrs
, content_type
);
1455 dump_object_metadata(this, s
, attrs
);
1456 end_header(s
, this, !content_type
.empty() ? content_type
.c_str()
1457 : "binary/octet-stream");
1459 s
->formatter
->close_section();
1460 rgw_flush_formatter(s
, s
->formatter
);
1464 int RGWGetObj_ObjStore_SWIFT::verify_permission(optional_yield y
)
1466 op_ret
= RGWGetObj_ObjStore::verify_permission(y
);
1468 /* We have to differentiate error codes depending on whether user is
1469 * anonymous (401 Unauthorized) or he doesn't have necessary permissions
1470 * (403 Forbidden). */
1471 if (s
->auth
.identity
->is_anonymous() && op_ret
== -EACCES
) {
1478 int RGWGetObj_ObjStore_SWIFT::get_params(optional_yield y
)
1480 const string
& mm
= s
->info
.args
.get("multipart-manifest");
1481 skip_manifest
= (mm
.compare("get") == 0);
1483 return RGWGetObj_ObjStore::get_params(y
);
1486 int RGWGetObj_ObjStore_SWIFT::send_response_data_error(optional_yield y
)
1488 std::string error_content
;
1489 op_ret
= error_handler(op_ret
, &error_content
, y
);
1491 /* The error handler has taken care of the error. */
1495 bufferlist error_bl
;
1496 error_bl
.append(error_content
);
1497 return send_response_data(error_bl
, 0, error_bl
.length());
1500 int RGWGetObj_ObjStore_SWIFT::send_response_data(bufferlist
& bl
,
1504 string content_type
;
1510 if (custom_http_ret
) {
1511 set_req_state_err(s
, 0);
1512 dump_errno(s
, custom_http_ret
);
1514 set_req_state_err(s
, (partial_content
&& !op_ret
) ? STATUS_PARTIAL_CONTENT
1519 end_header(s
, NULL
);
1525 dump_range(s
, ofs
, end
, s
->obj_size
);
1529 end_header(s
, NULL
);
1533 dump_content_length(s
, total_len
);
1534 dump_last_modified(s
, lastmod
);
1535 dump_header(s
, "X-Timestamp", utime_t(lastmod
));
1537 dump_header(s
, "X-Static-Large-Object", "True");
1541 if (! lo_etag
.empty()) {
1542 dump_etag(s
, lo_etag
, true /* quoted */);
1544 auto iter
= attrs
.find(RGW_ATTR_ETAG
);
1545 if (iter
!= attrs
.end()) {
1546 dump_etag(s
, iter
->second
.to_str());
1550 get_contype_from_attrs(attrs
, content_type
);
1551 dump_object_metadata(this, s
, attrs
);
1554 end_header(s
, this, !content_type
.empty() ? content_type
.c_str()
1555 : "binary/octet-stream");
1560 if (get_data
&& !op_ret
) {
1561 const auto r
= dump_body(s
, bl
.c_str() + bl_ofs
, bl_len
);
1566 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1571 void RGWOptionsCORS_ObjStore_SWIFT::send_response()
1573 string hdrs
, exp_hdrs
;
1574 uint32_t max_age
= CORS_MAX_AGE_INVALID
;
1575 /*EACCES means, there is no CORS registered yet for the bucket
1576 *ENOENT means, there is no match of the Origin in the list of CORSRule
1578 if (op_ret
== -ENOENT
)
1581 set_req_state_err(s
, op_ret
);
1583 end_header(s
, NULL
);
1586 get_response_params(hdrs
, exp_hdrs
, &max_age
);
1588 dump_access_control(s
, origin
, req_meth
, hdrs
.c_str(), exp_hdrs
.c_str(),
1590 end_header(s
, NULL
);
1593 int RGWBulkDelete_ObjStore_SWIFT::get_data(
1594 list
<RGWBulkDelete::acct_path_t
>& items
, bool * const is_truncated
)
1596 constexpr size_t MAX_LINE_SIZE
= 2048;
1598 RGWClientIOStreamBuf
ciosb(static_cast<RGWRestfulIO
&>(*(s
->cio
)),
1599 size_t(s
->cct
->_conf
->rgw_max_chunk_size
));
1600 istream
cioin(&ciosb
);
1602 char buf
[MAX_LINE_SIZE
];
1603 while (cioin
.getline(buf
, sizeof(buf
))) {
1604 string
path_str(buf
);
1606 ldpp_dout(this, 20) << "extracted Bulk Delete entry: " << path_str
<< dendl
;
1608 RGWBulkDelete::acct_path_t path
;
1610 /* We need to skip all slashes at the beginning in order to preserve
1611 * compliance with Swift. */
1612 const size_t start_pos
= path_str
.find_first_not_of('/');
1614 if (string::npos
!= start_pos
) {
1615 /* Seperator is the first slash after the leading ones. */
1616 const size_t sep_pos
= path_str
.find('/', start_pos
);
1618 if (string::npos
!= sep_pos
) {
1619 path
.bucket_name
= url_decode(path_str
.substr(start_pos
,
1620 sep_pos
- start_pos
));
1621 path
.obj_key
= url_decode(path_str
.substr(sep_pos
+ 1));
1623 /* It's guaranteed here that bucket name is at least one character
1624 * long and is different than slash. */
1625 path
.bucket_name
= url_decode(path_str
.substr(start_pos
));
1628 items
.push_back(path
);
1631 if (items
.size() == MAX_CHUNK_ENTRIES
) {
1632 *is_truncated
= true;
1637 *is_truncated
= false;
1641 void RGWBulkDelete_ObjStore_SWIFT::send_response()
1643 set_req_state_err(s
, op_ret
);
1645 end_header(s
, this /* RGWOp */, nullptr /* contype */,
1646 CHUNKED_TRANSFER_ENCODING
);
1648 bulkdelete_respond(deleter
->get_num_deleted(),
1649 deleter
->get_num_unfound(),
1650 deleter
->get_failures(),
1653 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1657 std::unique_ptr
<RGWBulkUploadOp::StreamGetter
>
1658 RGWBulkUploadOp_ObjStore_SWIFT::create_stream()
1660 class SwiftStreamGetter
: public StreamGetter
{
1661 const DoutPrefixProvider
* dpp
;
1662 const size_t conlen
;
1667 SwiftStreamGetter(const DoutPrefixProvider
* dpp
, req_state
* const s
, const size_t conlen
)
1674 ssize_t
get_at_most(size_t want
, ceph::bufferlist
& dst
) override
{
1675 /* maximum requested by a caller */
1676 /* data provided by client */
1677 /* RadosGW's limit. */
1678 const size_t max_chunk_size
= \
1679 static_cast<size_t>(s
->cct
->_conf
->rgw_max_chunk_size
);
1680 const size_t max_to_read
= std::min({ want
, conlen
- curpos
, max_chunk_size
});
1682 ldpp_dout(dpp
, 20) << "bulk_upload: get_at_most max_to_read="
1684 << ", dst.c_str()=" << reinterpret_cast<intptr_t>(dst
.c_str()) << dendl
;
1686 bufferptr
bp(max_to_read
);
1687 const auto read_len
= recv_body(s
, bp
.c_str(), max_to_read
);
1688 dst
.append(bp
, 0, read_len
);
1689 //const auto read_len = recv_body(s, dst.c_str(), max_to_read);
1695 return curpos
> s
->cct
->_conf
->rgw_max_put_size
? -ERR_TOO_LARGE
1699 ssize_t
get_exactly(size_t want
, ceph::bufferlist
& dst
) override
{
1700 ldpp_dout(dpp
, 20) << "bulk_upload: get_exactly want=" << want
<< dendl
;
1702 /* FIXME: do this in a loop. */
1703 const auto ret
= get_at_most(want
, dst
);
1704 ldpp_dout(dpp
, 20) << "bulk_upload: get_exactly ret=" << ret
<< dendl
;
1707 } else if (static_cast<size_t>(ret
) != want
) {
1719 ldpp_dout(this, 20) << "bulk upload: create_stream for length="
1720 << s
->length
<< dendl
;
1722 const size_t conlen
= atoll(s
->length
);
1723 return std::unique_ptr
<SwiftStreamGetter
>(new SwiftStreamGetter(this, s
, conlen
));
1727 void RGWBulkUploadOp_ObjStore_SWIFT::send_response()
1729 set_req_state_err(s
, op_ret
);
1731 end_header(s
, this /* RGWOp */, nullptr /* contype */,
1732 CHUNKED_TRANSFER_ENCODING
);
1733 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1735 s
->formatter
->open_object_section("delete");
1737 std::string resp_status
;
1738 std::string resp_body
;
1740 if (! failures
.empty()) {
1743 const auto last_err
= { failures
.back().err
};
1744 if (boost::algorithm::contains(last_err
, terminal_errors
)) {
1745 /* The terminal errors are affecting the status of the whole upload. */
1746 set_req_state_err(err
, failures
.back().err
, s
->prot_flags
);
1748 set_req_state_err(err
, ERR_INVALID_REQUEST
, s
->prot_flags
);
1751 dump_errno(err
, resp_status
);
1752 } else if (0 == num_created
&& failures
.empty()) {
1753 /* Nothing created, nothing failed. This means the archive contained no
1754 * entity we could understand (regular file or directory). We need to
1755 * send 400 Bad Request to an HTTP client in the internal status field. */
1756 dump_errno(400, resp_status
);
1757 resp_body
= "Invalid Tar File: No Valid Files";
1760 dump_errno(201, resp_status
);
1763 encode_json("Number Files Created", num_created
, s
->formatter
);
1764 encode_json("Response Body", resp_body
, s
->formatter
);
1765 encode_json("Response Status", resp_status
, s
->formatter
);
1767 s
->formatter
->open_array_section("Errors");
1768 for (const auto& fail_desc
: failures
) {
1769 s
->formatter
->open_array_section("object");
1771 encode_json("Name", fail_desc
.path
, s
->formatter
);
1774 set_req_state_err(err
, fail_desc
.err
, s
->prot_flags
);
1776 dump_errno(err
, status
);
1777 encode_json("Status", status
, s
->formatter
);
1779 s
->formatter
->close_section();
1781 s
->formatter
->close_section();
1783 s
->formatter
->close_section();
1784 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1788 void RGWGetCrossDomainPolicy_ObjStore_SWIFT::send_response()
1790 set_req_state_err(s
, op_ret
);
1792 end_header(s
, this, "application/xml");
1794 std::stringstream ss
;
1796 ss
<< R
"(<?xml version="1.0"?>)" << "\n"
1797 << R
"(<!DOCTYPE cross-domain-policy SYSTEM )"
1798 << R
"("http
://www.adobe.com/xml/dtds/cross-domain-policy.dtd" >)" << "\n"
1799 << R
"(<cross-domain-policy>)" << "\n"
1800 << g_conf()->rgw_cross_domain_policy
<< "\n"
1801 << R
"(</cross-domain-policy>)";
1803 dump_body(s
, ss
.str());
1806 void RGWGetHealthCheck_ObjStore_SWIFT::send_response()
1808 set_req_state_err(s
, op_ret
);
1810 end_header(s
, this, "application/xml");
1813 static constexpr char DISABLED
[] = "DISABLED BY FILE";
1814 dump_body(s
, DISABLED
, strlen(DISABLED
));
1818 const vector
<pair
<string
, RGWInfo_ObjStore_SWIFT::info
>> RGWInfo_ObjStore_SWIFT::swift_info
=
1820 {"bulk_delete", {false, nullptr}},
1821 {"container_quotas", {false, nullptr}},
1822 {"swift", {false, RGWInfo_ObjStore_SWIFT::list_swift_data
}},
1823 {"tempurl", { false, RGWInfo_ObjStore_SWIFT::list_tempurl_data
}},
1824 {"slo", {false, RGWInfo_ObjStore_SWIFT::list_slo_data
}},
1825 {"account_quotas", {false, nullptr}},
1826 {"staticweb", {false, nullptr}},
1827 {"tempauth", {false, RGWInfo_ObjStore_SWIFT::list_tempauth_data
}},
1830 void RGWInfo_ObjStore_SWIFT::execute(optional_yield y
)
1832 bool is_admin_info_enabled
= false;
1834 const string
& swiftinfo_sig
= s
->info
.args
.get("swiftinfo_sig");
1835 const string
& swiftinfo_expires
= s
->info
.args
.get("swiftinfo_expires");
1837 if (!swiftinfo_sig
.empty() &&
1838 !swiftinfo_expires
.empty() &&
1839 !is_expired(swiftinfo_expires
, this)) {
1840 is_admin_info_enabled
= true;
1843 s
->formatter
->open_object_section("info");
1845 for (const auto& pair
: swift_info
) {
1846 if(!is_admin_info_enabled
&& pair
.second
.is_admin_info
)
1849 if (!pair
.second
.list_data
) {
1850 s
->formatter
->open_object_section((pair
.first
).c_str());
1851 s
->formatter
->close_section();
1854 pair
.second
.list_data(*(s
->formatter
), s
->cct
->_conf
, store
);
1858 s
->formatter
->close_section();
1861 void RGWInfo_ObjStore_SWIFT::send_response()
1864 op_ret
= STATUS_NO_CONTENT
;
1866 set_req_state_err(s
, op_ret
);
1868 end_header(s
, this);
1869 rgw_flush_formatter_and_reset(s
, s
->formatter
);
1872 void RGWInfo_ObjStore_SWIFT::list_swift_data(Formatter
& formatter
,
1873 const ConfigProxy
& config
,
1874 rgw::sal::Store
* store
)
1876 formatter
.open_object_section("swift");
1877 formatter
.dump_int("max_file_size", config
->rgw_max_put_size
);
1878 formatter
.dump_int("container_listing_limit", RGW_LIST_BUCKETS_LIMIT_MAX
);
1880 string
ceph_version(CEPH_GIT_NICE_VER
);
1881 formatter
.dump_string("version", ceph_version
);
1883 const size_t max_attr_name_len
= \
1884 g_conf().get_val
<Option::size_t>("rgw_max_attr_name_len");
1885 if (max_attr_name_len
) {
1886 const size_t meta_name_limit
= \
1887 max_attr_name_len
- strlen(RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX
);
1888 formatter
.dump_int("max_meta_name_length", meta_name_limit
);
1891 const size_t meta_value_limit
= g_conf().get_val
<Option::size_t>("rgw_max_attr_size");
1892 if (meta_value_limit
) {
1893 formatter
.dump_int("max_meta_value_length", meta_value_limit
);
1896 const size_t meta_num_limit
= \
1897 g_conf().get_val
<uint64_t>("rgw_max_attrs_num_in_req");
1898 if (meta_num_limit
) {
1899 formatter
.dump_int("max_meta_count", meta_num_limit
);
1902 formatter
.open_array_section("policies");
1903 const RGWZoneGroup
& zonegroup
= store
->get_zone()->get_zonegroup();
1905 for (const auto& placement_targets
: zonegroup
.placement_targets
) {
1906 formatter
.open_object_section("policy");
1907 if (placement_targets
.second
.name
.compare(zonegroup
.default_placement
.name
) == 0)
1908 formatter
.dump_bool("default", true);
1909 formatter
.dump_string("name", placement_targets
.second
.name
.c_str());
1910 formatter
.close_section();
1912 formatter
.close_section();
1914 formatter
.dump_int("max_object_name_size", RGWHandler_REST::MAX_OBJ_NAME_LEN
);
1915 formatter
.dump_bool("strict_cors_mode", true);
1916 formatter
.dump_int("max_container_name_length", RGWHandler_REST::MAX_BUCKET_NAME_LEN
);
1917 formatter
.close_section();
1920 void RGWInfo_ObjStore_SWIFT::list_tempauth_data(Formatter
& formatter
,
1921 const ConfigProxy
& config
,
1922 rgw::sal::Store
* store
)
1924 formatter
.open_object_section("tempauth");
1925 formatter
.dump_bool("account_acls", true);
1926 formatter
.close_section();
1928 void RGWInfo_ObjStore_SWIFT::list_tempurl_data(Formatter
& formatter
,
1929 const ConfigProxy
& config
,
1930 rgw::sal::Store
* store
)
1932 formatter
.open_object_section("tempurl");
1933 formatter
.open_array_section("methods");
1934 formatter
.dump_string("methodname", "GET");
1935 formatter
.dump_string("methodname", "HEAD");
1936 formatter
.dump_string("methodname", "PUT");
1937 formatter
.dump_string("methodname", "POST");
1938 formatter
.dump_string("methodname", "DELETE");
1939 formatter
.close_section();
1940 formatter
.close_section();
1943 void RGWInfo_ObjStore_SWIFT::list_slo_data(Formatter
& formatter
,
1944 const ConfigProxy
& config
,
1945 rgw::sal::Store
* store
)
1947 formatter
.open_object_section("slo");
1948 formatter
.dump_int("max_manifest_segments", config
->rgw_max_slo_entries
);
1949 formatter
.close_section();
1952 bool RGWInfo_ObjStore_SWIFT::is_expired(const std::string
& expires
, const DoutPrefixProvider
*dpp
)
1955 const utime_t now
= ceph_clock_now();
1956 const uint64_t expiration
= (uint64_t)strict_strtoll(expires
.c_str(),
1959 ldpp_dout(dpp
, 5) << "failed to parse siginfo_expires: " << err
<< dendl
;
1963 if (expiration
<= (uint64_t)now
.sec()) {
1964 ldpp_dout(dpp
, 5) << "siginfo expired: " << expiration
<< " <= " << now
.sec() << dendl
;
1972 void RGWFormPost::init(rgw::sal::Store
* const store
,
1974 RGWHandler
* const dialect_handler
)
1976 prefix
= std::move(s
->object
->get_name());
1977 s
->object
->set_key(rgw_obj_key());
1979 return RGWPostObj_ObjStore::init(store
, s
, dialect_handler
);
1982 std::size_t RGWFormPost::get_max_file_size() /*const*/
1984 std::string max_str
= get_part_str(ctrl_parts
, "max_file_size", "0");
1987 const std::size_t max_file_size
=
1988 static_cast<uint64_t>(strict_strtoll(max_str
.c_str(), 10, &err
));
1990 if (! err
.empty()) {
1991 ldpp_dout(this, 5) << "failed to parse FormPost's max_file_size: " << err
1996 return max_file_size
;
1999 bool RGWFormPost::is_non_expired()
2001 std::string expires
= get_part_str(ctrl_parts
, "expires", "0");
2004 const uint64_t expires_timestamp
=
2005 static_cast<uint64_t>(strict_strtoll(expires
.c_str(), 10, &err
));
2007 if (! err
.empty()) {
2008 ldpp_dout(this, 5) << "failed to parse FormPost's expires: " << err
<< dendl
;
2012 const utime_t now
= ceph_clock_now();
2013 if (expires_timestamp
<= static_cast<uint64_t>(now
.sec())) {
2014 ldpp_dout(this, 5) << "FormPost form expired: "
2015 << expires_timestamp
<< " <= " << now
.sec() << dendl
;
2022 bool RGWFormPost::is_integral()
2024 const std::string form_signature
= get_part_str(ctrl_parts
, "signature");
2027 get_owner_info(s
, s
->user
->get_info());
2028 s
->auth
.identity
= rgw::auth::transform_old_authinfo(s
);
2030 ldpp_dout(this, 5) << "cannot get user_info of account's owner" << dendl
;
2034 for (const auto& kv
: s
->user
->get_info().temp_url_keys
) {
2035 const int temp_url_key_num
= kv
.first
;
2036 const string
& temp_url_key
= kv
.second
;
2038 if (temp_url_key
.empty()) {
2042 SignatureHelper sig_helper
;
2043 sig_helper
.calc(temp_url_key
,
2044 s
->info
.request_uri
,
2045 get_part_str(ctrl_parts
, "redirect"),
2046 get_part_str(ctrl_parts
, "max_file_size", "0"),
2047 get_part_str(ctrl_parts
, "max_file_count", "0"),
2048 get_part_str(ctrl_parts
, "expires", "0"));
2050 const auto local_sig
= sig_helper
.get_signature();
2052 ldpp_dout(this, 20) << "FormPost signature [" << temp_url_key_num
<< "]"
2053 << " (calculated): " << local_sig
<< dendl
;
2055 if (sig_helper
.is_equal_to(form_signature
)) {
2058 ldpp_dout(this, 5) << "FormPost's signature mismatch: "
2059 << local_sig
<< " != " << form_signature
<< dendl
;
2066 void RGWFormPost::get_owner_info(const req_state
* const s
,
2067 RGWUserInfo
& owner_info
) const
2069 /* We cannot use req_state::bucket_name because it isn't available
2070 * now. It will be initialized in RGWHandler_REST_SWIFT::postauth_init(). */
2071 const string
& bucket_name
= s
->init_state
.url_bucket
;
2073 std::unique_ptr
<rgw::sal::User
> user
;
2075 /* TempURL in Formpost only requires that bucket name is specified. */
2076 if (bucket_name
.empty()) {
2080 if (!s
->account_name
.empty()) {
2084 const rgw_user
uid(s
->account_name
);
2085 if (uid
.tenant
.empty()) {
2086 const rgw_user
tenanted_uid(uid
.id
, uid
.id
);
2087 user
= store
->get_user(tenanted_uid
);
2089 if (user
->load_user(s
, s
->yield
) >= 0) {
2096 user
= store
->get_user(uid
);
2097 if (user
->load_user(s
, s
->yield
) < 0) {
2103 /* Need to get user info of bucket owner. */
2104 std::unique_ptr
<rgw::sal::Bucket
> bucket
;
2105 int ret
= store
->get_bucket(s
, user
.get(), user
->get_tenant(), bucket_name
, &bucket
, s
->yield
);
2110 ldpp_dout(this, 20) << "temp url user (bucket owner): " << bucket
->get_info().owner
2113 user
= store
->get_user(bucket
->get_info().owner
);
2114 if (user
->load_user(s
, s
->yield
) < 0) {
2118 owner_info
= user
->get_info();
2121 int RGWFormPost::get_params(optional_yield y
)
2123 /* The parentt class extracts boundary info from the Content-Type. */
2124 int ret
= RGWPostObj_ObjStore::get_params(y
);
2129 policy
.create_default(s
->user
->get_id(), s
->user
->get_display_name());
2131 /* Let's start parsing the HTTP body by parsing each form part step-
2132 * by-step till encountering the first part with file data. */
2134 struct post_form_part part
;
2135 ret
= read_form_part_header(&part
, stream_done
);
2140 if (s
->cct
->_conf
->subsys
.should_gather
<ceph_subsys_rgw
, 20>()) {
2141 ldpp_dout(this, 20) << "read part header -- part.name="
2142 << part
.name
<< dendl
;
2144 for (const auto& pair
: part
.fields
) {
2145 ldpp_dout(this, 20) << "field.name=" << pair
.first
<< dendl
;
2146 ldpp_dout(this, 20) << "field.val=" << pair
.second
.val
<< dendl
;
2147 ldpp_dout(this, 20) << "field.params:" << dendl
;
2149 for (const auto& param_pair
: pair
.second
.params
) {
2150 ldpp_dout(this, 20) << " " << param_pair
.first
2151 << " -> " << param_pair
.second
<< dendl
;
2157 /* Unexpected here. */
2158 err_msg
= "Malformed request";
2162 const auto field_iter
= part
.fields
.find("Content-Disposition");
2163 if (std::end(part
.fields
) != field_iter
&&
2164 std::end(field_iter
->second
.params
) != field_iter
->second
.params
.find("filename")) {
2165 /* First data part ahead. */
2166 current_data_part
= std::move(part
);
2168 /* Stop the iteration. We can assume that all control parts have been
2169 * already parsed. The rest of HTTP body should contain data parts
2170 * only. They will be picked up by ::get_data(). */
2173 /* Control part ahead. Receive, parse and store for later usage. */
2175 ret
= read_data(part
.data
, s
->cct
->_conf
->rgw_max_chunk_size
,
2176 boundary
, stream_done
);
2179 } else if (! boundary
) {
2180 err_msg
= "Couldn't find boundary";
2184 ctrl_parts
[part
.name
] = std::move(part
);
2186 } while (! stream_done
);
2189 max_len
= get_max_file_size();
2191 if (! current_data_part
) {
2192 err_msg
= "FormPost: no files to process";
2196 if (! is_non_expired()) {
2197 err_msg
= "FormPost: Form Expired";
2201 if (! is_integral()) {
2202 err_msg
= "FormPost: Invalid Signature";
2209 std::string
RGWFormPost::get_current_filename() const
2212 const auto& field
= current_data_part
->fields
.at("Content-Disposition");
2213 const auto iter
= field
.params
.find("filename");
2215 if (std::end(field
.params
) != iter
) {
2216 return prefix
+ iter
->second
;
2218 } catch (std::out_of_range
&) {
2225 std::string
RGWFormPost::get_current_content_type() const
2228 const auto& field
= current_data_part
->fields
.at("Content-Type");
2230 } catch (std::out_of_range
&) {
2234 return std::string();
2237 bool RGWFormPost::is_next_file_to_upload()
2239 if (! stream_done
) {
2240 /* We have at least one additional part in the body. */
2241 struct post_form_part part
;
2242 int r
= read_form_part_header(&part
, stream_done
);
2247 const auto field_iter
= part
.fields
.find("Content-Disposition");
2248 if (std::end(part
.fields
) != field_iter
) {
2249 const auto& params
= field_iter
->second
.params
;
2250 const auto& filename_iter
= params
.find("filename");
2252 if (std::end(params
) != filename_iter
&& ! filename_iter
->second
.empty()) {
2253 current_data_part
= std::move(part
);
2262 int RGWFormPost::get_data(ceph::bufferlist
& bl
, bool& again
)
2266 int r
= read_data(bl
, s
->cct
->_conf
->rgw_max_chunk_size
,
2267 boundary
, stream_done
);
2272 /* Tell RGWPostObj::execute(optional_yield y) that it has some data to put. */
2278 void RGWFormPost::send_response()
2280 std::string redirect
= get_part_str(ctrl_parts
, "redirect");
2281 if (! redirect
.empty()) {
2282 op_ret
= STATUS_REDIRECT
;
2285 set_req_state_err(s
, op_ret
);
2286 s
->err
.err_code
= err_msg
;
2288 if (! redirect
.empty()) {
2289 dump_redirect(s
, redirect
);
2291 end_header(s
, this);
2294 bool RGWFormPost::is_formpost_req(req_state
* const s
)
2296 std::string content_type
;
2297 std::map
<std::string
, std::string
> params
;
2299 parse_boundary_params(s
->info
.env
->get("CONTENT_TYPE", ""),
2300 content_type
, params
);
2302 return boost::algorithm::iequals(content_type
, "multipart/form-data") &&
2303 params
.count("boundary") > 0;
2307 RGWOp
*RGWHandler_REST_Service_SWIFT::op_get()
2309 return new RGWListBuckets_ObjStore_SWIFT
;
2312 RGWOp
*RGWHandler_REST_Service_SWIFT::op_head()
2314 return new RGWStatAccount_ObjStore_SWIFT
;
2317 RGWOp
*RGWHandler_REST_Service_SWIFT::op_put()
2319 if (s
->info
.args
.exists("extract-archive")) {
2320 return new RGWBulkUploadOp_ObjStore_SWIFT
;
2325 RGWOp
*RGWHandler_REST_Service_SWIFT::op_post()
2327 if (s
->info
.args
.exists("bulk-delete")) {
2328 return new RGWBulkDelete_ObjStore_SWIFT
;
2330 return new RGWPutMetadataAccount_ObjStore_SWIFT
;
2333 RGWOp
*RGWHandler_REST_Service_SWIFT::op_delete()
2335 if (s
->info
.args
.exists("bulk-delete")) {
2336 return new RGWBulkDelete_ObjStore_SWIFT
;
2341 int RGWSwiftWebsiteHandler::serve_errordoc(const int http_ret
,
2342 const std::string error_doc
,
2345 /* Try to throw it all away. */
2346 s
->formatter
->reset();
2348 class RGWGetErrorPage
: public RGWGetObj_ObjStore_SWIFT
{
2350 RGWGetErrorPage(rgw::sal::Store
* const store
,
2351 RGWHandler_REST
* const handler
,
2353 const int http_ret
) {
2354 /* Calling a virtual from the base class is safe as the subobject should
2355 * be properly initialized and we haven't overridden the init method. */
2356 init(store
, s
, handler
);
2358 set_custom_http_response(http_ret
);
2361 int error_handler(const int err_no
,
2362 std::string
* const error_content
, optional_yield y
) override
{
2363 /* Enforce that any error generated while getting the error page will
2364 * not be send to a client. This allows us to recover from the double
2365 * fault situation by sending the original message. */
2368 } get_errpage_op(store
, handler
, s
, http_ret
);
2370 /* This is okay. It's an error, so nothing will run after this, and it can be
2371 * called by abort_early(), which can be called before s->object or s->bucket
2373 if (!rgw::sal::Bucket::empty(s
->bucket
.get())) {
2374 s
->object
= s
->bucket
->get_object(rgw_obj_key(std::to_string(http_ret
) + error_doc
));
2376 s
->object
= store
->get_object(rgw_obj_key(std::to_string(http_ret
) + error_doc
));
2379 RGWOp
* newop
= &get_errpage_op
;
2381 return rgw_process_authenticated(handler
, newop
, &req
, s
, y
, store
, true);
2384 int RGWSwiftWebsiteHandler::error_handler(const int err_no
,
2385 std::string
* const error_content
,
2388 if (!s
->bucket
.get()) {
2389 /* No bucket, default no-op handler */
2393 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2395 if (can_be_website_req() && ! ws_conf
.error_doc
.empty()) {
2396 set_req_state_err(s
, err_no
);
2397 return serve_errordoc(s
->err
.http_ret
, ws_conf
.error_doc
, y
);
2400 /* Let's go to the default, no-op handler. */
2404 bool RGWSwiftWebsiteHandler::is_web_mode() const
2406 const std::string_view webmode
= s
->info
.env
->get("HTTP_X_WEB_MODE", "");
2407 return boost::algorithm::iequals(webmode
, "true");
2410 bool RGWSwiftWebsiteHandler::can_be_website_req() const
2412 /* Static website works only with the GET or HEAD method. Nothing more. */
2413 static const std::set
<std::string_view
> ws_methods
= { "GET", "HEAD" };
2414 if (ws_methods
.count(s
->info
.method
) == 0) {
2418 /* We also need to handle early failures from the auth system. In such cases
2419 * req_state::auth.identity may be empty. Let's treat that the same way as
2420 * the anonymous access. */
2421 if (! s
->auth
.identity
) {
2425 /* Swift serves websites only for anonymous requests unless client explicitly
2426 * requested this behaviour by supplying X-Web-Mode HTTP header set to true. */
2427 if (s
->auth
.identity
->is_anonymous() || is_web_mode()) {
2434 RGWOp
* RGWSwiftWebsiteHandler::get_ws_redirect_op()
2436 class RGWMovedPermanently
: public RGWOp
{
2437 const std::string location
;
2439 explicit RGWMovedPermanently(const std::string
& location
)
2440 : location(location
) {
2443 int verify_permission(optional_yield
) override
{
2447 void execute(optional_yield
) override
{
2448 op_ret
= -ERR_PERMANENT_REDIRECT
;
2452 void send_response() override
{
2453 set_req_state_err(s
, op_ret
);
2455 dump_content_length(s
, 0);
2456 dump_redirect(s
, location
);
2457 end_header(s
, this);
2460 const char* name() const override
{
2461 return "RGWMovedPermanently";
2465 return new RGWMovedPermanently(s
->info
.request_uri
+ '/');
2468 RGWOp
* RGWSwiftWebsiteHandler::get_ws_index_op()
2470 /* Retarget to get obj on requested index file. */
2471 if (! s
->object
->empty()) {
2472 s
->object
->set_name(s
->object
->get_name() +
2473 s
->bucket
->get_info().website_conf
.get_index_doc());
2475 s
->object
->set_name(s
->bucket
->get_info().website_conf
.get_index_doc());
2478 auto getop
= new RGWGetObj_ObjStore_SWIFT
;
2479 getop
->set_get_data(boost::algorithm::equals("GET", s
->info
.method
));
2484 RGWOp
* RGWSwiftWebsiteHandler::get_ws_listing_op()
2486 class RGWWebsiteListing
: public RGWListBucket_ObjStore_SWIFT
{
2487 const std::string prefix_override
;
2489 int get_params(optional_yield
) override
{
2490 prefix
= prefix_override
;
2496 void send_response() override
{
2497 /* Generate the header now. */
2498 set_req_state_err(s
, op_ret
);
2500 dump_container_metadata(s
, s
->bucket
.get(), bucket_quota
,
2501 s
->bucket
->get_info().website_conf
);
2502 end_header(s
, this, "text/html");
2507 /* Now it's the time to start generating HTML bucket listing.
2508 * All the crazy stuff with crafting tags will be delegated to
2509 * RGWSwiftWebsiteListingFormatter. */
2510 std::stringstream ss
;
2511 RGWSwiftWebsiteListingFormatter
htmler(ss
, prefix
);
2513 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2514 htmler
.generate_header(s
->decoded_uri
,
2515 ws_conf
.listing_css_doc
);
2517 for (const auto& pair
: common_prefixes
) {
2518 std::string subdir_name
= pair
.first
;
2519 if (! subdir_name
.empty()) {
2520 /* To be compliant with Swift we need to remove the trailing
2522 subdir_name
.pop_back();
2525 htmler
.dump_subdir(subdir_name
);
2528 for (const rgw_bucket_dir_entry
& obj
: objs
) {
2529 if (! common_prefixes
.count(obj
.key
.name
+ '/')) {
2530 htmler
.dump_object(obj
);
2534 htmler
.generate_footer();
2535 dump_body(s
, ss
.str());
2538 /* Taking prefix_override by value to leverage std::string r-value ref
2539 * ctor and thus avoid extra memory copying/increasing ref counter. */
2540 explicit RGWWebsiteListing(std::string prefix_override
)
2541 : prefix_override(std::move(prefix_override
)) {
2545 std::string prefix
= std::move(s
->object
->get_name());
2546 s
->object
->set_key(rgw_obj_key());
2548 return new RGWWebsiteListing(std::move(prefix
));
2551 bool RGWSwiftWebsiteHandler::is_web_dir() const
2553 std::string subdir_name
= url_decode(s
->object
->get_name());
2555 /* Remove character from the subdir name if it is "/". */
2556 if (subdir_name
.empty()) {
2558 } else if (subdir_name
.back() == '/') {
2559 subdir_name
.pop_back();
2560 if (subdir_name
.empty()) {
2565 std::unique_ptr
<rgw::sal::Object
> obj
= s
->bucket
->get_object(rgw_obj_key(std::move(subdir_name
)));
2567 /* First, get attrset of the object we'll try to retrieve. */
2568 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2569 obj
->set_atomic(&obj_ctx
);
2570 obj
->set_prefetch_data(&obj_ctx
);
2572 RGWObjState
* state
= nullptr;
2573 if (obj
->get_obj_state(s
, &obj_ctx
, &state
, s
->yield
, false)) {
2577 /* A nonexistent object cannot be a considered as a marker representing
2578 * the emulation of catalog in FS hierarchy. */
2579 if (! state
->exists
) {
2583 /* Decode the content type. */
2584 std::string content_type
;
2585 get_contype_from_attrs(state
->attrset
, content_type
);
2587 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2588 const std::string subdir_marker
= ws_conf
.subdir_marker
.empty()
2589 ? "application/directory"
2590 : ws_conf
.subdir_marker
;
2591 return subdir_marker
== content_type
&& state
->size
<= 1;
2594 bool RGWSwiftWebsiteHandler::is_index_present(const std::string
& index
) const
2596 std::unique_ptr
<rgw::sal::Object
> obj
= s
->bucket
->get_object(rgw_obj_key(index
));
2598 RGWObjectCtx
& obj_ctx
= *static_cast<RGWObjectCtx
*>(s
->obj_ctx
);
2599 obj
->set_atomic(&obj_ctx
);
2600 obj
->set_prefetch_data(&obj_ctx
);
2602 RGWObjState
* state
= nullptr;
2603 if (obj
->get_obj_state(s
, &obj_ctx
, &state
, s
->yield
, false)) {
2607 /* A nonexistent object cannot be a considered as a viable index. We will
2608 * try to list the bucket or - if this is impossible - return an error. */
2609 return state
->exists
;
2612 int RGWSwiftWebsiteHandler::retarget_bucket(RGWOp
* op
, RGWOp
** new_op
)
2614 ldpp_dout(s
, 10) << "Starting retarget" << dendl
;
2615 RGWOp
* op_override
= nullptr;
2617 /* In Swift static web content is served if the request is anonymous or
2618 * has X-Web-Mode HTTP header specified to true. */
2619 if (can_be_website_req()) {
2620 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2621 const auto& index
= s
->bucket
->get_info().website_conf
.get_index_doc();
2623 if (s
->decoded_uri
.back() != '/') {
2624 op_override
= get_ws_redirect_op();
2625 } else if (! index
.empty() && is_index_present(index
)) {
2626 op_override
= get_ws_index_op();
2627 } else if (ws_conf
.listing_enabled
) {
2628 op_override
= get_ws_listing_op();
2633 handler
->put_op(op
);
2634 op_override
->init(store
, s
, handler
);
2636 *new_op
= op_override
;
2641 /* Return 404 Not Found is the request has web mode enforced but we static web
2642 * wasn't able to serve it accordingly. */
2643 return ! op_override
&& is_web_mode() ? -ENOENT
: 0;
2646 int RGWSwiftWebsiteHandler::retarget_object(RGWOp
* op
, RGWOp
** new_op
)
2648 ldpp_dout(s
, 10) << "Starting object retarget" << dendl
;
2649 RGWOp
* op_override
= nullptr;
2651 /* In Swift static web content is served if the request is anonymous or
2652 * has X-Web-Mode HTTP header specified to true. */
2653 if (can_be_website_req() && is_web_dir()) {
2654 const auto& ws_conf
= s
->bucket
->get_info().website_conf
;
2655 const auto& index
= s
->bucket
->get_info().website_conf
.get_index_doc();
2657 if (s
->decoded_uri
.back() != '/') {
2658 op_override
= get_ws_redirect_op();
2659 } else if (! index
.empty() && is_index_present(index
)) {
2660 op_override
= get_ws_index_op();
2661 } else if (ws_conf
.listing_enabled
) {
2662 op_override
= get_ws_listing_op();
2665 /* A regular request or the specified object isn't a subdirectory marker.
2666 * We don't need any re-targeting. Error handling (like sending a custom
2667 * error page) will be performed by error_handler of the actual RGWOp. */
2672 handler
->put_op(op
);
2673 op_override
->init(store
, s
, handler
);
2675 *new_op
= op_override
;
2680 /* Return 404 Not Found if we aren't able to re-target for subdir marker. */
2681 return ! op_override
? -ENOENT
: 0;
2685 RGWOp
*RGWHandler_REST_Bucket_SWIFT::get_obj_op(bool get_data
)
2688 return new RGWGetACLs_ObjStore_SWIFT
;
2692 return new RGWListBucket_ObjStore_SWIFT
;
2694 return new RGWStatBucket_ObjStore_SWIFT
;
2697 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_get()
2699 return get_obj_op(true);
2702 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_head()
2704 return get_obj_op(false);
2707 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_put()
2710 return new RGWPutACLs_ObjStore_SWIFT
;
2712 if(s
->info
.args
.exists("extract-archive")) {
2713 return new RGWBulkUploadOp_ObjStore_SWIFT
;
2715 return new RGWCreateBucket_ObjStore_SWIFT
;
2718 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_delete()
2720 return new RGWDeleteBucket_ObjStore_SWIFT
;
2723 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_post()
2725 if (RGWFormPost::is_formpost_req(s
)) {
2726 return new RGWFormPost
;
2728 return new RGWPutMetadataBucket_ObjStore_SWIFT
;
2732 RGWOp
*RGWHandler_REST_Bucket_SWIFT::op_options()
2734 return new RGWOptionsCORS_ObjStore_SWIFT
;
2738 RGWOp
*RGWHandler_REST_Obj_SWIFT::get_obj_op(bool get_data
)
2741 return new RGWGetACLs_ObjStore_SWIFT
;
2744 RGWGetObj_ObjStore_SWIFT
*get_obj_op
= new RGWGetObj_ObjStore_SWIFT
;
2745 get_obj_op
->set_get_data(get_data
);
2749 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_get()
2751 return get_obj_op(true);
2754 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_head()
2756 return get_obj_op(false);
2759 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_put()
2762 return new RGWPutACLs_ObjStore_SWIFT
;
2764 if(s
->info
.args
.exists("extract-archive")) {
2765 return new RGWBulkUploadOp_ObjStore_SWIFT
;
2767 if (s
->init_state
.src_bucket
.empty())
2768 return new RGWPutObj_ObjStore_SWIFT
;
2770 return new RGWCopyObj_ObjStore_SWIFT
;
2773 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_delete()
2775 return new RGWDeleteObj_ObjStore_SWIFT
;
2778 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_post()
2780 if (RGWFormPost::is_formpost_req(s
)) {
2781 return new RGWFormPost
;
2783 return new RGWPutMetadataObject_ObjStore_SWIFT
;
2787 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_copy()
2789 return new RGWCopyObj_ObjStore_SWIFT
;
2792 RGWOp
*RGWHandler_REST_Obj_SWIFT::op_options()
2794 return new RGWOptionsCORS_ObjStore_SWIFT
;
2798 int RGWHandler_REST_SWIFT::authorize(const DoutPrefixProvider
*dpp
, optional_yield y
)
2800 return rgw::auth::Strategy::apply(dpp
, auth_strategy
, s
, y
);
2803 int RGWHandler_REST_SWIFT::postauth_init(optional_yield y
)
2805 struct req_init_state
* t
= &s
->init_state
;
2807 /* XXX Stub this until Swift Auth sets account into URL. */
2808 s
->bucket_tenant
= s
->user
->get_tenant();
2809 s
->bucket_name
= t
->url_bucket
;
2812 /* Need an object, even an empty one */
2813 s
->object
= store
->get_object(rgw_obj_key());
2816 ldpp_dout(s
, 10) << "s->object=" <<
2817 (!s
->object
->empty() ? s
->object
->get_key() : rgw_obj_key("<NULL>"))
2819 << rgw_make_bucket_entry_name(s
->bucket_tenant
, s
->bucket_name
)
2823 ret
= rgw_validate_tenant_name(s
->bucket_tenant
);
2826 ret
= validate_bucket_name(s
->bucket_name
);
2829 ret
= validate_object_name(s
->object
->get_name());
2833 if (!t
->src_bucket
.empty()) {
2835 * We don't allow cross-tenant copy at present. It requires account
2836 * names in the URL for Swift.
2838 s
->src_tenant_name
= s
->user
->get_tenant();
2839 s
->src_bucket_name
= t
->src_bucket
;
2841 ret
= validate_bucket_name(s
->src_bucket_name
);
2845 ret
= validate_object_name(s
->src_object
->get_name());
2854 int RGWHandler_REST_SWIFT::validate_bucket_name(const string
& bucket
)
2856 const size_t len
= bucket
.size();
2858 if (len
> MAX_BUCKET_NAME_LEN
) {
2859 /* Bucket Name too long. Generate custom error message and bind it
2860 * to an R-value reference. */
2861 const auto msg
= boost::str(
2862 boost::format("Container name length of %lld longer than %lld")
2863 % len
% int(MAX_BUCKET_NAME_LEN
));
2864 set_req_state_err(s
, ERR_INVALID_BUCKET_NAME
, msg
);
2865 return -ERR_INVALID_BUCKET_NAME
;
2872 if (bucket
[0] == '.')
2873 return -ERR_INVALID_BUCKET_NAME
;
2875 if (check_utf8(bucket
.c_str(), len
))
2876 return -ERR_INVALID_UTF8
;
2878 const char *s
= bucket
.c_str();
2880 for (size_t i
= 0; i
< len
; ++i
, ++s
) {
2881 if (*(unsigned char *)s
== 0xff)
2882 return -ERR_INVALID_BUCKET_NAME
;
2883 if (*(unsigned char *)s
== '/')
2884 return -ERR_INVALID_BUCKET_NAME
;
2890 static void next_tok(string
& str
, string
& tok
, char delim
)
2892 if (str
.size() == 0) {
2897 int pos
= str
.find(delim
);
2899 tok
= str
.substr(0, pos
);
2900 str
= str
.substr(pos
+ 1);
2906 int RGWHandler_REST_SWIFT::init_from_header(rgw::sal::Store
* store
,
2907 struct req_state
* const s
,
2908 const std::string
& frontend_prefix
)
2913 s
->prot_flags
|= RGW_REST_SWIFT
;
2915 char reqbuf
[frontend_prefix
.length() + s
->decoded_uri
.length() + 1];
2916 sprintf(reqbuf
, "%s%s", frontend_prefix
.c_str(), s
->decoded_uri
.c_str());
2917 const char *req_name
= reqbuf
;
2921 if (*req_name
== '?') {
2924 p
= s
->info
.request_params
.c_str();
2927 s
->info
.args
.set(p
);
2928 s
->info
.args
.parse(s
);
2930 /* Skip the leading slash of URL hierarchy. */
2931 if (req_name
[0] != '/') {
2937 if ('\0' == req_name
[0]) {
2938 return g_conf()->rgw_swift_url_prefix
== "/" ? -ERR_BAD_URL
: 0;
2943 size_t pos
= req
.find('/');
2944 if (std::string::npos
!= pos
&& g_conf()->rgw_swift_url_prefix
!= "/") {
2945 bool cut_url
= g_conf()->rgw_swift_url_prefix
.length();
2946 first
= req
.substr(0, pos
);
2948 if (first
.compare(g_conf()->rgw_swift_url_prefix
) == 0) {
2950 /* Rewind to the "v1/..." part. */
2951 next_tok(req
, first
, '/');
2954 } else if (req
.compare(g_conf()->rgw_swift_url_prefix
) == 0) {
2955 s
->formatter
= new RGWFormatter_Plain
;
2956 return -ERR_BAD_URL
;
2961 std::string tenant_path
;
2962 if (! g_conf()->rgw_swift_tenant_name
.empty()) {
2963 tenant_path
= "/AUTH_";
2964 tenant_path
.append(g_conf()->rgw_swift_tenant_name
);
2967 /* verify that the request_uri conforms with what's expected */
2968 char buf
[g_conf()->rgw_swift_url_prefix
.length() + 16 + tenant_path
.length()];
2970 if (g_conf()->rgw_swift_url_prefix
== "/") {
2971 blen
= sprintf(buf
, "/v1%s", tenant_path
.c_str());
2973 blen
= sprintf(buf
, "/%s/v1%s",
2974 g_conf()->rgw_swift_url_prefix
.c_str(), tenant_path
.c_str());
2977 if (strncmp(reqbuf
, buf
, blen
) != 0) {
2981 int ret
= allocate_formatter(s
, RGW_FORMAT_PLAIN
, true);
2987 next_tok(req
, ver
, '/');
2989 if (!tenant_path
.empty() || g_conf()->rgw_swift_account_in_url
) {
2990 string account_name
;
2991 next_tok(req
, account_name
, '/');
2993 /* Erase all pre-defined prefixes like "AUTH_" or "KEY_". */
2994 const vector
<string
> skipped_prefixes
= { "AUTH_", "KEY_" };
2996 for (const auto& pfx
: skipped_prefixes
) {
2997 const size_t comp_len
= min(account_name
.length(), pfx
.length());
2998 if (account_name
.compare(0, comp_len
, pfx
) == 0) {
2999 /* Prefix is present. Drop it. */
3000 account_name
= account_name
.substr(comp_len
);
3005 if (account_name
.empty()) {
3006 return -ERR_PRECONDITION_FAILED
;
3008 s
->account_name
= account_name
;
3012 next_tok(req
, first
, '/');
3014 ldpp_dout(s
, 10) << "ver=" << ver
<< " first=" << first
<< " req=" << req
<< dendl
;
3015 if (first
.size() == 0)
3018 s
->info
.effective_uri
= "/" + first
;
3020 // Save bucket to tide us over until token is parsed.
3021 s
->init_state
.url_bucket
= first
;
3024 s
->object
= store
->get_object(
3025 rgw_obj_key(req
, s
->info
.env
->get("HTTP_X_OBJECT_VERSION_ID", ""))); /* rgw swift extension */
3026 s
->info
.effective_uri
.append("/" + s
->object
->get_name());
3032 int RGWHandler_REST_SWIFT::init(rgw::sal::Store
* store
, struct req_state
* s
,
3033 rgw::io::BasicClient
*cio
)
3035 struct req_init_state
*t
= &s
->init_state
;
3037 s
->dialect
= "swift";
3039 std::string copy_source
= s
->info
.env
->get("HTTP_X_COPY_FROM", "");
3040 if (! copy_source
.empty()) {
3042 bool result
= RGWCopyObj::parse_copy_location(copy_source
, t
->src_bucket
, key
, s
);
3044 return -ERR_BAD_URL
;
3045 s
->src_object
= store
->get_object(key
);
3047 return -ERR_BAD_URL
;
3050 if (s
->op
== OP_COPY
) {
3051 std::string req_dest
= s
->info
.env
->get("HTTP_DESTINATION", "");
3052 if (req_dest
.empty())
3053 return -ERR_BAD_URL
;
3055 std::string dest_bucket_name
;
3056 rgw_obj_key dest_obj_key
;
3058 RGWCopyObj::parse_copy_location(req_dest
, dest_bucket_name
,
3061 return -ERR_BAD_URL
;
3063 std::string dest_object_name
= dest_obj_key
.name
;
3065 /* convert COPY operation into PUT */
3066 t
->src_bucket
= t
->url_bucket
;
3067 s
->src_object
= s
->object
->clone();
3068 t
->url_bucket
= dest_bucket_name
;
3069 s
->object
->set_name(dest_object_name
);
3073 s
->info
.storage_class
= s
->info
.env
->get("HTTP_X_OBJECT_STORAGE_CLASS", "");
3075 return RGWHandler_REST::init(store
, s
, cio
);
3079 RGWRESTMgr_SWIFT::get_handler(rgw::sal::Store
* store
,
3080 struct req_state
* const s
,
3081 const rgw::auth::StrategyRegistry
& auth_registry
,
3082 const std::string
& frontend_prefix
)
3084 int ret
= RGWHandler_REST_SWIFT::init_from_header(store
, s
, frontend_prefix
);
3086 ldpp_dout(s
, 10) << "init_from_header returned err=" << ret
<< dendl
;
3090 const auto& auth_strategy
= auth_registry
.get_swift();
3092 if (s
->init_state
.url_bucket
.empty()) {
3093 return new RGWHandler_REST_Service_SWIFT(auth_strategy
);
3096 if (rgw::sal::Object::empty(s
->object
.get())) {
3097 return new RGWHandler_REST_Bucket_SWIFT(auth_strategy
);
3100 return new RGWHandler_REST_Obj_SWIFT(auth_strategy
);
3103 RGWHandler_REST
* RGWRESTMgr_SWIFT_Info::get_handler(
3104 rgw::sal::Store
* store
,
3105 struct req_state
* const s
,
3106 const rgw::auth::StrategyRegistry
& auth_registry
,
3107 const std::string
& frontend_prefix
)
3109 s
->prot_flags
|= RGW_REST_SWIFT
;
3110 const auto& auth_strategy
= auth_registry
.get_swift();
3111 return new RGWHandler_REST_SWIFT_Info(auth_strategy
);