]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw, optimization: switch to std::string& when possible in the new auth.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 20 May 2016 13:28:52 +0000 (15:28 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 2 Jun 2016 19:17:13 +0000 (21:17 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_acl.cc
src/rgw/rgw_acl_swift.cc
src/rgw/rgw_auth.cc
src/rgw/rgw_auth.h
src/rgw/rgw_keystone.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_swift_auth.cc
src/rgw/rgw_swift_auth.h

index bbd19a71781fbab87957cf72b32d3ef3fe8d7e90..f43e87b0feb396432de6022ed5cadfee3dc94d64 100644 (file)
@@ -79,7 +79,7 @@ int RGWAccessControlList::get_referer_perm(const std::string http_referer,
   /* FIXME: C++11 doesn't have std::rbegin nor std::rend. We would like to
    * switch when C++14 becomes available. */
   const auto iter = std::find_if(referer_list.crbegin(), referer_list.crend(),
-    [http_referer](const ACLReferer& r) -> bool {
+    [&http_referer](const ACLReferer& r) -> bool {
       return r.is_match(http_referer);
     }
   );
index eb0afe4cc1ce022458440cfb2ee2e1fdc0c9d546..7f0759213b2b7e7d38948bd4f7ad35cca044178a 100644 (file)
@@ -214,7 +214,7 @@ void RGWAccessControlPolicy_SWIFTAcct::add_grants(RGWRados * const store,
                                                   const std::vector<std::string>& uids,
                                                   const int perm)
 {
-  for (const auto uid : uids) {
+  for (const auto& uid : uids) {
     ACLGrant grant;
     RGWUserInfo grant_user;
 
@@ -290,7 +290,7 @@ void RGWAccessControlPolicy_SWIFTAcct::to_str(std::string& acl_str) const
   std::vector<std::string> readonly;
 
   /* Parition the grant map into three not-overlapping groups. */
-  for (const auto item : get_acl().get_grant_map()) {
+  for (const auto& item : get_acl().get_grant_map()) {
     const ACLGrant& grant = item.second;
     const int perm = grant.get_permission().get_permissions();
 
index 1089fd283df0f7b0d1fdf2fcfbf27b1e21ea18b9..a89dedcb011c529764218be42600cbb62dbde177 100644 (file)
@@ -149,7 +149,7 @@ std::string RGWRemoteAuthApplier::to_str() const
   return ss.str();
 }
 
-void RGWRemoteAuthApplier::create_account(const rgw_user acct_user,
+void RGWRemoteAuthApplier::create_account(const rgw_user& acct_user,
                                           RGWUserInfo& user_info) const      /* out */
 {
   rgw_user new_acct_user = acct_user;
@@ -310,7 +310,7 @@ bool RGWKeystoneAuthEngine::is_applicable() const noexcept
   return false == cct->_conf->rgw_keystone_url.empty();
 }
 
-KeystoneToken RGWKeystoneAuthEngine::decode_pki_token(const std::string token) const
+KeystoneToken RGWKeystoneAuthEngine::decode_pki_token(const std::string& token) const
 {
   bufferlist token_body_bl;
   int ret = rgw_decode_b64_cms(cct, token, token_body_bl);
@@ -330,7 +330,7 @@ KeystoneToken RGWKeystoneAuthEngine::decode_pki_token(const std::string token) c
   return token_body;
 }
 
-KeystoneToken RGWKeystoneAuthEngine::get_from_keystone(const std::string token) const
+KeystoneToken RGWKeystoneAuthEngine::get_from_keystone(const std::string& token) const
 {
   bufferlist token_body_bl;
   RGWValidateKeystoneToken validate(cct, &token_body_bl);
@@ -380,7 +380,7 @@ RGWKeystoneAuthEngine::get_creds_info(const KeystoneToken& token,
 {
   /* Check whether the user has an admin status. */
   bool is_admin = false;
-  for (const auto admin_role : admin_roles) {
+  for (const auto& admin_role : admin_roles) {
     if (token.has_role(admin_role)) {
       is_admin = true;
       break;
@@ -399,8 +399,8 @@ RGWKeystoneAuthEngine::get_creds_info(const KeystoneToken& token,
   };
 }
 
-static inline const std::string make_spec_item(const std::string tenant,
-                                               const std::string id)
+static inline const std::string make_spec_item(const std::string& tenant,
+                                               const std::string& id)
 {
   return tenant + ":" + id;
 }
@@ -409,12 +409,12 @@ RGWKeystoneAuthEngine::acl_strategy_t
 RGWKeystoneAuthEngine::get_acl_strategy(const KeystoneToken& token) const
 {
   /* The primary identity is constructed upon UUIDs. */
-  const auto tenant_uuid = token.get_project_id();
-  const auto user_uuid = token.get_user_id();
+  const auto& tenant_uuid = token.get_project_id();
+  const auto& user_uuid = token.get_user_id();
 
   /* For Keystone v2 an alias may be also used. */
-  const auto tenant_name = token.get_project_name();
-  const auto user_name = token.get_user_name();
+  const auto& tenant_name = token.get_project_name();
+  const auto& user_name = token.get_user_name();
 
   /* Construct all possible combinations including Swift's wildcards. */
   const std::vector<std::string> allowed_items = {
@@ -465,7 +465,7 @@ RGWAuthApplier::aplptr_t RGWKeystoneAuthEngine::authenticate() const
 
   /* Token ID is a concept that makes dealing with PKI tokens more effective.
    * Instead of storing several kilobytes, a short hash can be burried. */
-  const auto token_id = rgw_get_token_id(token);
+  const auto& token_id = rgw_get_token_id(token);
   ldout(cct, 20) << "token_id=" << token_id << dendl;
 
   /* Check cache first. */
@@ -499,7 +499,7 @@ RGWAuthApplier::aplptr_t RGWKeystoneAuthEngine::authenticate() const
   }
 
   /* Check for necessary roles. */
-  for (const auto role : roles.plain) {
+  for (const auto& role : roles.plain) {
     if (t.has_role(role) == true) {
       ldout(cct, 0) << "validated token: " << t.get_project_name()
                     << ":" << t.get_user_name()
index 993319a5424909130c0f6fe8169abe721b893211..67abdfe80b142bf8a994c9535417662830a318bc 100644 (file)
@@ -116,8 +116,8 @@ public:
     const bool is_admin;
 
   public:
-    AuthInfo(const rgw_user acct_user,
-             const std::string acct_name,
+    AuthInfo(const rgw_user& acct_user,
+             const std::string& acct_name,
              const uint32_t perm_mask,
              const bool is_admin)
     : acct_user(acct_user),
@@ -141,14 +141,14 @@ protected:
 
   const AuthInfo info;
 
-  virtual void create_account(const rgw_user acct_user,
+  virtual void create_account(const rgw_user& acct_user,
                               RGWUserInfo& user_info) const;          /* out */
 
 public:
   RGWRemoteAuthApplier(CephContext * const cct,
                        RGWRados * const store,
                        acl_strategy_t&& extra_acl_strategy,
-                       const AuthInfo info)
+                       const AuthInfo& info)
     : RGWAuthApplier(cct),
       store(store),
       extra_acl_strategy(std::move(extra_acl_strategy)),
@@ -291,8 +291,8 @@ protected:
   const RGWRemoteAuthApplier::Factory * const apl_factory;
 
   /* Helper methods. */
-  KeystoneToken decode_pki_token(const std::string token) const;
-  KeystoneToken get_from_keystone(const std::string token) const;
+  KeystoneToken decode_pki_token(const std::string& token) const;
+  KeystoneToken get_from_keystone(const std::string& token) const;
   acl_strategy_t get_acl_strategy(const KeystoneToken& token) const;
   RGWRemoteAuthApplier::AuthInfo get_creds_info(const KeystoneToken& token,
                                                 const std::vector<std::string>& admin_roles
index 2449dae7a265bca202451aee9eef48bf91b178ad..e2a3bfa80ba32080f60a27e164653601afd1e6d9 100644 (file)
@@ -114,12 +114,12 @@ public:
   // FIXME: default ctor needs to be eradicated here
   KeystoneToken() = default;
   time_t get_expires() const { return token.expires; }
-  string get_domain_id() const {return project.domain.id;};
-  string get_domain_name() const {return project.domain.name;};
-  string get_project_id() const {return project.id;};
-  string get_project_name() const {return project.name;};
-  string get_user_id() const {return user.id;};
-  string get_user_name() const {return user.name;};
+  const std::string& get_domain_id() const {return project.domain.id;};
+  const std::string& get_domain_name() const {return project.domain.name;};
+  const std::string& get_project_id() const {return project.id;};
+  const std::string& get_project_name() const {return project.name;};
+  const std::string& get_user_id() const {return user.id;};
+  const std::string& get_user_name() const {return user.name;};
   bool has_role(const string& r) const;
   bool expired() {
     uint64_t now = ceph_clock_now(NULL).sec();
index 56b915ebe35b359faa60d44120891eae235c3edc..7ded6c68255f14485d7f38e58f4f2700cc0f3cef 100644 (file)
@@ -3006,7 +3006,7 @@ int RGW_Auth_S3_Keystone_ValidateToken::validate_s3token(
 
   /* check if we have a valid role */
   bool found = false;
-  for (const auto role : accepted_roles) {
+  for (const auto& role : accepted_roles) {
     if (response.has_role(role) == true) {
       found = true;
       break;
index 7f56a3d646d48d26fd67e78e91f57d93857fb1ae..7f41287a37360731dbaeac4df63a6a83dc2a63f5 100644 (file)
@@ -29,7 +29,7 @@ using namespace ceph::crypto;
 void RGWTempURLAuthApplier::modify_request_state(req_state * s) const       /* in/out */
 {
   bool inline_exists = false;
-  string filename = s->info.args.get("filename");
+  const string& filename = s->info.args.get("filename");
 
   s->info.args.get("inline", &inline_exists);
   if (inline_exists) {
@@ -309,7 +309,7 @@ RGWAuthApplier::aplptr_t RGWExternalTokenAuthEngine::authenticate() const
     if (0 == swift_groups.size()) {
       return nullptr;
     } else {
-      swift_user = swift_groups[0];
+      swift_user = std::move(swift_groups[0]);
     }
   } catch (std::out_of_range) {
     /* The X-Auth-Groups header isn't present in the response. */
index c6a1b1c3c1e695d14dfcd7f17de7ae4203db6c1c..0f559fddf9a6a6ea1723f1708c0ed5f37219ecbc 100644 (file)
@@ -116,7 +116,9 @@ public:
   RGWXAuthTokenExtractor(const req_state * const s)
     : s(s) {
   }
-  std::string get_token() const {
+  std::string get_token() const override {
+    /* Returning a reference here would end in GCC complaining about a reference
+     * to temporary. */
     return s->info.env->get("HTTP_X_AUTH_TOKEN", "");
   }
 };