]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: Update MonCap to work without using namespace
authorAdam C. Emerson <aemerson@redhat.com>
Fri, 29 Mar 2019 00:40:45 +0000 (20:40 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 29 Mar 2019 14:30:35 +0000 (10:30 -0400)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/mon/MonCap.cc
src/mon/MonCap.h

index 00b3016b3ba5dc4b3c55ba4e410bd000f9666398..3d2adb5a4d088c114ac28a992c7fe7f877023ce3 100644 (file)
 
 #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<string,StringConstraint>::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<MonCapGrant>::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);
index 67ed105ebda518d182381753e1bc8db7e874c3ce..b97b1604d59ef54534c417d007e3f757c5696e0b 100644 (file)
@@ -5,7 +5,6 @@
 #define CEPH_MONCAP_H
 
 #include <ostream>
-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<std::string,StringConstraint> command_args;
+  std::map<std::string, StringConstraint> 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<MonCapGrant> profile_grants;
+  mutable std::list<MonCapGrant> 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<string,string>& command_args) const;
+                        const std::map<std::string, std::string>& 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<MonCapGrant> grants;
 
   MonCap() {}
   explicit MonCap(const std::vector<MonCapGrant> &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<string,string>& command_args,
+                 const std::string& service,
+                 const std::string& command,
+                 const std::map<std::string, std::string>& 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<MonCap*>& 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<MonCap*>& ls);
 };
 WRITE_CLASS_ENCODER(MonCap)
 
-ostream& operator<<(ostream& out, const MonCap& cap);
+std::ostream& operator<<(std::ostream& out, const MonCap& cap);
 
 #endif