#include <seastar/util/log.hh>
#include "auth/AuthClientHandler.h"
+#include "auth/AuthMethodList.h"
#include "auth/RotatingKeyRing.h"
#include "crimson/auth/KeyRing.h"
ceph::net::ConnectionRef Connection::get_conn() {
return conn;
}
+
namespace {
-AuthMethodList create_auth_methods(uint32_t entity_type)
+auto create_auth_methods(uint32_t entity_type)
{
auto& conf = ceph::common::local_conf();
std::string method;
} else {
method = conf.get_val<std::string>("auth_client_required");
}
- return AuthMethodList(nullptr, method);
+ return std::make_unique<AuthMethodList>(nullptr, method);
}
}
Client::Client(ceph::net::Messenger& messenger)
// currently, crimson is OSD-only
- : auth_methods{create_auth_methods(CEPH_ENTITY_TYPE_OSD)},
- want_keys{CEPH_ENTITY_TYPE_MON |
+ : want_keys{CEPH_ENTITY_TYPE_MON |
CEPH_ENTITY_TYPE_OSD |
CEPH_ENTITY_TYPE_MGR},
timer{[this] { tick(); }},
Client::Client(Client&&) = default;
Client::~Client() = default;
-void Client::set_name(const EntityName& name)
-{
- entity_name = name;
+seastar::future<> Client::start() {
+ entity_name = ceph::common::local_conf()->name;
// should always be OSD, though
- auth_methods = create_auth_methods(name.get_type());
+ auth_methods = create_auth_methods(entity_name.get_type());
+ return load_keyring().then([this] {
+ return monmap.build_initial(ceph::common::local_conf(), false);
+ }).then([this] {
+ return authenticate();
+ });
}
seastar::future<> Client::load_keyring()
{
- if (!auth_methods.is_supported_auth(CEPH_AUTH_CEPHX)) {
+ if (!auth_methods->is_supported_auth(CEPH_AUTH_CEPHX)) {
return seastar::now();
} else {
return ceph::auth::load_from_keyring(&keyring).then([](KeyRing* keyring) {
}
}
-seastar::future<> Client::build_initial_map()
-{
- return monmap.build_initial(ceph::common::local_conf(), false);
-}
-
seastar::future<> Client::authenticate()
{
return reopen_session(-1);
seastar::future<> Client::stop()
{
- return tick_gate.close().finally([this] {
- return timer.cancel();
- }).then([this] {
+ return tick_gate.close().then([this] {
if (active_con) {
return active_con->close();
} else {
auto& mc = pending_conns.emplace_back(conn, &keyring);
return mc.authenticate(
monmap.get_epoch(), entity_name,
- auth_methods, want_keys).handle_exception([conn](auto ep) {
+ *auth_methods, want_keys).handle_exception([conn](auto ep) {
return conn->close().then([ep = std::move(ep)] {
std::rethrow_exception(ep);
});
#include <seastar/core/lowres_clock.hh>
#include <seastar/core/timer.hh>
-#include "auth/AuthMethodList.h"
#include "auth/KeyRing.h"
#include "crimson/net/Dispatcher.h"
class Messenger;
}
+class AuthMethodList;
class MAuthReply;
struct MMonMap;
struct MMonSubscribeAck;
class Client : public ceph::net::Dispatcher {
EntityName entity_name;
KeyRing keyring;
- AuthMethodList auth_methods;
+ std::unique_ptr<AuthMethodList> auth_methods;
const uint32_t want_keys;
MonMap monmap;
Client(ceph::net::Messenger& messenger);
Client(Client&&);
~Client();
- void set_name(const EntityName& name);
-
- seastar::future<> load_keyring();
- seastar::future<> build_initial_map();
- seastar::future<> authenticate();
+ seastar::future<> start();
seastar::future<> stop();
+
get_version_t get_version(const std::string& map);
command_result_t run_command(const std::vector<std::string>& cmd,
const bufferlist& bl);
seastar::future<> handle_config(Ref<MConfig> m);
private:
+ seastar::future<> load_keyring();
+ seastar::future<> authenticate();
+
bool is_hunting() const;
seastar::future<> reopen_session(int rank);
std::vector<unsigned> get_random_mons(unsigned n) const;
}
return seastar::do_with(MonClient{msgr},
[&msgr](auto& monc) {
- monc.set_name(ceph::common::local_conf()->name);
- return monc.build_initial_map().then([&monc] {
- return monc.load_keyring();
- }).then([&msgr, &monc] {
- return msgr.start(&monc);
- }).then([&monc] {
+ return msgr.start(&monc).then([&monc] {
return seastar::with_timeout(
seastar::lowres_clock::now() + std::chrono::seconds{10},
- monc.authenticate());
- }).finally([&monc] {
+ monc.start());
+ }).then([&monc] {
return monc.stop();
});
}).finally([&msgr] {