]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add 'auth get-or-create' variant that outputs a keyring
authorSage Weil <sage@inktank.com>
Wed, 23 May 2012 01:54:10 +0000 (18:54 -0700)
committerSage Weil <sage@inktank.com>
Sat, 9 Jun 2012 00:22:10 +0000 (17:22 -0700)
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>
src/auth/KeyRing.h
src/mon/AuthMonitor.cc

index 26f41ab3e55268577f5e64750ca97e5a0caf9701..26358003766fe3fc5a09382f6054ce0ec61718d9 100644 (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);
   }
index df7ce5532204b2a9869c7f8d07d672a8e760704e..d9b698aefd5e3c5a8b0d162ee6000ef797943c30 100644 (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) {