From: Abhishek Lekshmanan Date: Wed, 24 Jan 2018 13:39:54 +0000 (+0100) Subject: rgw: rgw_add_to_iam_env use string_view X-Git-Tag: v13.0.2~246^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=583ff77c9510a5de3d7e824c79f41d6d3833cbe6;p=ceph.git rgw: rgw_add_to_iam_env use string_view This commit unites the various add_to_iam_env implementations and uses the std::string_view variant. Also updated call sites which check empty key values since that is done in the function Signed-off-by: Abhishek Lekshmanan --- diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index ef246e7990c..7c6f0199c0a 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -566,14 +566,11 @@ int rgw_build_object_policies(RGWRados *store, struct req_state *s, return ret; } -void rgw_add_to_iam_environment(rgw::IAM::Environment& e, const std::string& key, const std::string& val){ - e[key] = val; -} - - -void rgw_add_to_iam_environment(rgw::IAM::Environment& e, const char* key, const char* val){ - if (key != nullptr && val != nullptr) - e[key] = val; +void rgw_add_to_iam_environment(rgw::IAM::Environment& e, std::string_view key, std::string_view val){ + // This variant just adds non empty key pairs to IAM env., values can be empty + // in certain cases like tagging + if (!key.empty()) + e.emplace(key,val); } static int rgw_iam_add_tags_from_bl(struct req_state* s, bufferlist& bl){ @@ -626,7 +623,6 @@ static void rgw_add_grant_to_iam_environment(rgw::IAM::Environment& e, struct re } } - rgw::IAM::Environment rgw_build_iam_environment(RGWRados* store, struct req_state* s) { @@ -3067,9 +3063,7 @@ int RGWPutObj::verify_permission() if (s->iam_policy) { rgw_add_grant_to_iam_environment(s->env, s); - if (!s->canned_acl.empty()){ - rgw_add_to_iam_environment(s->env, "s3:x-amz-acl", s->canned_acl); - } + rgw_add_to_iam_environment(s->env, "s3:x-amz-acl", s->canned_acl); if (obj_tags != nullptr && obj_tags->count() > 0){ auto tags = obj_tags->get_tags(); @@ -4722,9 +4716,7 @@ int RGWPutACLs::verify_permission() { bool perm; - if (!s->canned_acl.empty()){ - rgw_add_to_iam_environment(s->env, "s3:x-amz-acl", s->canned_acl); - } + rgw_add_to_iam_environment(s->env, "s3:x-amz-acl", s->canned_acl); rgw_add_grant_to_iam_environment(s->env, s); if (!s->object.empty()) {