forked from ceph/ceph
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rgw_admin.cc
9519 lines (8485 loc) · 315 KB
/
rgw_admin.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp
#include <errno.h>
#include <iostream>
#include <sstream>
#include <string>
#include <boost/optional.hpp>
extern "C" {
#include <liboath/oath.h>
}
#include "auth/Crypto.h"
#include "compressor/Compressor.h"
#include "common/armor.h"
#include "common/ceph_json.h"
#include "common/config.h"
#include "common/ceph_argparse.h"
#include "common/Formatter.h"
#include "common/errno.h"
#include "common/safe_io.h"
#include "include/util.h"
#include "cls/rgw/cls_rgw_types.h"
#include "cls/rgw/cls_rgw_client.h"
#include "global/global_init.h"
#include "include/utime.h"
#include "include/str_list.h"
#include "rgw_user.h"
#include "rgw_bucket.h"
#include "rgw_otp.h"
#include "rgw_rados.h"
#include "rgw_acl.h"
#include "rgw_acl_s3.h"
#include "rgw_datalog.h"
#include "rgw_lc.h"
#include "rgw_log.h"
#include "rgw_formats.h"
#include "rgw_usage.h"
#include "rgw_orphan.h"
#include "rgw_sync.h"
#include "rgw_trim_bilog.h"
#include "rgw_trim_datalog.h"
#include "rgw_trim_mdlog.h"
#include "rgw_data_sync.h"
#include "rgw_rest_conn.h"
#include "rgw_realm_watcher.h"
#include "rgw_role.h"
#include "rgw_reshard.h"
#include "rgw_http_client_curl.h"
#include "rgw_zone.h"
#include "rgw_pubsub.h"
#include "rgw_bucket_sync.h"
#include "rgw_sync_checkpoint.h"
#include "rgw_lua.h"
#include "services/svc_sync_modules.h"
#include "services/svc_cls.h"
#include "services/svc_bilog_rados.h"
#include "services/svc_mdlog.h"
#include "services/svc_meta_be_otp.h"
#include "services/svc_zone.h"
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rgw
#define SECRET_KEY_LEN 40
#define PUBLIC_ID_LEN 20
static rgw::sal::RGWRadosStore *store = NULL;
static const DoutPrefixProvider* dpp() {
struct GlobalPrefix : public DoutPrefixProvider {
CephContext *get_cct() const override { return dout_context; }
unsigned get_subsys() const override { return dout_subsys; }
std::ostream& gen_prefix(std::ostream& out) const override { return out; }
};
static GlobalPrefix global_dpp;
return &global_dpp;
}
#define CHECK_TRUE(x, msg, err) \
do { \
if (!x) { \
cerr << msg << std::endl; \
return err; \
} \
} while (0)
#define CHECK_SUCCESS(x, msg) \
do { \
int _x_val = (x); \
if (_x_val < 0) { \
cerr << msg << ": " << cpp_strerror(-_x_val) << std::endl; \
return _x_val; \
} \
} while (0)
void usage()
{
cout << "usage: radosgw-admin <cmd> [options...]" << std::endl;
cout << "commands:\n";
cout << " user create create a new user\n" ;
cout << " user modify modify user\n";
cout << " user info get user info\n";
cout << " user rename rename user\n";
cout << " user rm remove user\n";
cout << " user suspend suspend a user\n";
cout << " user enable re-enable user after suspension\n";
cout << " user check check user info\n";
cout << " user stats show user stats as accounted by quota subsystem\n";
cout << " user list list users\n";
cout << " caps add add user capabilities\n";
cout << " caps rm remove user capabilities\n";
cout << " subuser create create a new subuser\n" ;
cout << " subuser modify modify subuser\n";
cout << " subuser rm remove subuser\n";
cout << " key create create access key\n";
cout << " key rm remove access key\n";
cout << " bucket list list buckets (specify --allow-unordered for\n";
cout << " faster, unsorted listing)\n";
cout << " bucket limit check show bucket sharding stats\n";
cout << " bucket link link bucket to specified user\n";
cout << " bucket unlink unlink bucket from specified user\n";
cout << " bucket stats returns bucket statistics\n";
cout << " bucket rm remove bucket\n";
cout << " bucket check check bucket index\n";
cout << " bucket chown link bucket to specified user and update its object ACLs\n";
cout << " bucket reshard reshard bucket\n";
cout << " bucket rewrite rewrite all objects in the specified bucket\n";
cout << " bucket sync checkpoint poll a bucket's sync status until it catches up to its remote\n";
cout << " bucket sync disable disable bucket sync\n";
cout << " bucket sync enable enable bucket sync\n";
cout << " bucket radoslist list rados objects backing bucket's objects\n";
cout << " bi get retrieve bucket index object entries\n";
cout << " bi put store bucket index object entries\n";
cout << " bi list list raw bucket index entries\n";
cout << " bi purge purge bucket index entries\n";
cout << " object rm remove object\n";
cout << " object put put object\n";
cout << " object stat stat an object for its metadata\n";
cout << " object unlink unlink object from bucket index\n";
cout << " object rewrite rewrite the specified object\n";
cout << " objects expire run expired objects cleanup\n";
cout << " objects expire-stale list list stale expired objects (caused by reshard)\n";
cout << " objects expire-stale rm remove stale expired objects\n";
cout << " period rm remove a period\n";
cout << " period get get period info\n";
cout << " period get-current get current period info\n";
cout << " period pull pull a period\n";
cout << " period push push a period\n";
cout << " period list list all periods\n";
cout << " period update update the staging period\n";
cout << " period commit commit the staging period\n";
cout << " quota set set quota params\n";
cout << " quota enable enable quota\n";
cout << " quota disable disable quota\n";
cout << " global quota get view global quota params\n";
cout << " global quota set set global quota params\n";
cout << " global quota enable enable a global quota\n";
cout << " global quota disable disable a global quota\n";
cout << " realm create create a new realm\n";
cout << " realm rm remove a realm\n";
cout << " realm get show realm info\n";
cout << " realm get-default get default realm name\n";
cout << " realm list list realms\n";
cout << " realm list-periods list all realm periods\n";
cout << " realm rename rename a realm\n";
cout << " realm set set realm info (requires infile)\n";
cout << " realm default set realm as default\n";
cout << " realm pull pull a realm and its current period\n";
cout << " zonegroup add add a zone to a zonegroup\n";
cout << " zonegroup create create a new zone group info\n";
cout << " zonegroup default set default zone group\n";
cout << " zonegroup delete delete a zone group info\n";
cout << " zonegroup get show zone group info\n";
cout << " zonegroup modify modify an existing zonegroup\n";
cout << " zonegroup set set zone group info (requires infile)\n";
cout << " zonegroup rm remove a zone from a zonegroup\n";
cout << " zonegroup rename rename a zone group\n";
cout << " zonegroup list list all zone groups set on this cluster\n";
cout << " zonegroup placement list list zonegroup's placement targets\n";
cout << " zonegroup placement get get a placement target of a specific zonegroup\n";
cout << " zonegroup placement add add a placement target id to a zonegroup\n";
cout << " zonegroup placement modify modify a placement target of a specific zonegroup\n";
cout << " zonegroup placement rm remove a placement target from a zonegroup\n";
cout << " zonegroup placement default set a zonegroup's default placement target\n";
cout << " zone create create a new zone\n";
cout << " zone rm remove a zone\n";
cout << " zone get show zone cluster params\n";
cout << " zone modify modify an existing zone\n";
cout << " zone set set zone cluster params (requires infile)\n";
cout << " zone list list all zones set on this cluster\n";
cout << " zone rename rename a zone\n";
cout << " zone placement list list zone's placement targets\n";
cout << " zone placement get get a zone placement target\n";
cout << " zone placement add add a zone placement target\n";
cout << " zone placement modify modify a zone placement target\n";
cout << " zone placement rm remove a zone placement target\n";
cout << " metadata sync status get metadata sync status\n";
cout << " metadata sync init init metadata sync\n";
cout << " metadata sync run run metadata sync\n";
cout << " data sync status get data sync status of the specified source zone\n";
cout << " data sync init init data sync for the specified source zone\n";
cout << " data sync run run data sync for the specified source zone\n";
cout << " pool add add an existing pool for data placement\n";
cout << " pool rm remove an existing pool from data placement set\n";
cout << " pools list list placement active set\n";
cout << " policy read bucket/object policy\n";
cout << " log list list log objects\n";
cout << " log show dump a log from specific object or (bucket + date\n";
cout << " + bucket-id)\n";
cout << " (NOTE: required to specify formatting of date\n";
cout << " to \"YYYY-MM-DD-hh\")\n";
cout << " log rm remove log object\n";
cout << " usage show show usage (by user, by bucket, date range)\n";
cout << " usage trim trim usage (by user, by bucket, date range)\n";
cout << " usage clear reset all the usage stats for the cluster\n";
cout << " gc list dump expired garbage collection objects (specify\n";
cout << " --include-all to list all entries, including unexpired)\n";
cout << " gc process manually process garbage (specify\n";
cout << " --include-all to process all entries, including unexpired)\n";
cout << " lc list list all bucket lifecycle progress\n";
cout << " lc get get a lifecycle bucket configuration\n";
cout << " lc process manually process lifecycle\n";
cout << " lc reshard fix fix LC for a resharded bucket\n";
cout << " metadata get get metadata info\n";
cout << " metadata put put metadata info\n";
cout << " metadata rm remove metadata info\n";
cout << " metadata list list metadata info\n";
cout << " mdlog list list metadata log\n";
cout << " mdlog trim trim metadata log (use marker)\n";
cout << " mdlog status read metadata log status\n";
cout << " bilog list list bucket index log\n";
cout << " bilog trim trim bucket index log (use start-marker, end-marker)\n";
cout << " bilog status read bucket index log status\n";
cout << " datalog list list data log\n";
cout << " datalog trim trim data log\n";
cout << " datalog status read data log status\n";
cout << " datalog type change datalog type to --log_type={fifo,omap}\n";
cout << " orphans find deprecated -- init and run search for leaked rados objects (use job-id, pool)\n";
cout << " orphans finish deprecated -- clean up search for leaked rados objects\n";
cout << " orphans list-jobs deprecated -- list the current job-ids for orphans search\n";
cout << " * the three 'orphans' sub-commands are now deprecated; consider using the `rgw-orphan-list` tool\n";
cout << " role create create a AWS role for use with STS\n";
cout << " role rm remove a role\n";
cout << " role get get a role\n";
cout << " role list list roles with specified path prefix\n";
cout << " role modify modify the assume role policy of an existing role\n";
cout << " role-policy put add/update permission policy to role\n";
cout << " role-policy list list policies attached to a role\n";
cout << " role-policy get get the specified inline policy document embedded with the given role\n";
cout << " role-policy rm remove policy attached to a role\n";
cout << " reshard add schedule a resharding of a bucket\n";
cout << " reshard list list all bucket resharding or scheduled to be resharded\n";
cout << " reshard status read bucket resharding status\n";
cout << " reshard process process of scheduled reshard jobs\n";
cout << " reshard cancel cancel resharding a bucket\n";
cout << " reshard stale-instances list list stale-instances from bucket resharding\n";
cout << " reshard stale-instances rm cleanup stale-instances from bucket resharding\n";
cout << " sync error list list sync error\n";
cout << " sync error trim trim sync error\n";
cout << " mfa create create a new MFA TOTP token\n";
cout << " mfa list list MFA TOTP tokens\n";
cout << " mfa get show MFA TOTP token\n";
cout << " mfa remove delete MFA TOTP token\n";
cout << " mfa check check MFA TOTP token\n";
cout << " mfa resync re-sync MFA TOTP token\n";
cout << " topic list list bucket notifications/pubsub topics\n";
cout << " topic get get a bucket notifications/pubsub topic\n";
cout << " topic rm remove a bucket notifications/pubsub topic\n";
cout << " subscription get get a pubsub subscription definition\n";
cout << " subscription rm remove a pubsub subscription\n";
cout << " subscription pull show events in a pubsub subscription\n";
cout << " subscription ack ack (remove) an events in a pubsub subscription\n";
cout << " script put upload a lua script to a context\n";
cout << " script get get the lua script of a context\n";
cout << " script rm remove the lua scripts of a context\n";
cout << " script-package add add a lua package to the scripts allowlist\n";
cout << " script-package rm remove a lua package from the scripts allowlist\n";
cout << " script-package list get the lua packages allowlist\n";
cout << "options:\n";
cout << " --tenant=<tenant> tenant name\n";
cout << " --user_ns=<namespace> namespace of user (oidc in case of users authenticated with oidc provider)\n";
cout << " --uid=<id> user id\n";
cout << " --new-uid=<id> new user id\n";
cout << " --subuser=<name> subuser name\n";
cout << " --access-key=<key> S3 access key\n";
cout << " --email=<email> user's email address\n";
cout << " --secret/--secret-key=<key>\n";
cout << " specify secret key\n";
cout << " --gen-access-key generate random access key (for S3)\n";
cout << " --gen-secret generate random secret key\n";
cout << " --key-type=<type> key type, options are: swift, s3\n";
cout << " --temp-url-key[-2]=<key> temp url key\n";
cout << " --access=<access> Set access permissions for sub-user, should be one\n";
cout << " of read, write, readwrite, full\n";
cout << " --display-name=<name> user's display name\n";
cout << " --max-buckets max number of buckets for a user\n";
cout << " --admin set the admin flag on the user\n";
cout << " --system set the system flag on the user\n";
cout << " --op-mask set the op mask on the user\n";
cout << " --bucket=<bucket> Specify the bucket name. Also used by the quota command.\n";
cout << " --pool=<pool> Specify the pool name. Also used to scan for leaked rados objects.\n";
cout << " --object=<object> object name\n";
cout << " --object-version=<version> object version\n";
cout << " --date=<date> date in the format yyyy-mm-dd\n";
cout << " --start-date=<date> start date in the format yyyy-mm-dd\n";
cout << " --end-date=<date> end date in the format yyyy-mm-dd\n";
cout << " --bucket-id=<bucket-id> bucket id\n";
cout << " --bucket-new-name=<bucket>\n";
cout << " for bucket link: optional new name\n";
cout << " --shard-id=<shard-id> optional for: \n";
cout << " mdlog list\n";
cout << " data sync status\n";
cout << " required for: \n";
cout << " mdlog trim\n";
cout << " --max-entries=<entries> max entries for listing operations\n";
cout << " --metadata-key=<key> key to retrieve metadata from with metadata get\n";
cout << " --remote=<remote> zone or zonegroup id of remote gateway\n";
cout << " --period=<id> period id\n";
cout << " --url=<url> url for pushing/pulling period/realm\n";
cout << " --epoch=<number> period epoch\n";
cout << " --commit commit the period during 'period update'\n";
cout << " --staging get staging period info\n";
cout << " --master set as master\n";
cout << " --master-zone=<id> master zone id\n";
cout << " --rgw-realm=<name> realm name\n";
cout << " --realm-id=<id> realm id\n";
cout << " --realm-new-name=<name> realm new name\n";
cout << " --rgw-zonegroup=<name> zonegroup name\n";
cout << " --zonegroup-id=<id> zonegroup id\n";
cout << " --zonegroup-new-name=<name>\n";
cout << " zonegroup new name\n";
cout << " --rgw-zone=<name> name of zone in which radosgw is running\n";
cout << " --zone-id=<id> zone id\n";
cout << " --zone-new-name=<name> zone new name\n";
cout << " --source-zone specify the source zone (for data sync)\n";
cout << " --default set entity (realm, zonegroup, zone) as default\n";
cout << " --read-only set zone as read-only (when adding to zonegroup)\n";
cout << " --redirect-zone specify zone id to redirect when response is 404 (not found)\n";
cout << " --placement-id placement id for zonegroup placement commands\n";
cout << " --storage-class storage class for zonegroup placement commands\n";
cout << " --tags=<list> list of tags for zonegroup placement add and modify commands\n";
cout << " --tags-add=<list> list of tags to add for zonegroup placement modify command\n";
cout << " --tags-rm=<list> list of tags to remove for zonegroup placement modify command\n";
cout << " --endpoints=<list> zone endpoints\n";
cout << " --index-pool=<pool> placement target index pool\n";
cout << " --data-pool=<pool> placement target data pool\n";
cout << " --data-extra-pool=<pool> placement target data extra (non-ec) pool\n";
cout << " --placement-index-type=<type>\n";
cout << " placement target index type (normal, indexless, or #id)\n";
cout << " --compression=<type> placement target compression type (plugin name or empty/none)\n";
cout << " --tier-type=<type> zone tier type\n";
cout << " --tier-config=<k>=<v>[,...]\n";
cout << " set zone tier config keys, values\n";
cout << " --tier-config-rm=<k>[,...]\n";
cout << " unset zone tier config keys\n";
cout << " --sync-from-all[=false] set/reset whether zone syncs from all zonegroup peers\n";
cout << " --sync-from=[zone-name][,...]\n";
cout << " set list of zones to sync from\n";
cout << " --sync-from-rm=[zone-name][,...]\n";
cout << " remove zones from list of zones to sync from\n";
cout << " --bucket-index-max-shards override a zone/zonegroup's default bucket index shard count\n";
cout << " --fix besides checking bucket index, will also fix it\n";
cout << " --check-objects bucket check: rebuilds bucket index according to\n";
cout << " actual objects state\n";
cout << " --format=<format> specify output format for certain operations: xml,\n";
cout << " json\n";
cout << " --purge-data when specified, user removal will also purge all the\n";
cout << " user data\n";
cout << " --purge-keys when specified, subuser removal will also purge all the\n";
cout << " subuser keys\n";
cout << " --purge-objects remove a bucket's objects before deleting it\n";
cout << " (NOTE: required to delete a non-empty bucket)\n";
cout << " --sync-stats option to 'user stats', update user stats with current\n";
cout << " stats reported by user's buckets indexes\n";
cout << " --reset-stats option to 'user stats', reset stats in accordance with user buckets\n";
cout << " --show-log-entries=<flag> enable/disable dump of log entries on log show\n";
cout << " --show-log-sum=<flag> enable/disable dump of log summation on log show\n";
cout << " --skip-zero-entries log show only dumps entries that don't have zero value\n";
cout << " in one of the numeric field\n";
cout << " --infile=<file> specify a file to read in when setting data\n";
cout << " --categories=<list> comma separated list of categories, used in usage show\n";
cout << " --caps=<caps> list of caps (e.g., \"usage=read, write; user=read\")\n";
cout << " --op-mask=<op-mask> permission of user's operations (e.g., \"read, write, delete, *\")\n";
cout << " --yes-i-really-mean-it required for certain operations\n";
cout << " --warnings-only when specified with bucket limit check, list\n";
cout << " only buckets nearing or over the current max\n";
cout << " objects per shard value\n";
cout << " --bypass-gc when specified with bucket deletion, triggers\n";
cout << " object deletions by not involving GC\n";
cout << " --inconsistent-index when specified with bucket deletion and bypass-gc set to true,\n";
cout << " ignores bucket index consistency\n";
cout << " --min-rewrite-size min object size for bucket rewrite (default 4M)\n";
cout << " --max-rewrite-size max object size for bucket rewrite (default ULLONG_MAX)\n";
cout << " --min-rewrite-stripe-size min stripe size for object rewrite (default 0)\n";
cout << " --trim-delay-ms time interval in msec to limit the frequency of sync error log entries trimming operations,\n";
cout << " the trimming process will sleep the specified msec for every 1000 entries trimmed\n";
cout << " --max-concurrent-ios maximum concurrent ios for bucket operations (default: 32)\n";
cout << "\n";
cout << "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
cout << "\nQuota options:\n";
cout << " --max-objects specify max objects (negative value to disable)\n";
cout << " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
cout << " --quota-scope scope of quota (bucket, user)\n";
cout << "\nOrphans search options:\n";
cout << " --num-shards num of shards to use for keeping the temporary scan info\n";
cout << " --orphan-stale-secs num of seconds to wait before declaring an object to be an orphan (default: 86400)\n";
cout << " --job-id set the job id (for orphans find)\n";
cout << " --detail detailed mode, log and stat head objects as well\n";
cout << "\nOrphans list-jobs options:\n";
cout << " --extra-info provide extra info in job list\n";
cout << "\nRole options:\n";
cout << " --role-name name of the role to create\n";
cout << " --path path to the role\n";
cout << " --assume-role-policy-doc the trust relationship policy document that grants an entity permission to assume the role\n";
cout << " --policy-name name of the policy document\n";
cout << " --policy-doc permission policy document\n";
cout << " --path-prefix path prefix for filtering roles\n";
cout << "\nMFA options:\n";
cout << " --totp-serial a string that represents the ID of a TOTP token\n";
cout << " --totp-seed the secret seed that is used to calculate the TOTP\n";
cout << " --totp-seconds the time resolution that is being used for TOTP generation\n";
cout << " --totp-window the number of TOTP tokens that are checked before and after the current token when validating token\n";
cout << " --totp-pin the valid value of a TOTP token at a certain time\n";
cout << "\nBucket notifications/pubsub options:\n";
cout << " --topic bucket notifications/pubsub topic name\n";
cout << " --subscription pubsub subscription name\n";
cout << " --event-id event id in a pubsub subscription\n";
cout << "\nScript options:\n";
cout << " --context context in which the script runs. one of: preRequest, postRequest\n";
cout << " --package name of the lua package that should be added/removed to/from the allowlist\n";
cout << " --allow-compilation package is allowed to compile C code as part of its installation\n";
cout << "\nradoslist options:\n";
cout << " --rgw-obj-fs the field separator that will separate the rados\n";
cout << " object name from the rgw object name;\n";
cout << " additionally rados objects for incomplete\n";
cout << " multipart uploads will not be output\n";
cout << "\n";
generic_client_usage();
}
class SimpleCmd {
public:
struct Def {
string cmd;
std::any opt;
};
using Aliases = std::vector<std::set<string> >;
using Commands = std::vector<Def>;
private:
struct Node {
map<string, Node> next;
set<string> expected; /* separate un-normalized list */
std::any opt;
};
Node cmd_root;
map<string, string> alias_map;
string normalize_alias(const string& s) const {
auto iter = alias_map.find(s);
if (iter == alias_map.end()) {
return s;
}
return iter->second;
}
void init_alias_map(Aliases& aliases) {
for (auto& alias_set : aliases) {
std::optional<string> first;
for (auto& alias : alias_set) {
if (!first) {
first = alias;
} else {
alias_map[alias] = *first;
}
}
}
}
bool gen_next_expected(Node *node, vector<string> *expected, bool ret) {
for (auto& next_cmd : node->expected) {
expected->push_back(next_cmd);
}
return ret;
}
Node root;
public:
SimpleCmd() {}
SimpleCmd(std::optional<Commands> cmds,
std::optional<Aliases> aliases) {
if (aliases) {
add_aliases(*aliases);
}
if (cmds) {
add_commands(*cmds);
}
}
void add_aliases(Aliases& aliases) {
init_alias_map(aliases);
}
void add_commands(std::vector<Def>& cmds) {
for (auto& cmd : cmds) {
vector<string> words;
get_str_vec(cmd.cmd, " ", words);
auto node = &cmd_root;
for (auto& word : words) {
auto norm = normalize_alias(word);
auto parent = node;
node->expected.insert(word);
node = &node->next[norm];
if (norm == "[*]") { /* optional param at the end */
parent->next["*"] = *node; /* can be also looked up by '*' */
parent->opt = cmd.opt;
}
}
node->opt = cmd.opt;
}
}
template <class Container>
bool find_command(Container& args,
std::any *opt_cmd,
vector<string> *extra_args,
string *error,
vector<string> *expected) {
auto node = &cmd_root;
std::optional<std::any> found_opt;
for (auto& arg : args) {
string norm = normalize_alias(arg);
auto iter = node->next.find(norm);
if (iter == node->next.end()) {
iter = node->next.find("*");
if (iter == node->next.end()) {
*error = string("ERROR: Unrecognized argument: '") + arg + "'";
return gen_next_expected(node, expected, false);
}
extra_args->push_back(arg);
if (!found_opt) {
found_opt = node->opt;
}
}
node = &(iter->second);
}
*opt_cmd = found_opt.value_or(node->opt);
if (!opt_cmd->has_value()) {
*error ="ERROR: Unknown command";
return gen_next_expected(node, expected, false);
}
return true;
}
};
namespace rgw_admin {
enum class OPT {
NO_CMD,
USER_CREATE,
USER_INFO,
USER_MODIFY,
USER_RENAME,
USER_RM,
USER_SUSPEND,
USER_ENABLE,
USER_CHECK,
USER_STATS,
USER_LIST,
SUBUSER_CREATE,
SUBUSER_MODIFY,
SUBUSER_RM,
KEY_CREATE,
KEY_RM,
BUCKETS_LIST,
BUCKET_LIMIT_CHECK,
BUCKET_LINK,
BUCKET_UNLINK,
BUCKET_STATS,
BUCKET_CHECK,
BUCKET_SYNC_CHECKPOINT,
BUCKET_SYNC_INFO,
BUCKET_SYNC_STATUS,
BUCKET_SYNC_MARKERS,
BUCKET_SYNC_INIT,
BUCKET_SYNC_RUN,
BUCKET_SYNC_DISABLE,
BUCKET_SYNC_ENABLE,
BUCKET_RM,
BUCKET_REWRITE,
BUCKET_RESHARD,
BUCKET_CHOWN,
BUCKET_RADOS_LIST,
POLICY,
POOL_ADD,
POOL_RM,
POOLS_LIST,
LOG_LIST,
LOG_SHOW,
LOG_RM,
USAGE_SHOW,
USAGE_TRIM,
USAGE_CLEAR,
OBJECT_PUT,
OBJECT_RM,
OBJECT_UNLINK,
OBJECT_STAT,
OBJECT_REWRITE,
OBJECTS_EXPIRE,
OBJECTS_EXPIRE_STALE_LIST,
OBJECTS_EXPIRE_STALE_RM,
BI_GET,
BI_PUT,
BI_LIST,
BI_PURGE,
OLH_GET,
OLH_READLOG,
QUOTA_SET,
QUOTA_ENABLE,
QUOTA_DISABLE,
GC_LIST,
GC_PROCESS,
LC_LIST,
LC_GET,
LC_PROCESS,
LC_RESHARD_FIX,
ORPHANS_FIND,
ORPHANS_FINISH,
ORPHANS_LIST_JOBS,
ZONEGROUP_ADD,
ZONEGROUP_CREATE,
ZONEGROUP_DEFAULT,
ZONEGROUP_DELETE,
ZONEGROUP_GET,
ZONEGROUP_MODIFY,
ZONEGROUP_SET,
ZONEGROUP_LIST,
ZONEGROUP_REMOVE,
ZONEGROUP_RENAME,
ZONEGROUP_PLACEMENT_ADD,
ZONEGROUP_PLACEMENT_MODIFY,
ZONEGROUP_PLACEMENT_RM,
ZONEGROUP_PLACEMENT_LIST,
ZONEGROUP_PLACEMENT_GET,
ZONEGROUP_PLACEMENT_DEFAULT,
ZONE_CREATE,
ZONE_DELETE,
ZONE_GET,
ZONE_MODIFY,
ZONE_SET,
ZONE_LIST,
ZONE_RENAME,
ZONE_DEFAULT,
ZONE_PLACEMENT_ADD,
ZONE_PLACEMENT_MODIFY,
ZONE_PLACEMENT_RM,
ZONE_PLACEMENT_LIST,
ZONE_PLACEMENT_GET,
CAPS_ADD,
CAPS_RM,
METADATA_GET,
METADATA_PUT,
METADATA_RM,
METADATA_LIST,
METADATA_SYNC_STATUS,
METADATA_SYNC_INIT,
METADATA_SYNC_RUN,
MDLOG_LIST,
MDLOG_AUTOTRIM,
MDLOG_TRIM,
MDLOG_FETCH,
MDLOG_STATUS,
SYNC_ERROR_LIST,
SYNC_ERROR_TRIM,
SYNC_GROUP_CREATE,
SYNC_GROUP_MODIFY,
SYNC_GROUP_GET,
SYNC_GROUP_REMOVE,
SYNC_GROUP_FLOW_CREATE,
SYNC_GROUP_FLOW_REMOVE,
SYNC_GROUP_PIPE_CREATE,
SYNC_GROUP_PIPE_MODIFY,
SYNC_GROUP_PIPE_REMOVE,
SYNC_POLICY_GET,
BILOG_LIST,
BILOG_TRIM,
BILOG_STATUS,
BILOG_AUTOTRIM,
DATA_SYNC_STATUS,
DATA_SYNC_INIT,
DATA_SYNC_RUN,
DATALOG_LIST,
DATALOG_STATUS,
DATALOG_AUTOTRIM,
DATALOG_TRIM,
DATALOG_TYPE,
DATALOG_PRUNE,
REALM_CREATE,
REALM_DELETE,
REALM_GET,
REALM_GET_DEFAULT,
REALM_LIST,
REALM_LIST_PERIODS,
REALM_RENAME,
REALM_SET,
REALM_DEFAULT,
REALM_PULL,
PERIOD_DELETE,
PERIOD_GET,
PERIOD_GET_CURRENT,
PERIOD_PULL,
PERIOD_PUSH,
PERIOD_LIST,
PERIOD_UPDATE,
PERIOD_COMMIT,
GLOBAL_QUOTA_GET,
GLOBAL_QUOTA_SET,
GLOBAL_QUOTA_ENABLE,
GLOBAL_QUOTA_DISABLE,
SYNC_INFO,
SYNC_STATUS,
ROLE_CREATE,
ROLE_DELETE,
ROLE_GET,
ROLE_MODIFY,
ROLE_LIST,
ROLE_POLICY_PUT,
ROLE_POLICY_LIST,
ROLE_POLICY_GET,
ROLE_POLICY_DELETE,
RESHARD_ADD,
RESHARD_LIST,
RESHARD_STATUS,
RESHARD_PROCESS,
RESHARD_CANCEL,
MFA_CREATE,
MFA_REMOVE,
MFA_GET,
MFA_LIST,
MFA_CHECK,
MFA_RESYNC,
RESHARD_STALE_INSTANCES_LIST,
RESHARD_STALE_INSTANCES_DELETE,
PUBSUB_TOPICS_LIST,
// TODO add "subscription list" command
PUBSUB_TOPIC_GET,
PUBSUB_TOPIC_RM,
PUBSUB_SUB_GET,
PUBSUB_SUB_RM,
PUBSUB_SUB_PULL,
PUBSUB_EVENT_RM,
SCRIPT_PUT,
SCRIPT_GET,
SCRIPT_RM,
SCRIPT_PACKAGE_ADD,
SCRIPT_PACKAGE_RM,
SCRIPT_PACKAGE_LIST
};
}
using namespace rgw_admin;
static SimpleCmd::Commands all_cmds = {
{ "user create", OPT::USER_CREATE },
{ "user info", OPT::USER_INFO },
{ "user modify", OPT::USER_MODIFY },
{ "user rename", OPT::USER_RENAME },
{ "user rm", OPT::USER_RM },
{ "user suspend", OPT::USER_SUSPEND },
{ "user enable", OPT::USER_ENABLE },
{ "user check", OPT::USER_CHECK },
{ "user stats", OPT::USER_STATS },
{ "user list", OPT::USER_LIST },
{ "subuser create", OPT::SUBUSER_CREATE },
{ "subuser modify", OPT::SUBUSER_MODIFY },
{ "subuser rm", OPT::SUBUSER_RM },
{ "key create", OPT::KEY_CREATE },
{ "key rm", OPT::KEY_RM },
{ "buckets list", OPT::BUCKETS_LIST },
{ "bucket list", OPT::BUCKETS_LIST },
{ "bucket limit check", OPT::BUCKET_LIMIT_CHECK },
{ "bucket link", OPT::BUCKET_LINK },
{ "bucket unlink", OPT::BUCKET_UNLINK },
{ "bucket stats", OPT::BUCKET_STATS },
{ "bucket check", OPT::BUCKET_CHECK },
{ "bucket sync checkpoint", OPT::BUCKET_SYNC_CHECKPOINT },
{ "bucket sync info", OPT::BUCKET_SYNC_INFO },
{ "bucket sync status", OPT::BUCKET_SYNC_STATUS },
{ "bucket sync markers", OPT::BUCKET_SYNC_MARKERS },
{ "bucket sync init", OPT::BUCKET_SYNC_INIT },
{ "bucket sync run", OPT::BUCKET_SYNC_RUN },
{ "bucket sync disable", OPT::BUCKET_SYNC_DISABLE },
{ "bucket sync enable", OPT::BUCKET_SYNC_ENABLE },
{ "bucket rm", OPT::BUCKET_RM },
{ "bucket rewrite", OPT::BUCKET_REWRITE },
{ "bucket reshard", OPT::BUCKET_RESHARD },
{ "bucket chown", OPT::BUCKET_CHOWN },
{ "bucket radoslist", OPT::BUCKET_RADOS_LIST },
{ "bucket rados list", OPT::BUCKET_RADOS_LIST },
{ "policy", OPT::POLICY },
{ "pool add", OPT::POOL_ADD },
{ "pool rm", OPT::POOL_RM },
{ "pool list", OPT::POOLS_LIST },
{ "pools list", OPT::POOLS_LIST },
{ "log list", OPT::LOG_LIST },
{ "log show", OPT::LOG_SHOW },
{ "log rm", OPT::LOG_RM },
{ "usage show", OPT::USAGE_SHOW },
{ "usage trim", OPT::USAGE_TRIM },
{ "usage clear", OPT::USAGE_CLEAR },
{ "object put", OPT::OBJECT_PUT },
{ "object rm", OPT::OBJECT_RM },
{ "object unlink", OPT::OBJECT_UNLINK },
{ "object stat", OPT::OBJECT_STAT },
{ "object rewrite", OPT::OBJECT_REWRITE },
{ "objects expire", OPT::OBJECTS_EXPIRE },
{ "objects expire-stale list", OPT::OBJECTS_EXPIRE_STALE_LIST },
{ "objects expire-stale rm", OPT::OBJECTS_EXPIRE_STALE_RM },
{ "bi get", OPT::BI_GET },
{ "bi put", OPT::BI_PUT },
{ "bi list", OPT::BI_LIST },
{ "bi purge", OPT::BI_PURGE },
{ "olh get", OPT::OLH_GET },
{ "olh readlog", OPT::OLH_READLOG },
{ "quota set", OPT::QUOTA_SET },
{ "quota enable", OPT::QUOTA_ENABLE },
{ "quota disable", OPT::QUOTA_DISABLE },
{ "gc list", OPT::GC_LIST },
{ "gc process", OPT::GC_PROCESS },
{ "lc list", OPT::LC_LIST },
{ "lc get", OPT::LC_GET },
{ "lc process", OPT::LC_PROCESS },
{ "lc reshard fix", OPT::LC_RESHARD_FIX },
{ "orphans find", OPT::ORPHANS_FIND },
{ "orphans finish", OPT::ORPHANS_FINISH },
{ "orphans list jobs", OPT::ORPHANS_LIST_JOBS },
{ "orphans list-jobs", OPT::ORPHANS_LIST_JOBS },
{ "zonegroup add", OPT::ZONEGROUP_ADD },
{ "zonegroup create", OPT::ZONEGROUP_CREATE },
{ "zonegroup default", OPT::ZONEGROUP_DEFAULT },
{ "zonegroup delete", OPT::ZONEGROUP_DELETE },
{ "zonegroup get", OPT::ZONEGROUP_GET },
{ "zonegroup modify", OPT::ZONEGROUP_MODIFY },
{ "zonegroup set", OPT::ZONEGROUP_SET },
{ "zonegroup list", OPT::ZONEGROUP_LIST },
{ "zonegroups list", OPT::ZONEGROUP_LIST },
{ "zonegroup remove", OPT::ZONEGROUP_REMOVE },
{ "zonegroup remove zone", OPT::ZONEGROUP_REMOVE },
{ "zonegroup rename", OPT::ZONEGROUP_RENAME },
{ "zonegroup placement add", OPT::ZONEGROUP_PLACEMENT_ADD },
{ "zonegroup placement modify", OPT::ZONEGROUP_PLACEMENT_MODIFY },
{ "zonegroup placement rm", OPT::ZONEGROUP_PLACEMENT_RM },
{ "zonegroup placement list", OPT::ZONEGROUP_PLACEMENT_LIST },
{ "zonegroup placement get", OPT::ZONEGROUP_PLACEMENT_GET },
{ "zonegroup placement default", OPT::ZONEGROUP_PLACEMENT_DEFAULT },
{ "zone create", OPT::ZONE_CREATE },
{ "zone delete", OPT::ZONE_DELETE },
{ "zone get", OPT::ZONE_GET },
{ "zone modify", OPT::ZONE_MODIFY },
{ "zone set", OPT::ZONE_SET },
{ "zone list", OPT::ZONE_LIST },
{ "zones list", OPT::ZONE_LIST },
{ "zone rename", OPT::ZONE_RENAME },
{ "zone default", OPT::ZONE_DEFAULT },
{ "zone placement add", OPT::ZONE_PLACEMENT_ADD },
{ "zone placement modify", OPT::ZONE_PLACEMENT_MODIFY },
{ "zone placement rm", OPT::ZONE_PLACEMENT_RM },
{ "zone placement list", OPT::ZONE_PLACEMENT_LIST },
{ "zone placement get", OPT::ZONE_PLACEMENT_GET },
{ "caps add", OPT::CAPS_ADD },
{ "caps rm", OPT::CAPS_RM },
{ "metadata get [*]", OPT::METADATA_GET },
{ "metadata put [*]", OPT::METADATA_PUT },
{ "metadata rm [*]", OPT::METADATA_RM },
{ "metadata list [*]", OPT::METADATA_LIST },
{ "metadata sync status", OPT::METADATA_SYNC_STATUS },
{ "metadata sync init", OPT::METADATA_SYNC_INIT },
{ "metadata sync run", OPT::METADATA_SYNC_RUN },
{ "mdlog list", OPT::MDLOG_LIST },
{ "mdlog autotrim", OPT::MDLOG_AUTOTRIM },
{ "mdlog trim", OPT::MDLOG_TRIM },
{ "mdlog fetch", OPT::MDLOG_FETCH },
{ "mdlog status", OPT::MDLOG_STATUS },
{ "sync error list", OPT::SYNC_ERROR_LIST },
{ "sync error trim", OPT::SYNC_ERROR_TRIM },
{ "sync policy get", OPT::SYNC_POLICY_GET },
{ "sync group create", OPT::SYNC_GROUP_CREATE },
{ "sync group modify", OPT::SYNC_GROUP_MODIFY },
{ "sync group get", OPT::SYNC_GROUP_GET },
{ "sync group remove", OPT::SYNC_GROUP_REMOVE },
{ "sync group flow create", OPT::SYNC_GROUP_FLOW_CREATE },
{ "sync group flow remove", OPT::SYNC_GROUP_FLOW_REMOVE },
{ "sync group pipe create", OPT::SYNC_GROUP_PIPE_CREATE },
{ "sync group pipe modify", OPT::SYNC_GROUP_PIPE_MODIFY },
{ "sync group pipe remove", OPT::SYNC_GROUP_PIPE_REMOVE },
{ "bilog list", OPT::BILOG_LIST },
{ "bilog trim", OPT::BILOG_TRIM },
{ "bilog status", OPT::BILOG_STATUS },
{ "bilog autotrim", OPT::BILOG_AUTOTRIM },
{ "data sync status", OPT::DATA_SYNC_STATUS },
{ "data sync init", OPT::DATA_SYNC_INIT },
{ "data sync run", OPT::DATA_SYNC_RUN },
{ "datalog list", OPT::DATALOG_LIST },
{ "datalog status", OPT::DATALOG_STATUS },
{ "datalog autotrim", OPT::DATALOG_AUTOTRIM },
{ "datalog trim", OPT::DATALOG_TRIM },
{ "datalog type", OPT::DATALOG_TYPE },
{ "datalog prune", OPT::DATALOG_PRUNE },
{ "realm create", OPT::REALM_CREATE },
{ "realm delete", OPT::REALM_DELETE },
{ "realm get", OPT::REALM_GET },
{ "realm get default", OPT::REALM_GET_DEFAULT },
{ "realm get-default", OPT::REALM_GET_DEFAULT },
{ "realm list", OPT::REALM_LIST },
{ "realm list periods", OPT::REALM_LIST_PERIODS },
{ "realm list-periods", OPT::REALM_LIST_PERIODS },
{ "realm rename", OPT::REALM_RENAME },
{ "realm set", OPT::REALM_SET },
{ "realm default", OPT::REALM_DEFAULT },
{ "realm pull", OPT::REALM_PULL },
{ "period delete", OPT::PERIOD_DELETE },
{ "period get", OPT::PERIOD_GET },
{ "period get-current", OPT::PERIOD_GET_CURRENT },
{ "period get current", OPT::PERIOD_GET_CURRENT },
{ "period pull", OPT::PERIOD_PULL },
{ "period push", OPT::PERIOD_PUSH },
{ "period list", OPT::PERIOD_LIST },
{ "period update", OPT::PERIOD_UPDATE },
{ "period commit", OPT::PERIOD_COMMIT },
{ "global quota get", OPT::GLOBAL_QUOTA_GET },
{ "global quota set", OPT::GLOBAL_QUOTA_SET },
{ "global quota enable", OPT::GLOBAL_QUOTA_ENABLE },
{ "global quota disable", OPT::GLOBAL_QUOTA_DISABLE },
{ "sync info", OPT::SYNC_INFO },
{ "sync status", OPT::SYNC_STATUS },
{ "role create", OPT::ROLE_CREATE },
{ "role delete", OPT::ROLE_DELETE },
{ "role get", OPT::ROLE_GET },
{ "role modify", OPT::ROLE_MODIFY },
{ "role list", OPT::ROLE_LIST },
{ "role policy put", OPT::ROLE_POLICY_PUT },
{ "role-policy put", OPT::ROLE_POLICY_PUT },
{ "role policy list", OPT::ROLE_POLICY_LIST },
{ "role-policy list", OPT::ROLE_POLICY_LIST },
{ "role policy get", OPT::ROLE_POLICY_GET },
{ "role-policy get", OPT::ROLE_POLICY_GET },
{ "role policy delete", OPT::ROLE_POLICY_DELETE },
{ "role-policy delete", OPT::ROLE_POLICY_DELETE },
{ "reshard bucket", OPT::BUCKET_RESHARD },
{ "reshard add", OPT::RESHARD_ADD },
{ "reshard list", OPT::RESHARD_LIST },
{ "reshard status", OPT::RESHARD_STATUS },
{ "reshard process", OPT::RESHARD_PROCESS },
{ "reshard cancel", OPT::RESHARD_CANCEL },
{ "mfa create", OPT::MFA_CREATE },
{ "mfa remove", OPT::MFA_REMOVE },
{ "mfa get", OPT::MFA_GET },
{ "mfa list", OPT::MFA_LIST },
{ "mfa check", OPT::MFA_CHECK },
{ "mfa resync", OPT::MFA_RESYNC },
{ "reshard stale-instances list", OPT::RESHARD_STALE_INSTANCES_LIST },
{ "reshard stale list", OPT::RESHARD_STALE_INSTANCES_LIST },
{ "reshard stale-instances delete", OPT::RESHARD_STALE_INSTANCES_DELETE },
{ "reshard stale delete", OPT::RESHARD_STALE_INSTANCES_DELETE },
{ "topic list", OPT::PUBSUB_TOPICS_LIST },
{ "topic get", OPT::PUBSUB_TOPIC_GET },
{ "topic rm", OPT::PUBSUB_TOPIC_RM },
{ "subscription get", OPT::PUBSUB_SUB_GET },
{ "subscription rm", OPT::PUBSUB_SUB_RM },
{ "subscription pull", OPT::PUBSUB_SUB_PULL },
{ "subscription ack", OPT::PUBSUB_EVENT_RM },