mon: add 'auth get-or-create' variant that outputs a keyring

This is more convenient when you're creating daemons, since you want to
write out a keyring file for them.  This lets you do it in a single
command.

Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Sage Weil 2012-05-22 18:54:10 -07:00
parent b2793c426e
commit 4551808fa0
2 changed files with 25 additions and 4 deletions

View File

@ -74,6 +74,11 @@ public:
void add(const EntityName& name, EntityAuth &a) {
keys[name] = a;
}
void add(const EntityName& name, CryptoKey &k) {
EntityAuth a;
a.key = k;
keys[name] = a;
}
void remove(const EntityName& name) {
keys.erase(name);
}

View File

@ -431,6 +431,7 @@ bool AuthMonitor::preprocess_command(MMonCommand *m)
if (m->cmd.size() > 1) {
if (m->cmd[1] == "add" ||
m->cmd[1] == "del" ||
m->cmd[1] == "get-or-create" ||
m->cmd[1] == "get-or-create-key" ||
m->cmd[1] == "caps") {
return false;
@ -628,7 +629,9 @@ bool AuthMonitor::prepare_command(MMonCommand *m)
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
return true;
}
else if (m->cmd[1] == "get-or-create-key" && m->cmd.size() >= 3) {
else if ((m->cmd[1] == "get-or-create-key" ||
m->cmd[1] == "get-or-create") &&
m->cmd.size() >= 3) {
// auth get-or-create <name> [mon osdcapa osd osdcapb ...]
EntityName entity;
if (!entity.from_str(m->cmd[2])) {
@ -652,7 +655,13 @@ bool AuthMonitor::prepare_command(MMonCommand *m)
}
}
ss << entity_auth.key;
if (m->cmd[1] == "get-or-create-key") {
ss << entity_auth.key;
} else {
KeyRing kr;
kr.add(entity, entity_auth.key);
kr.encode_plaintext(rdata);
}
err = 0;
goto done;
}
@ -683,9 +692,16 @@ bool AuthMonitor::prepare_command(MMonCommand *m)
push_cephx_inc(auth_inc);
ss << auth_inc.auth.key;
if (m->cmd[1] == "get-or-create-key") {
ss << auth_inc.auth.key;
} else {
KeyRing kr;
kr.add(entity, auth_inc.auth.key);
kr.encode_plaintext(rdata);
}
getline(ss, rs);
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, rdata, paxos->get_version()));
return true;
}
else if (m->cmd[1] == "caps" && m->cmd.size() >= 3) {