#include "services/svc_zone.h"
#include "services/svc_sys_obj.h"
#include "rgw_zone.h"
+#include "common/ceph_json.h"
#define dout_subsys ceph_subsys_rgw
return 0;
}
+
+static void dump_access_keys(Formatter *f, std::vector<RGWAccessKey>& access_keys)
+{
+ f->open_array_section("keys");
+ for (auto& k : access_keys) {
+ f->open_object_section("key");
+ f->dump_string("access_key", k.id);
+ f->dump_string("secret_key", k.key);
+ f->dump_bool("active", k.active);
+ encode_json("create_date", k.create_date, f);
+ f->close_section();
+ }
+ f->close_section();
+}
+
class RGWOp_User_List : public RGWRESTOp {
public:
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
return;
}
+
op_ret = RGWUserAdminOp_Subuser::create(s, driver, op_state, flusher, y);
}
return;
}
- RGWAccessKey key;
- try {
- key.decode_json(&jp);
- } catch (const JSONDecoder::err& e) {
- cout << "failed to decode JSON input: " << e.what() << std::endl;
- ret = -EINVAL;
- return;
- }
- op_state.op_master_key = std::move(key);
+ if (gen_key) { // if generate-key is false, we simply read the user input key and store them
+ RGWAccessKey key;
+ try {
+ key.decode_json(&jp);
+ } catch (const JSONDecoder::err& e) {
+ Formatter *formatter = flusher.get_formatter();
+ std::vector<RGWAccessKey> access_keys;
+ decode_json_obj(access_keys, &jp);
+ dump_access_keys(formatter, access_keys);
+ return;
+ }
+ op_state.op_master_key = std::move(key);
+ }
// set_generate_key() is not set if keys have already been fetched from master zone
gen_key = false;
}
f->open_object_section("user");
string s;
info.user_id.to_str(s);
- f->dump_format("id", "%s:%s", s.c_str(), u.name.c_str());
- char buf[256];
- rgw_perm_to_str(u.perm_mask, buf, sizeof(buf));
- f->dump_string("permissions", buf);
+ u.dump(f, s);
f->close_section();
}
f->close_section();
f->open_array_section("keys");
for (kiter = info.access_keys.begin(); kiter != info.access_keys.end(); ++kiter) {
RGWAccessKey& k = kiter->second;
- const char *sep = (k.subuser.empty() ? "" : ":");
- const char *subuser = (k.subuser.empty() ? "" : k.subuser.c_str());
f->open_object_section("key");
string s;
info.user_id.to_str(s);
- f->dump_format("user", "%s%s%s", s.c_str(), sep, subuser);
- f->dump_string("access_key", k.id);
- f->dump_string("secret_key", k.key);
- f->dump_bool("active", k.active);
- encode_json("create_date", k.create_date, f);
+ k.dump(f, s, false);
f->close_section();
}
f->close_section();
}
-
-static void dump_master_key(Formatter *f, RGWUserInfo &info)
+static void dump_master_key(Formatter *f, RGWUserInfo& info, RGWAccessKey& k)
{
- f->open_object_section("user_info");
- RGWAccessKey& k = info.master_key;
- const char *sep = (k.subuser.empty() ? "" : ":");
- const char *subuser = (k.subuser.empty() ? "" : k.subuser.c_str());
+ f->open_object_section("key");
string s;
info.user_id.to_str(s);
- f->dump_format("user", "%s%s%s", s.c_str(), sep, subuser);
- f->dump_string("access_key", k.id);
- f->dump_string("secret_key", k.key);
- f->dump_bool("active", k.active);
- encode_json("create_date", k.create_date, f);
+ k.dump(f, s, false);
f->close_section();
}
swift_keys = op_state.get_swift_keys();
access_keys = op_state.get_access_keys();
- master_key = op_state.get_master_key();
keys_allowed = true;
return &user->get_info().access_keys;
}
-RGWAccessKey *RGWUserAdminOpState::get_master_key()
-{
- return &user->get_info().master_key;
-}
-
map<std::string, RGWSubUser>* RGWUserAdminOpState::get_subusers()
{
return &user->get_info().subusers;
new_key.id = id;
new_key.key = key;
access_keys->emplace(id, new_key);
+ op_state.op_master_key = new_key;
}
- *master_key = new_key;
} else if (key_type == KEY_TYPE_SWIFT) {
swift_keys->emplace(id, new_key);
}
return ret;
}
+
ret = user.info(info, NULL);
if (ret < 0)
return ret;
dump_swift_keys_info(formatter, info);
else if (key_type == KEY_TYPE_S3) {
- dump_master_key(formatter, info);
+ dump_master_key(formatter, info, op_state.op_master_key);
}
flusher.flush();