MCPcopy Create free account
hub / github.com/ceph/ceph / from_ceph_context

Method from_ceph_context

src/auth/KeyRing.cc:43–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41using ceph::Formatter;
42
43int KeyRing::from_ceph_context(CephContext *cct)
44{
45 const auto& conf = cct->_conf;
46 string filename;
47
48 int ret = ceph_resolve_file_search(conf->keyring, filename);
49 if (!ret) {
50 ret = load(cct, filename);
51 if (ret < 0)
52 lderr(cct) << "failed to load " << filename
53 << ": " << cpp_strerror(ret) << dendl;
54 } else if (conf->key.empty() && conf->keyfile.empty()) {
55 lderr(cct) << "unable to find a keyring on " << conf->keyring
56 << ": " << cpp_strerror(ret) << dendl;
57 }
58
59 if (!conf->key.empty()) {
60 EntityAuth ea;
61 try {
62 ea.key.decode_base64(conf->key);
63 add(conf->name, ea);
64 return 0;
65 }
66 catch (ceph::buffer::error& e) {
67 lderr(cct) << "failed to decode key '" << conf->key << "'" << dendl;
68 return -EINVAL;
69 }
70 }
71
72 if (!conf->keyfile.empty()) {
73 bufferlist bl;
74 string err;
75 int r = bl.read_file(conf->keyfile.c_str(), &err);
76 if (r < 0) {
77 lderr(cct) << err << dendl;
78 return r;
79 }
80 string k(bl.c_str(), bl.length());
81 EntityAuth ea;
82 try {
83 ea.key.decode_base64(k);
84 add(conf->name, ea);
85 }
86 catch (ceph::buffer::error& e) {
87 lderr(cct) << "failed to decode key '" << k << "'" << dendl;
88 return -EINVAL;
89 }
90 return 0;
91 }
92
93 return ret;
94}
95
96int KeyRing::set_modifier(const char *type,
97 const char *val,

Callers 5

build_map_bufFunction · 0.80
_refresh_configMethod · 0.80
ping_monitorMethod · 0.80
initMethod · 0.80

Calls 9

ceph_resolve_file_searchFunction · 0.85
cpp_strerrorFunction · 0.85
loadFunction · 0.50
addFunction · 0.50
emptyMethod · 0.45
decode_base64Method · 0.45
read_fileMethod · 0.45
c_strMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected