24
cerr << "usage: radosgw_admin <--user-gen | --user-modify | --read-policy | --list-buckets > [options...]" << std::endl;
25
cerr << "options:" << std::endl;
26
cerr << " --uid=<id> (S3 uid)" << std::endl;
27
cerr << " --auth_uid=<auid> (librados uid)" << std::endl;
28
cerr << " --secret=<key>" << std::endl;
29
cerr << " --email=<email>" << std::endl;
30
cerr << " --display-name=<name>" << std::endl;
31
cerr << " --bucket=<bucket>" << std::endl;
32
cerr << " --object=<object>" << std::endl;
26
cerr << "usage: radosgw_admin <cmd> [options...]" << std::endl;
27
cerr << "commands:\n";
28
cerr << " user create create a new user\n" ;
29
cerr << " user modify modify user\n";
30
cerr << " user info get user info\n";
31
cerr << " user rm remove user\n";
32
cerr << " buckets list list buckets\n";
33
cerr << " bucket unlink unlink bucket from specified user\n";
34
cerr << " policy read bucket/object policy\n";
35
cerr << " log show dump a log from specific bucket, date\n";
37
cerr << " --uid=<id> user id\n";
38
cerr << " --access-key=<id> S3 access key\n";
39
cerr << " --os-user=<group:name> OpenStack user\n";
40
cerr << " --email=<email>\n";
41
cerr << " --auth_uid=<auid> librados uid\n";
42
cerr << " --secret=<key> S3 key\n";
43
cerr << " --os-secret=<key> OpenStack key\n";
44
cerr << " --display-name=<name>\n";
45
cerr << " --bucket=<bucket>\n";
46
cerr << " --object=<object>\n";
47
cerr << " --date=<yyyy-mm-dd>\n";
48
generic_client_usage();
64
static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
67
if (strcmp(cmd, "user") == 0 ||
68
strcmp(cmd, "buckets") == 0 ||
69
strcmp(cmd, "bucket") == 0 ||
70
strcmp(cmd, "log") == 0) {
75
if (strcmp(cmd, "policy") == 0)
81
if (strcmp(prev_cmd, "user") == 0) {
82
if (strcmp(cmd, "create") == 0)
83
return OPT_USER_CREATE;
84
if (strcmp(cmd, "info") == 0)
86
if (strcmp(cmd, "modify") == 0)
87
return OPT_USER_MODIFY;
88
if (strcmp(cmd, "rm") == 0)
90
} else if (strcmp(prev_cmd, "buckets") == 0) {
91
if (strcmp(cmd, "list") == 0)
92
return OPT_BUCKETS_LIST;
93
} else if (strcmp(prev_cmd, "bucket") == 0) {
94
if (strcmp(cmd, "unlink") == 0)
95
return OPT_BUCKET_UNLINK;
96
} else if (strcmp(prev_cmd, "log") == 0) {
97
if (strcmp(cmd, "show") == 0)
37
104
int gen_rand_base64(char *dest, int size) /* size should be the required string size + 1 */
39
unsigned char buf[size];
40
107
char tmp_dest[size + 4]; /* so that there's space for the extra '=' characters, and some */
42
CryptoPP::AutoSeededRandomPool rng;
43
rng.GenerateBlock(buf, sizeof(buf));
45
int ret = ceph_armor(tmp_dest, &tmp_dest[sizeof(tmp_dest)],
110
ret = get_random_bytes(buf, sizeof(buf));
112
cerr << "cannot get random bytes: " << cpp_strerror(-ret) << std::endl;
116
ret = ceph_armor(tmp_dest, &tmp_dest[sizeof(tmp_dest)],
46
117
(const char *)buf, ((const char *)buf) + ((size - 1) * 3 + 4 - 1) / 4);
48
119
cerr << "ceph_armor failed" << std::endl;
82
175
argv_to_vec(argc, (const char **)argv, args);
85
common_set_defaults(true);
86
common_init(args, "rgw", true);
178
common_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
179
keyring_init(&g_conf);
88
181
const char *user_id = 0;
182
const char *access_key = 0;
89
183
const char *secret_key = 0;
90
184
const char *user_email = 0;
91
185
const char *display_name = 0;
92
186
const char *bucket = 0;
93
187
const char *object = 0;
94
bool gen_user = false;
95
bool mod_user = false;
96
bool read_policy = false;
97
bool list_buckets = false;
98
bool delete_user = false;
188
const char *openstack_user = 0;
189
const char *openstack_key = 0;
190
const char *date = 0;
100
191
uint64_t auid = 0;
101
192
RGWUserInfo info;
102
193
RGWAccess *store;
104
if (g_conf.clock_tare) g_clock.tare();
194
const char *prev_cmd = NULL;
195
int opt_cmd = OPT_NO_CMD;
106
198
FOR_EACH_ARG(args) {
107
if (CONF_ARG_EQ("user-gen", 'g')) {
109
} else if (CONF_ARG_EQ("user-modify", 'm')) {
111
} else if (CONF_ARG_EQ("read-policy", 'p')) {
113
} else if (CONF_ARG_EQ("list-buckets", 'l')) {
115
} else if (CONF_ARG_EQ("uid", 'i')) {
116
CONF_SAFE_SET_ARG_VAL(&user_id, OPT_STR);
117
} else if (CONF_ARG_EQ("secret", 's')) {
118
CONF_SAFE_SET_ARG_VAL(&secret_key, OPT_STR);
119
} else if (CONF_ARG_EQ("email", 'e')) {
120
CONF_SAFE_SET_ARG_VAL(&user_email, OPT_STR);
121
} else if (CONF_ARG_EQ("display-name", 'n')) {
122
CONF_SAFE_SET_ARG_VAL(&display_name, OPT_STR);
123
} else if (CONF_ARG_EQ("bucket", 'b')) {
124
CONF_SAFE_SET_ARG_VAL(&bucket, OPT_STR);
125
} else if (CONF_ARG_EQ("object", 'o')) {
126
CONF_SAFE_SET_ARG_VAL(&object, OPT_STR);
127
} else if (CONF_ARG_EQ("auth_uid", 'a')) {
128
CONF_SAFE_SET_ARG_VAL(&auid, OPT_LONGLONG);
129
} else if (CONF_ARG_EQ("delete_user", 'd')) {
199
if (CEPH_ARGPARSE_EQ("uid", 'i')) {
200
CEPH_ARGPARSE_SET_ARG_VAL(&user_id, OPT_STR);
201
} else if (CEPH_ARGPARSE_EQ("access-key", '\0')) {
202
CEPH_ARGPARSE_SET_ARG_VAL(&access_key, OPT_STR);
203
} else if (CEPH_ARGPARSE_EQ("secret", 's')) {
204
CEPH_ARGPARSE_SET_ARG_VAL(&secret_key, OPT_STR);
205
} else if (CEPH_ARGPARSE_EQ("email", 'e')) {
206
CEPH_ARGPARSE_SET_ARG_VAL(&user_email, OPT_STR);
207
} else if (CEPH_ARGPARSE_EQ("display-name", 'n')) {
208
CEPH_ARGPARSE_SET_ARG_VAL(&display_name, OPT_STR);
209
} else if (CEPH_ARGPARSE_EQ("bucket", 'b')) {
210
CEPH_ARGPARSE_SET_ARG_VAL(&bucket, OPT_STR);
211
} else if (CEPH_ARGPARSE_EQ("object", 'o')) {
212
CEPH_ARGPARSE_SET_ARG_VAL(&object, OPT_STR);
213
} else if (CEPH_ARGPARSE_EQ("auth-uid", 'a')) {
214
CEPH_ARGPARSE_SET_ARG_VAL(&auid, OPT_LONGLONG);
215
} else if (CEPH_ARGPARSE_EQ("os-user", '\0')) {
216
CEPH_ARGPARSE_SET_ARG_VAL(&openstack_user, OPT_STR);
217
} else if (CEPH_ARGPARSE_EQ("os-secret", '\0')) {
218
CEPH_ARGPARSE_SET_ARG_VAL(&openstack_key, OPT_STR);
219
} else if (CEPH_ARGPARSE_EQ("date", '\0')) {
220
CEPH_ARGPARSE_SET_ARG_VAL(&date, OPT_STR);
132
cerr << "unrecognized arg " << args[i] << std::endl;
223
opt_cmd = get_cmd(CEPH_ARGPARSE_VAL, prev_cmd, &need_more);
225
cerr << "unrecognized arg " << args[i] << std::endl;
229
prev_cmd = CEPH_ARGPARSE_VAL;
233
cerr << "unrecognized arg " << args[i] << std::endl;
137
store = RGWAccess::init_storage_provider("rados", argc, argv);
239
if (opt_cmd == OPT_NO_CMD)
242
store = RGWAccess::init_storage_provider("rados", &g_conf);
139
244
cerr << "couldn't init storage provider" << std::endl;
248
if (opt_cmd != OPT_USER_CREATE && opt_cmd != OPT_LOG_SHOW && !user_id) {
253
if (rgw_get_user_info_by_email(s, info) >= 0) {
256
cerr << "could not find user by specified email" << std::endl;
259
if (!found && access_key) {
261
if (rgw_get_user_info_by_access_key(s, info) >= 0) {
264
cerr << "could not find user by specified access key" << std::endl;
267
if (!found && openstack_user) {
269
if (rgw_get_user_info_by_openstack(s, info) >= 0) {
272
cerr << "could not find user by specified openstack username" << std::endl;
275
user_id = info.user_id.c_str();
279
if (opt_cmd == OPT_USER_CREATE || opt_cmd == OPT_USER_MODIFY ||
280
opt_cmd == OPT_USER_INFO || opt_cmd == OPT_BUCKET_UNLINK) {
148
282
cerr << "user_id was not specified, aborting" << std::endl;
152
286
string user_id_str = user_id;
154
if (rgw_get_user_info(user_id_str, info) < 0) {
288
if (opt_cmd != OPT_USER_CREATE &&
289
info.user_id.empty() &&
290
rgw_get_user_info_by_uid(user_id_str, info) < 0) {
155
291
cerr << "error reading user info, aborting" << std::endl;
296
if (opt_cmd == OPT_USER_CREATE) {
162
297
char secret_key_buf[SECRET_KEY_LEN + 1];
163
298
char public_id_buf[PUBLIC_ID_LEN + 1];
418
if (opt_cmd == OPT_BUCKET_UNLINK) {
420
cerr << "bucket name was not specified" << std::endl;
423
string bucket_str(bucket);
424
int r = rgw_remove_bucket(user_id, bucket_str);
426
cerr << "error unlinking bucket " << cpp_strerror(-r) << std::endl;
430
if (opt_cmd == OPT_LOG_SHOW) {
431
if (!date || !bucket) {
433
cerr << "date was not specified" << std::endl;
435
cerr << "bucket was not specified" << std::endl;
439
string log_bucket = RGW_LOG_BUCKET_NAME;
442
oid += string(bucket);
444
int r = store->obj_stat(log_bucket, oid, &size, NULL);
446
cerr << "error while doing stat on " << log_bucket << ":" << oid
447
<< " " << cpp_strerror(-r) << std::endl;
451
r = store->read(log_bucket, oid, 0, size, bl);
453
cerr << "error while reading from " << log_bucket << ":" << oid
454
<< " " << cpp_strerror(-r) << std::endl;
458
bufferlist::iterator iter = bl.begin();
460
struct rgw_log_entry entry;
461
const char *delim = " ";
463
while (!iter.end()) {
464
::decode(entry, iter);
466
cout << (entry.owner.size() ? entry.owner : "-" ) << delim
467
<< entry.bucket << delim
468
<< entry.time << delim
469
<< entry.remote_addr << delim
470
<< entry.user << delim
472
<< "\"" << escape_str(entry.uri, '"') << "\"" << delim
473
<< entry.http_status << delim
474
<< entry.error_code << delim
475
<< entry.bytes_sent << delim
476
<< entry.obj_size << delim
477
<< entry.total_time.usec() << delim
478
<< "\"" << escape_str(entry.user_agent, '"') << "\"" << delim
479
<< "\"" << escape_str(entry.referrer, '"') << "\"" << std::endl;
483
if (opt_cmd == OPT_USER_RM) {
271
484
rgw_delete_user(info);