From 181f70226c2c08289c7461b0371a5644fe9be1f1 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Thu, 28 Mar 2019 20:40:45 -0400 Subject: [PATCH] mon: Update MonCap to work without using namespace Signed-off-by: Adam C. Emerson --- src/mon/MonCap.cc | 23 +++++++++++++++-------- src/mon/MonCap.h | 46 +++++++++++++++++++++++----------------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/mon/MonCap.cc b/src/mon/MonCap.cc index 00b3016b3ba5d..3d2adb5a4d088 100644 --- a/src/mon/MonCap.cc +++ b/src/mon/MonCap.cc @@ -31,21 +31,28 @@ #include "include/ceph_assert.h" +using std::list; +using std::map; +using std::ostream; +using std::pair; +using std::string; +using std::vector; + +using ceph::bufferlist; +using ceph::Formatter; + static inline bool is_not_alnum_space(char c) { return !(isalpha(c) || isdigit(c) || (c == '-') || (c == '_')); } -static string maybe_quote_string(const std::string& str) +static std::string maybe_quote_string(const std::string& str) { if (find_if(str.begin(), str.end(), is_not_alnum_space) == str.end()) return str; return string("\"") + str + string("\""); } -using std::ostream; -using std::vector; - #define dout_subsys ceph_subsys_mon ostream& operator<<(ostream& out, const mon_rwxa_t& p) @@ -87,7 +94,7 @@ ostream& operator<<(ostream& out, const MonCapGrant& m) out << " command " << maybe_quote_string(m.command); if (!m.command_args.empty()) { out << " with"; - for (map::const_iterator p = m.command_args.begin(); + for (auto p = m.command_args.begin(); p != m.command_args.end(); ++p) { switch (p->second.match_type) { @@ -216,7 +223,7 @@ void MonCapGrant::expand_profile_mon(const EntityName& name) const StringConstraint constraint(StringConstraint::MATCH_TYPE_PREFIX, string("daemon-private/") + stringify(name) + string("/")); - string prefix = string("daemon-private/") + stringify(name) + string("/"); + std::string prefix = string("daemon-private/") + stringify(name) + string("/"); profile_grants.push_back(MonCapGrant("config-key get", "key", constraint)); profile_grants.push_back(MonCapGrant("config-key put", "key", constraint)); profile_grants.push_back(MonCapGrant("config-key set", "key", constraint)); @@ -326,7 +333,7 @@ mon_rwxa_t MonCapGrant::get_allowed(CephContext *cct, if (profile.length()) { expand_profile(daemon_type, name); mon_rwxa_t a; - for (list::const_iterator p = profile_grants.begin(); + for (auto p = profile_grants.begin(); p != profile_grants.end(); ++p) a = a | p->get_allowed(cct, daemon_type, name, s, c, c_args); return a; @@ -465,7 +472,7 @@ void MonCap::encode(bufferlist& bl) const void MonCap::decode(bufferlist::const_iterator& bl) { - string s; + std::string s; DECODE_START(4, bl); decode(s, bl); DECODE_FINISH(bl); diff --git a/src/mon/MonCap.h b/src/mon/MonCap.h index 67ed105ebda51..b97b1604d59ef 100644 --- a/src/mon/MonCap.h +++ b/src/mon/MonCap.h @@ -5,7 +5,6 @@ #define CEPH_MONCAP_H #include -using std::ostream; #include "include/types.h" #include "common/entity_name.h" @@ -32,7 +31,7 @@ struct mon_rwxa_t { } }; -ostream& operator<<(ostream& out, const mon_rwxa_t& p); +std::ostream& operator<<(std::ostream& out, const mon_rwxa_t& p); struct StringConstraint { enum MatchType { @@ -43,15 +42,15 @@ struct StringConstraint { }; MatchType match_type = MATCH_TYPE_NONE; - string value; + std::string value; StringConstraint() {} - StringConstraint(MatchType match_type, string value) + StringConstraint(MatchType match_type, std::string value) : match_type(match_type), value(value) { } }; -ostream& operator<<(ostream& out, const StringConstraint& c); +std::ostream& operator<<(std::ostream& out, const StringConstraint& c); struct MonCapGrant { /* @@ -78,7 +77,7 @@ struct MonCapGrant { std::string service; std::string profile; std::string command; - map command_args; + std::map command_args; // restrict by network std::string network; @@ -94,7 +93,7 @@ struct MonCapGrant { // explicit grants that a profile grant expands to; populated as // needed by expand_profile() (via is_match()) and cached here. - mutable list profile_grants; + mutable std::list profile_grants; void expand_profile(int daemon_type, const EntityName& name) const; void expand_profile_mon(const EntityName& name) const; @@ -103,10 +102,10 @@ struct MonCapGrant { MonCapGrant() : allow(0) {} // cppcheck-suppress noExplicitConstructor MonCapGrant(mon_rwxa_t a) : allow(a) {} - MonCapGrant(string s, mon_rwxa_t a) : service(std::move(s)), allow(a) {} - // cppcheck-suppress noExplicitConstructor - MonCapGrant(string c) : command(std::move(c)) {} - MonCapGrant(string c, string a, StringConstraint co) : command(std::move(c)) { + MonCapGrant(std::string s, mon_rwxa_t a) : service(std::move(s)), allow(a) {} + // cppcheck-suppress noExplicitConstructor + MonCapGrant(std::string c) : command(std::move(c)) {} + MonCapGrant(std::string c, std::string a, StringConstraint co) : command(std::move(c)) { command_args[a] = co; } @@ -125,7 +124,7 @@ struct MonCapGrant { EntityName name, const std::string& service, const std::string& command, - const map& command_args) const; + const std::map& command_args) const; bool is_allow_all() const { return @@ -136,22 +135,22 @@ struct MonCapGrant { } }; -ostream& operator<<(ostream& out, const MonCapGrant& g); +std::ostream& operator<<(std::ostream& out, const MonCapGrant& g); struct MonCap { - string text; + std::string text; std::vector grants; MonCap() {} explicit MonCap(const std::vector &g) : grants(g) {} - string get_str() const { + std::string get_str() const { return text; } bool is_allow_all() const; void set_allow_all(); - bool parse(const std::string& str, ostream *err=NULL); + bool parse(const std::string& str, std::ostream *err=NULL); /** * check if we are capable of something @@ -171,18 +170,19 @@ struct MonCap { bool is_capable(CephContext *cct, int daemon_type, EntityName name, - const string& service, - const string& command, const map& command_args, + const std::string& service, + const std::string& command, + const std::map& command_args, bool op_may_read, bool op_may_write, bool op_may_exec, const entity_addr_t& addr) const; - void encode(bufferlist& bl) const; - void decode(bufferlist::const_iterator& bl); - void dump(Formatter *f) const; - static void generate_test_instances(list& ls); + void encode(ceph::buffer::list& bl) const; + void decode(ceph::buffer::list::const_iterator& bl); + void dump(ceph::Formatter *f) const; + static void generate_test_instances(std::list& ls); }; WRITE_CLASS_ENCODER(MonCap) -ostream& operator<<(ostream& out, const MonCap& cap); +std::ostream& operator<<(std::ostream& out, const MonCap& cap); #endif -- 2.39.5