1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "common/ceph_json.h"
8 #include "rgw_rest_user.h"
10 #include "include/str_list.h"
11 #include "include/ceph_assert.h"
13 #define dout_subsys ceph_subsys_rgw
15 class RGWOp_User_List
: public RGWRESTOp
{
20 int check_caps(RGWUserCaps
& caps
) override
{
21 return caps
.check_cap("users", RGW_CAP_READ
);
24 void execute() override
;
26 const char* name() const override
{ return "list_user"; }
29 void RGWOp_User_List::execute()
31 RGWUserAdminOpState op_state
;
35 RESTArgs::get_uint32(s
, "max-entries", 1000, &max_entries
);
36 RESTArgs::get_string(s
, "marker", marker
, &marker
);
38 op_state
.max_entries
= max_entries
;
39 op_state
.marker
= marker
;
40 http_ret
= RGWUserAdminOp_User::list(store
, op_state
, flusher
);
43 class RGWOp_User_Info
: public RGWRESTOp
{
48 int check_caps(RGWUserCaps
& caps
) override
{
49 return caps
.check_cap("users", RGW_CAP_READ
);
52 void execute() override
;
54 const char* name() const override
{ return "get_user_info"; }
57 void RGWOp_User_Info::execute()
59 RGWUserAdminOpState op_state
;
61 std::string uid_str
, access_key_str
;
65 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
66 RESTArgs::get_string(s
, "access-key", access_key_str
, &access_key_str
);
68 // if uid was not supplied in rest argument, error out now, otherwise we'll
69 // end up initializing anonymous user, for which keys.init will eventually
71 if (uid_str
.empty() && access_key_str
.empty()){
76 rgw_user
uid(uid_str
);
78 RESTArgs::get_bool(s
, "stats", false, &fetch_stats
);
80 RESTArgs::get_bool(s
, "sync", false, &sync_stats
);
82 op_state
.set_user_id(uid
);
83 op_state
.set_access_key(access_key_str
);
84 op_state
.set_fetch_stats(fetch_stats
);
85 op_state
.set_sync_stats(sync_stats
);
87 http_ret
= RGWUserAdminOp_User::info(store
, op_state
, flusher
);
90 class RGWOp_User_Create
: public RGWRESTOp
{
93 RGWOp_User_Create() {}
95 int check_caps(RGWUserCaps
& caps
) override
{
96 return caps
.check_cap("users", RGW_CAP_WRITE
);
99 void execute() override
;
101 const char* name() const override
{ return "create_user"; }
104 void RGWOp_User_Create::execute()
107 std::string display_name
;
109 std::string access_key
;
110 std::string secret_key
;
111 std::string key_type_str
;
113 std::string tenant_name
;
114 std::string op_mask_str
;
122 int32_t default_max_buckets
= s
->cct
->_conf
->rgw_user_max_buckets
;
124 RGWUserAdminOpState op_state
;
126 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
127 rgw_user
uid(uid_str
);
129 RESTArgs::get_string(s
, "display-name", display_name
, &display_name
);
130 RESTArgs::get_string(s
, "email", email
, &email
);
131 RESTArgs::get_string(s
, "access-key", access_key
, &access_key
);
132 RESTArgs::get_string(s
, "secret-key", secret_key
, &secret_key
);
133 RESTArgs::get_string(s
, "key-type", key_type_str
, &key_type_str
);
134 RESTArgs::get_string(s
, "user-caps", caps
, &caps
);
135 RESTArgs::get_string(s
, "tenant", tenant_name
, &tenant_name
);
136 RESTArgs::get_bool(s
, "generate-key", true, &gen_key
);
137 RESTArgs::get_bool(s
, "suspended", false, &suspended
);
138 RESTArgs::get_int32(s
, "max-buckets", default_max_buckets
, &max_buckets
);
139 RESTArgs::get_bool(s
, "system", false, &system
);
140 RESTArgs::get_bool(s
, "exclusive", false, &exclusive
);
141 RESTArgs::get_string(s
, "op-mask", op_mask_str
, &op_mask_str
);
143 if (!s
->user
->system
&& system
) {
144 ldout(s
->cct
, 0) << "cannot set system flag by non-system user" << dendl
;
149 if (!tenant_name
.empty()) {
150 uid
.tenant
= tenant_name
;
153 // TODO: validate required args are passed in. (for eg. uid and display_name here)
154 op_state
.set_user_id(uid
);
155 op_state
.set_display_name(display_name
);
156 op_state
.set_user_email(email
);
157 op_state
.set_caps(caps
);
158 op_state
.set_access_key(access_key
);
159 op_state
.set_secret_key(secret_key
);
161 if (!op_mask_str
.empty()) {
163 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
165 ldout(s
->cct
, 0) << "failed to parse op_mask: " << ret
<< dendl
;
169 op_state
.set_op_mask(op_mask
);
172 if (!key_type_str
.empty()) {
173 int32_t key_type
= KEY_TYPE_UNDEFINED
;
174 if (key_type_str
.compare("swift") == 0)
175 key_type
= KEY_TYPE_SWIFT
;
176 else if (key_type_str
.compare("s3") == 0)
177 key_type
= KEY_TYPE_S3
;
179 op_state
.set_key_type(key_type
);
182 if (max_buckets
!= default_max_buckets
)
183 op_state
.set_max_buckets(max_buckets
);
185 if (s
->info
.args
.exists("suspended"))
186 op_state
.set_suspension(suspended
);
188 if (s
->info
.args
.exists("system"))
189 op_state
.set_system(system
);
191 if (s
->info
.args
.exists("exclusive"))
192 op_state
.set_exclusive(exclusive
);
195 op_state
.set_generate_key();
197 http_ret
= RGWUserAdminOp_User::create(store
, op_state
, flusher
);
200 class RGWOp_User_Modify
: public RGWRESTOp
{
203 RGWOp_User_Modify() {}
205 int check_caps(RGWUserCaps
& caps
) override
{
206 return caps
.check_cap("users", RGW_CAP_WRITE
);
209 void execute() override
;
211 const char* name() const override
{ return "modify_user"; }
214 void RGWOp_User_Modify::execute()
217 std::string display_name
;
219 std::string access_key
;
220 std::string secret_key
;
221 std::string key_type_str
;
223 std::string op_mask_str
;
232 RGWUserAdminOpState op_state
;
234 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
235 rgw_user
uid(uid_str
);
237 RESTArgs::get_string(s
, "display-name", display_name
, &display_name
);
238 RESTArgs::get_string(s
, "email", email
, &email
, &email_set
);
239 RESTArgs::get_string(s
, "access-key", access_key
, &access_key
);
240 RESTArgs::get_string(s
, "secret-key", secret_key
, &secret_key
);
241 RESTArgs::get_string(s
, "user-caps", caps
, &caps
);
242 RESTArgs::get_bool(s
, "generate-key", false, &gen_key
);
243 RESTArgs::get_bool(s
, "suspended", false, &suspended
);
244 RESTArgs::get_int32(s
, "max-buckets", RGW_DEFAULT_MAX_BUCKETS
, &max_buckets
, "a_set
);
245 RESTArgs::get_string(s
, "key-type", key_type_str
, &key_type_str
);
247 RESTArgs::get_bool(s
, "system", false, &system
);
248 RESTArgs::get_string(s
, "op-mask", op_mask_str
, &op_mask_str
);
250 if (!s
->user
->system
&& system
) {
251 ldout(s
->cct
, 0) << "cannot set system flag by non-system user" << dendl
;
256 op_state
.set_user_id(uid
);
257 op_state
.set_display_name(display_name
);
260 op_state
.set_user_email(email
);
262 op_state
.set_caps(caps
);
263 op_state
.set_access_key(access_key
);
264 op_state
.set_secret_key(secret_key
);
267 op_state
.set_max_buckets(max_buckets
);
270 op_state
.set_generate_key();
272 if (!key_type_str
.empty()) {
273 int32_t key_type
= KEY_TYPE_UNDEFINED
;
274 if (key_type_str
.compare("swift") == 0)
275 key_type
= KEY_TYPE_SWIFT
;
276 else if (key_type_str
.compare("s3") == 0)
277 key_type
= KEY_TYPE_S3
;
279 op_state
.set_key_type(key_type
);
282 if (s
->info
.args
.exists("suspended"))
283 op_state
.set_suspension(suspended
);
285 if (s
->info
.args
.exists("system"))
286 op_state
.set_system(system
);
288 if (!op_mask_str
.empty()) {
290 int ret
= rgw_parse_op_type_list(op_mask_str
, &op_mask
);
292 ldout(s
->cct
, 0) << "failed to parse op_mask: " << ret
<< dendl
;
296 op_state
.set_op_mask(op_mask
);
299 http_ret
= RGWUserAdminOp_User::modify(store
, op_state
, flusher
);
302 class RGWOp_User_Remove
: public RGWRESTOp
{
305 RGWOp_User_Remove() {}
307 int check_caps(RGWUserCaps
& caps
) override
{
308 return caps
.check_cap("users", RGW_CAP_WRITE
);
311 void execute() override
;
313 const char* name() const override
{ return "remove_user"; }
316 void RGWOp_User_Remove::execute()
321 RGWUserAdminOpState op_state
;
323 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
324 rgw_user
uid(uid_str
);
326 RESTArgs::get_bool(s
, "purge-data", false, &purge_data
);
328 // FIXME: no double checking
330 op_state
.set_user_id(uid
);
332 op_state
.set_purge_data(purge_data
);
334 http_ret
= RGWUserAdminOp_User::remove(store
, op_state
, flusher
);
337 class RGWOp_Subuser_Create
: public RGWRESTOp
{
340 RGWOp_Subuser_Create() {}
342 int check_caps(RGWUserCaps
& caps
) override
{
343 return caps
.check_cap("users", RGW_CAP_WRITE
);
346 void execute() override
;
348 const char* name() const override
{ return "create_subuser"; }
351 void RGWOp_Subuser_Create::execute()
355 std::string secret_key
;
356 std::string access_key
;
357 std::string perm_str
;
358 std::string key_type_str
;
360 bool gen_subuser
= false; // FIXME placeholder
364 uint32_t perm_mask
= 0;
365 int32_t key_type
= KEY_TYPE_SWIFT
;
367 RGWUserAdminOpState op_state
;
369 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
370 rgw_user
uid(uid_str
);
372 RESTArgs::get_string(s
, "subuser", subuser
, &subuser
);
373 RESTArgs::get_string(s
, "access-key", access_key
, &access_key
);
374 RESTArgs::get_string(s
, "secret-key", secret_key
, &secret_key
);
375 RESTArgs::get_string(s
, "access", perm_str
, &perm_str
);
376 RESTArgs::get_string(s
, "key-type", key_type_str
, &key_type_str
);
377 //RESTArgs::get_bool(s, "generate-subuser", false, &gen_subuser);
378 RESTArgs::get_bool(s
, "generate-secret", false, &gen_secret
);
379 RESTArgs::get_bool(s
, "gen-access-key", false, &gen_access
);
381 perm_mask
= rgw_str_to_perm(perm_str
.c_str());
382 op_state
.set_perm(perm_mask
);
384 op_state
.set_user_id(uid
);
385 op_state
.set_subuser(subuser
);
386 op_state
.set_access_key(access_key
);
387 op_state
.set_secret_key(secret_key
);
388 op_state
.set_generate_subuser(gen_subuser
);
391 op_state
.set_gen_access();
394 op_state
.set_gen_secret();
396 if (!key_type_str
.empty()) {
397 if (key_type_str
.compare("swift") == 0)
398 key_type
= KEY_TYPE_SWIFT
;
399 else if (key_type_str
.compare("s3") == 0)
400 key_type
= KEY_TYPE_S3
;
402 op_state
.set_key_type(key_type
);
404 http_ret
= RGWUserAdminOp_Subuser::create(store
, op_state
, flusher
);
407 class RGWOp_Subuser_Modify
: public RGWRESTOp
{
410 RGWOp_Subuser_Modify() {}
412 int check_caps(RGWUserCaps
& caps
) override
{
413 return caps
.check_cap("users", RGW_CAP_WRITE
);
416 void execute() override
;
418 const char* name() const override
{ return "modify_subuser"; }
421 void RGWOp_Subuser_Modify::execute()
425 std::string secret_key
;
426 std::string key_type_str
;
427 std::string perm_str
;
429 RGWUserAdminOpState op_state
;
432 int32_t key_type
= KEY_TYPE_SWIFT
;
436 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
437 rgw_user
uid(uid_str
);
439 RESTArgs::get_string(s
, "subuser", subuser
, &subuser
);
440 RESTArgs::get_string(s
, "secret-key", secret_key
, &secret_key
);
441 RESTArgs::get_string(s
, "access", perm_str
, &perm_str
);
442 RESTArgs::get_string(s
, "key-type", key_type_str
, &key_type_str
);
443 RESTArgs::get_bool(s
, "generate-secret", false, &gen_secret
);
445 perm_mask
= rgw_str_to_perm(perm_str
.c_str());
446 op_state
.set_perm(perm_mask
);
448 op_state
.set_user_id(uid
);
449 op_state
.set_subuser(subuser
);
451 if (!secret_key
.empty())
452 op_state
.set_secret_key(secret_key
);
455 op_state
.set_gen_secret();
457 if (!key_type_str
.empty()) {
458 if (key_type_str
.compare("swift") == 0)
459 key_type
= KEY_TYPE_SWIFT
;
460 else if (key_type_str
.compare("s3") == 0)
461 key_type
= KEY_TYPE_S3
;
463 op_state
.set_key_type(key_type
);
465 http_ret
= RGWUserAdminOp_Subuser::modify(store
, op_state
, flusher
);
468 class RGWOp_Subuser_Remove
: public RGWRESTOp
{
471 RGWOp_Subuser_Remove() {}
473 int check_caps(RGWUserCaps
& caps
) override
{
474 return caps
.check_cap("users", RGW_CAP_WRITE
);
477 void execute() override
;
479 const char* name() const override
{ return "remove_subuser"; }
482 void RGWOp_Subuser_Remove::execute()
488 RGWUserAdminOpState op_state
;
490 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
491 rgw_user
uid(uid_str
);
493 RESTArgs::get_string(s
, "subuser", subuser
, &subuser
);
494 RESTArgs::get_bool(s
, "purge-keys", true, &purge_keys
);
496 op_state
.set_user_id(uid
);
497 op_state
.set_subuser(subuser
);
500 op_state
.set_purge_keys();
502 http_ret
= RGWUserAdminOp_Subuser::remove(store
, op_state
, flusher
);
505 class RGWOp_Key_Create
: public RGWRESTOp
{
508 RGWOp_Key_Create() {}
510 int check_caps(RGWUserCaps
& caps
) override
{
511 return caps
.check_cap("users", RGW_CAP_WRITE
);
514 void execute() override
;
516 const char* name() const override
{ return "create_access_key"; }
519 void RGWOp_Key_Create::execute()
523 std::string access_key
;
524 std::string secret_key
;
525 std::string key_type_str
;
529 RGWUserAdminOpState op_state
;
531 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
532 rgw_user
uid(uid_str
);
534 RESTArgs::get_string(s
, "subuser", subuser
, &subuser
);
535 RESTArgs::get_string(s
, "access-key", access_key
, &access_key
);
536 RESTArgs::get_string(s
, "secret-key", secret_key
, &secret_key
);
537 RESTArgs::get_string(s
, "key-type", key_type_str
, &key_type_str
);
538 RESTArgs::get_bool(s
, "generate-key", true, &gen_key
);
540 op_state
.set_user_id(uid
);
541 op_state
.set_subuser(subuser
);
542 op_state
.set_access_key(access_key
);
543 op_state
.set_secret_key(secret_key
);
546 op_state
.set_generate_key();
548 if (!key_type_str
.empty()) {
549 int32_t key_type
= KEY_TYPE_UNDEFINED
;
550 if (key_type_str
.compare("swift") == 0)
551 key_type
= KEY_TYPE_SWIFT
;
552 else if (key_type_str
.compare("s3") == 0)
553 key_type
= KEY_TYPE_S3
;
555 op_state
.set_key_type(key_type
);
558 http_ret
= RGWUserAdminOp_Key::create(store
, op_state
, flusher
);
561 class RGWOp_Key_Remove
: public RGWRESTOp
{
564 RGWOp_Key_Remove() {}
566 int check_caps(RGWUserCaps
& caps
) override
{
567 return caps
.check_cap("users", RGW_CAP_WRITE
);
570 void execute() override
;
572 const char* name() const override
{ return "remove_access_key"; }
575 void RGWOp_Key_Remove::execute()
579 std::string access_key
;
580 std::string key_type_str
;
582 RGWUserAdminOpState op_state
;
584 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
585 rgw_user
uid(uid_str
);
587 RESTArgs::get_string(s
, "subuser", subuser
, &subuser
);
588 RESTArgs::get_string(s
, "access-key", access_key
, &access_key
);
589 RESTArgs::get_string(s
, "key-type", key_type_str
, &key_type_str
);
591 op_state
.set_user_id(uid
);
592 op_state
.set_subuser(subuser
);
593 op_state
.set_access_key(access_key
);
595 if (!key_type_str
.empty()) {
596 int32_t key_type
= KEY_TYPE_UNDEFINED
;
597 if (key_type_str
.compare("swift") == 0)
598 key_type
= KEY_TYPE_SWIFT
;
599 else if (key_type_str
.compare("s3") == 0)
600 key_type
= KEY_TYPE_S3
;
602 op_state
.set_key_type(key_type
);
605 http_ret
= RGWUserAdminOp_Key::remove(store
, op_state
, flusher
);
608 class RGWOp_Caps_Add
: public RGWRESTOp
{
613 int check_caps(RGWUserCaps
& caps
) override
{
614 return caps
.check_cap("users", RGW_CAP_WRITE
);
617 void execute() override
;
619 const char* name() const override
{ return "add_user_caps"; }
622 void RGWOp_Caps_Add::execute()
627 RGWUserAdminOpState op_state
;
629 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
630 rgw_user
uid(uid_str
);
632 RESTArgs::get_string(s
, "user-caps", caps
, &caps
);
634 op_state
.set_user_id(uid
);
635 op_state
.set_caps(caps
);
637 http_ret
= RGWUserAdminOp_Caps::add(store
, op_state
, flusher
);
640 class RGWOp_Caps_Remove
: public RGWRESTOp
{
643 RGWOp_Caps_Remove() {}
645 int check_caps(RGWUserCaps
& caps
) override
{
646 return caps
.check_cap("users", RGW_CAP_WRITE
);
649 void execute() override
;
651 const char* name() const override
{ return "remove_user_caps"; }
654 void RGWOp_Caps_Remove::execute()
659 RGWUserAdminOpState op_state
;
661 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
662 rgw_user
uid(uid_str
);
664 RESTArgs::get_string(s
, "user-caps", caps
, &caps
);
666 op_state
.set_user_id(uid
);
667 op_state
.set_caps(caps
);
669 http_ret
= RGWUserAdminOp_Caps::remove(store
, op_state
, flusher
);
673 RGWQuotaInfo bucket_quota
;
674 RGWQuotaInfo user_quota
;
678 explicit UserQuotas(RGWUserInfo
& info
) : bucket_quota(info
.bucket_quota
),
679 user_quota(info
.user_quota
) {}
681 void dump(Formatter
*f
) const {
682 encode_json("bucket_quota", bucket_quota
, f
);
683 encode_json("user_quota", user_quota
, f
);
685 void decode_json(JSONObj
*obj
) {
686 JSONDecoder::decode_json("bucket_quota", bucket_quota
, obj
);
687 JSONDecoder::decode_json("user_quota", user_quota
, obj
);
691 class RGWOp_Quota_Info
: public RGWRESTOp
{
694 RGWOp_Quota_Info() {}
696 int check_caps(RGWUserCaps
& caps
) override
{
697 return caps
.check_cap("users", RGW_CAP_READ
);
700 void execute() override
;
702 const char* name() const override
{ return "get_quota_info"; }
706 void RGWOp_Quota_Info::execute()
708 RGWUserAdminOpState op_state
;
711 std::string quota_type
;
713 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
714 RESTArgs::get_string(s
, "quota-type", quota_type
, "a_type
);
716 if (uid_str
.empty()) {
721 rgw_user
uid(uid_str
);
723 bool show_all
= quota_type
.empty();
724 bool show_bucket
= show_all
|| (quota_type
== "bucket");
725 bool show_user
= show_all
|| (quota_type
== "user");
727 if (!(show_all
|| show_bucket
|| show_user
)) {
732 op_state
.set_user_id(uid
);
735 http_ret
= user
.init(store
, op_state
);
739 if (!op_state
.has_existing_user()) {
740 http_ret
= -ERR_NO_SUCH_USER
;
746 http_ret
= user
.info(info
, &err_msg
);
752 UserQuotas
quotas(info
);
753 encode_json("quota", quotas
, s
->formatter
);
754 } else if (show_user
) {
755 encode_json("user_quota", info
.user_quota
, s
->formatter
);
757 encode_json("bucket_quota", info
.bucket_quota
, s
->formatter
);
763 class RGWOp_Quota_Set
: public RGWRESTOp
{
768 int check_caps(RGWUserCaps
& caps
) override
{
769 return caps
.check_cap("users", RGW_CAP_WRITE
);
772 void execute() override
;
774 const char* name() const override
{ return "set_quota_info"; }
780 * two different ways to set the quota info: as json struct in the message body or via http params.
784 * PUT /admin/user?uid=<uid>["a-type=<type>]
786 * whereas quota-type is optional and is either user, or bucket
788 * if quota-type is not specified then we expect to get a structure that contains both quotas,
789 * otherwise we'll only get the relevant configuration.
791 * E.g., if quota type not specified:
794 * "max_size_kb" : 4096,
795 * "max_objects" : -1,
799 * "max_size_kb" : 1024,
800 * "max_objects" : -1,
806 * or if quota type is specified:
808 * "max_size_kb" : 4096,
809 * "max_objects" : -1,
813 * Another option is not to pass any body and set the following http params:
817 * max-objects=<max objects>
818 * enabled[={true,false}]
820 * all params are optionals and default to the current settings. With this type of configuration the
821 * quota-type param is mandatory.
825 void RGWOp_Quota_Set::execute()
827 RGWUserAdminOpState op_state
;
830 std::string quota_type
;
832 RESTArgs::get_string(s
, "uid", uid_str
, &uid_str
);
833 RESTArgs::get_string(s
, "quota-type", quota_type
, "a_type
);
835 if (uid_str
.empty()) {
840 rgw_user
uid(uid_str
);
842 bool set_all
= quota_type
.empty();
843 bool set_bucket
= set_all
|| (quota_type
== "bucket");
844 bool set_user
= set_all
|| (quota_type
== "user");
846 if (!(set_all
|| set_bucket
|| set_user
)) {
847 ldout(store
->ctx(), 20) << "invalid quota type" << dendl
;
852 bool use_http_params
;
854 if (s
->content_length
> 0) {
855 use_http_params
= false;
857 const char *encoding
= s
->info
.env
->get("HTTP_TRANSFER_ENCODING");
858 use_http_params
= (!encoding
|| strcmp(encoding
, "chunked") != 0);
861 if (use_http_params
&& set_all
) {
862 ldout(store
->ctx(), 20) << "quota type was not specified, can't set all quotas via http headers" << dendl
;
867 op_state
.set_user_id(uid
);
870 http_ret
= user
.init(store
, op_state
);
872 ldout(store
->ctx(), 20) << "failed initializing user info: " << http_ret
<< dendl
;
876 if (!op_state
.has_existing_user()) {
877 http_ret
= -ERR_NO_SUCH_USER
;
881 #define QUOTA_INPUT_MAX_LEN 1024
885 if ((http_ret
= rgw_rest_get_json_input(store
->ctx(), s
, quotas
, QUOTA_INPUT_MAX_LEN
, NULL
)) < 0) {
886 ldout(store
->ctx(), 20) << "failed to retrieve input" << dendl
;
890 op_state
.set_user_quota(quotas
.user_quota
);
891 op_state
.set_bucket_quota(quotas
.bucket_quota
);
895 if (!use_http_params
) {
897 http_ret
= rgw_rest_get_json_input(store
->ctx(), s
, quota
, QUOTA_INPUT_MAX_LEN
, &empty
);
899 ldout(store
->ctx(), 20) << "failed to retrieve input" << dendl
;
903 /* was probably chunked input, but no content provided, configure via http params */
904 use_http_params
= true;
908 if (use_http_params
) {
911 http_ret
= user
.info(info
, &err_msg
);
913 ldout(store
->ctx(), 20) << "failed to get user info: " << http_ret
<< dendl
;
916 RGWQuotaInfo
*old_quota
;
918 old_quota
= &info
.user_quota
;
920 old_quota
= &info
.bucket_quota
;
923 RESTArgs::get_int64(s
, "max-objects", old_quota
->max_objects
, "a
.max_objects
);
924 RESTArgs::get_int64(s
, "max-size", old_quota
->max_size
, "a
.max_size
);
926 bool has_max_size_kb
= false;
927 RESTArgs::get_int64(s
, "max-size-kb", 0, &max_size_kb
, &has_max_size_kb
);
928 if (has_max_size_kb
) {
929 quota
.max_size
= max_size_kb
* 1024;
931 RESTArgs::get_bool(s
, "enabled", old_quota
->enabled
, "a
.enabled
);
935 op_state
.set_user_quota(quota
);
937 op_state
.set_bucket_quota(quota
);
942 http_ret
= user
.modify(op_state
, &err
);
944 ldout(store
->ctx(), 20) << "failed updating user info: " << http_ret
<< ": " << err
<< dendl
;
949 RGWOp
*RGWHandler_User::op_get()
951 if (s
->info
.args
.sub_resource_exists("quota"))
952 return new RGWOp_Quota_Info
;
954 if (s
->info
.args
.sub_resource_exists("list"))
955 return new RGWOp_User_List
;
957 return new RGWOp_User_Info
;
960 RGWOp
*RGWHandler_User::op_put()
962 if (s
->info
.args
.sub_resource_exists("subuser"))
963 return new RGWOp_Subuser_Create
;
965 if (s
->info
.args
.sub_resource_exists("key"))
966 return new RGWOp_Key_Create
;
968 if (s
->info
.args
.sub_resource_exists("caps"))
969 return new RGWOp_Caps_Add
;
971 if (s
->info
.args
.sub_resource_exists("quota"))
972 return new RGWOp_Quota_Set
;
974 return new RGWOp_User_Create
;
977 RGWOp
*RGWHandler_User::op_post()
979 if (s
->info
.args
.sub_resource_exists("subuser"))
980 return new RGWOp_Subuser_Modify
;
982 return new RGWOp_User_Modify
;
985 RGWOp
*RGWHandler_User::op_delete()
987 if (s
->info
.args
.sub_resource_exists("subuser"))
988 return new RGWOp_Subuser_Remove
;
990 if (s
->info
.args
.sub_resource_exists("key"))
991 return new RGWOp_Key_Remove
;
993 if (s
->info
.args
.sub_resource_exists("caps"))
994 return new RGWOp_Caps_Remove
;
996 return new RGWOp_User_Remove
;