#include "common/debug.h"
#include "common/errno.h"
#include "include/str_list.h"
+#include "common/Formatter.h"
#define dout_subsys ceph_subsys_auth
bl.append(str);
}
+void KeyRing::encode_formatted(string label, Formatter *f, bufferlist& bl)
+{
+ std::ostringstream(os);
+ f->open_array_section(label.c_str());
+ for (map<EntityName, EntityAuth>::iterator p = keys.begin();
+ p != keys.end();
+ ++p) {
+
+ f->open_object_section("auth_entities");
+ f->dump_string("entity", p->first.to_str().c_str());
+ std::ostringstream keyss;
+ keyss << p->second.key;
+ f->dump_string("key", keyss.str());
+ f->open_object_section("caps");
+ for (map<string, bufferlist>::iterator q = p->second.caps.begin();
+ q != p->second.caps.end();
+ ++q) {
+ bufferlist::iterator dataiter = q->second.begin();
+ string caps;
+ ::decode(caps, dataiter);
+ f->dump_string(q->first.c_str(), caps);
+ }
+ f->close_section(); /* caps */
+ f->close_section(); /* auth_entities */
+ }
+ f->close_section(); /* auth_dump */
+ f->flush(os);
+ bl.append(os.str());
+}
+
void KeyRing::decode_plaintext(bufferlist::iterator& bli)
{
int ret;
map<string, bufferlist> caps;
if (!ename.from_str(name)) {
ostringstream oss;
- oss << "bad entity name n keyring: " << name;
+ oss << "bad entity name in keyring: " << name;
throw buffer::malformed_input(oss.str().c_str());
}
void decode(bufferlist::iterator& bl);
void encode_plaintext(bufferlist& bl);
+ void encode_formatted(string label, Formatter *f, bufferlist& bl);
};
// don't use WRITE_CLASS_ENCODER macro because we don't have an encode
r = -EINVAL;
}
+ string format;
+ cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
+ boost::scoped_ptr<Formatter> f(new_formatter(format));
+
if (prefix == "auth export") {
KeyRing keyring;
export_keyring(keyring);
if (keyring.get_auth(entity, eauth)) {
KeyRing kr;
kr.add(entity, eauth);
- kr.encode_plaintext(rdata);
+ if (f)
+ kr.encode_formatted("auth", f.get(), rdata);
+ else
+ kr.encode_plaintext(rdata);
ss << "export " << eauth;
r = 0;
} else {
r = -ENOENT;
}
} else {
- keyring.encode_plaintext(rdata);
+ if (f)
+ keyring.encode_formatted("auth", f.get(), rdata);
+ else
+ keyring.encode_plaintext(rdata);
+
ss << "exported master keyring";
r = 0;
}
r = -ENOENT;
} else {
keyring.add(entity, entity_auth);
- keyring.encode_plaintext(rdata);
+ if (f)
+ keyring.encode_formatted("auth", f.get(), rdata);
+ else
+ keyring.encode_plaintext(rdata);
ss << "exported keyring for " << entity_name;
r = 0;
}
cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
+ string format;
+ cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
+ boost::scoped_ptr<Formatter> f(new_formatter(format));
+
MonSession *session = m->get_session();
if (!session ||
(!mon->_allowed_command(session, cmdmap))) {