struct EntityAuth {
CryptoKey key;
std::map<std::string, ceph::buffer::list> caps;
+ CryptoKey pending_key; ///< new but uncommitted key
void encode(ceph::buffer::list& bl) const {
- __u8 struct_v = 2;
+ __u8 struct_v = 3;
using ceph::encode;
encode(struct_v, bl);
encode((uint64_t)CEPH_AUTH_UID_DEFAULT, bl);
encode(key, bl);
encode(caps, bl);
+ encode(pending_key, bl);
}
void decode(ceph::buffer::list::const_iterator& bl) {
using ceph::decode;
}
decode(key, bl);
decode(caps, bl);
+ if (struct_v >= 3) {
+ decode(pending_key, bl);
+ }
}
};
WRITE_CLASS_ENCODER(EntityAuth)
-inline std::ostream& operator<<(std::ostream& out, const EntityAuth& a) {
- return out << "auth(key=" << a.key << ")";
+inline std::ostream& operator<<(std::ostream& out, const EntityAuth& a)
+{
+ out << "auth(key=" << a.key;
+ if (!a.pending_key.empty()) {
+ out << " pending_key=" << a.pending_key;
+ }
+ out << ")";
+ return out;
}
struct AuthCapsInfo {
#include <algorithm>
#include <boost/algorithm/string/replace.hpp>
#include "auth/KeyRing.h"
+#include "include/stringify.h"
#include "common/ceph_context.h"
#include "common/config.h"
#include "common/debug.h"
void KeyRing::encode_formatted(string label, Formatter *f, bufferlist& bl)
{
f->open_array_section(label.c_str());
- for (map<EntityName, EntityAuth>::iterator p = keys.begin();
- p != keys.end();
- ++p) {
-
+ for (const auto &[ename, eauth] : keys) {
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->dump_string("entity", ename.to_str().c_str());
+ f->dump_string("key", stringify(eauth.key));
+ if (!eauth.pending_key.empty()) {
+ f->dump_string("pending_key", stringify(eauth.pending_key));
+ }
f->open_object_section("caps");
- for (map<string, bufferlist>::iterator q = p->second.caps.begin();
- q != p->second.caps.end();
- ++q) {
- auto dataiter = q->second.cbegin();
+ for (auto& [sys, capsbl] : eauth.caps) {
+ auto dataiter = capsbl.cbegin();
string caps;
- using ceph::decode;
- decode(caps, dataiter);
- f->dump_string(q->first.c_str(), caps);
+ ceph::decode(caps, dataiter);
+ f->dump_string(sys.c_str(), caps);
}
f->close_section(); /* caps */
f->close_section(); /* auth_entities */
void KeyRing::print(ostream& out)
{
- for (map<EntityName, EntityAuth>::iterator p = keys.begin();
- p != keys.end();
- ++p) {
- out << "[" << p->first << "]" << std::endl;
- out << "\tkey = " << p->second.key << std::endl;
+ for (auto& [ename, eauth] : keys) {
+ out << "[" << ename << "]" << std::endl;
+ out << "\tkey = " << eauth.key << std::endl;
+ if (!eauth.pending_key.empty()) {
+ out << "\tpending key = " << eauth.pending_key << std::endl;
+ }
- for (map<string, bufferlist>::iterator q = p->second.caps.begin();
- q != p->second.caps.end();
- ++q) {
- auto dataiter = q->second.cbegin();
+ for (auto& [sys, capbl] : eauth.caps) {
+ auto dataiter = capbl.cbegin();
string caps;
- using ceph::decode;
- decode(caps, dataiter);
+ ceph::decode(caps, dataiter);
boost::replace_all(caps, "\"", "\\\"");
- out << "\tcaps " << q->first << " = \"" << caps << '"' << std::endl;
+ out << "\tcaps " << sys << " = \"" << caps << '"' << std::endl;
}
}
}