]> git.proxmox.com Git - ceph.git/blame - ceph/src/crimson/auth/KeyRing.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / crimson / auth / KeyRing.cc
CommitLineData
11fdf7f2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "KeyRing.h"
5
6#include <boost/algorithm/string.hpp>
7
8#include <seastar/core/do_with.hh>
9#include <seastar/core/fstream.hh>
10#include <seastar/core/future-util.hh>
11#include <seastar/core/reactor.hh>
12
13#include "common/buffer_seastar.h"
14#include "auth/KeyRing.h"
15#include "include/denc.h"
f67539c2 16#include "crimson/common/buffer_io.h"
11fdf7f2
TL
17#include "crimson/common/config_proxy.h"
18
9f95a23c 19namespace crimson::auth {
11fdf7f2 20
11fdf7f2
TL
21seastar::future<KeyRing*> load_from_keyring(KeyRing* keyring)
22{
23 std::vector<std::string> paths;
9f95a23c 24 boost::split(paths, crimson::common::local_conf()->keyring,
11fdf7f2
TL
25 boost::is_any_of(",;"));
26 std::pair<bool, std::string> found;
27 return seastar::map_reduce(paths, [](auto path) {
28 return seastar::engine().file_exists(path).then([path](bool file_exists) {
29 return std::make_pair(file_exists, path);
30 });
31 }, std::move(found), [](auto found, auto file_exists_and_path) {
32 if (!found.first && file_exists_and_path.first) {
33 found = std::move(file_exists_and_path);
34 }
35 return found;
36 }).then([keyring] (auto file_exists_and_path) {
37 const auto& [exists, path] = file_exists_and_path;
38 if (exists) {
39 return read_file(path).then([keyring](auto buf) {
40 bufferlist bl;
41 bl.append(buffer::create(std::move(buf)));
42 auto i = bl.cbegin();
43 keyring->decode(i);
44 return seastar::make_ready_future<KeyRing*>(keyring);
45 });
46 } else {
47 return seastar::make_ready_future<KeyRing*>(keyring);
48 }
49 });
50}
51
52seastar::future<KeyRing*> load_from_keyfile(KeyRing* keyring)
53{
9f95a23c 54 auto& path = crimson::common::local_conf()->keyfile;
11fdf7f2
TL
55 if (!path.empty()) {
56 return read_file(path).then([keyring](auto buf) {
57 EntityAuth ea;
58 ea.key.decode_base64(std::string(buf.begin(),
59 buf.end()));
9f95a23c 60 keyring->add(crimson::common::local_conf()->name, ea);
11fdf7f2
TL
61 return seastar::make_ready_future<KeyRing*>(keyring);
62 });
63 } else {
64 return seastar::make_ready_future<KeyRing*>(keyring);
65 }
66}
67
68seastar::future<KeyRing*> load_from_key(KeyRing* keyring)
69{
9f95a23c 70 auto& key = crimson::common::local_conf()->key;
11fdf7f2
TL
71 if (!key.empty()) {
72 EntityAuth ea;
73 ea.key.decode_base64(key);
9f95a23c 74 keyring->add(crimson::common::local_conf()->name, ea);
11fdf7f2
TL
75 }
76 return seastar::make_ready_future<KeyRing*>(keyring);
77}
78
9f95a23c 79} // namespace crimson::auth