From: Omri Zeneva Date: Sun, 27 Mar 2022 17:10:33 +0000 (+0300) Subject: rgw: support bucket name in pre request context X-Git-Tag: v18.0.0~979^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cd97a30bedf563a1f96b80d4f025fe73e01a9f4c;p=ceph.git rgw: support bucket name in pre request context because bucket object is created only after authentication, if bucket object is null upon accessing Request.Bucket.Name, we return req_state->init_state.url_bucket Signed-off-by: Omri Zeneva --- diff --git a/doc/radosgw/lua-scripting.rst b/doc/radosgw/lua-scripting.rst index d970455a5205..31306dec98ac 100644 --- a/doc/radosgw/lua-scripting.rst +++ b/doc/radosgw/lua-scripting.rst @@ -140,27 +140,27 @@ Request Fields +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ | ``Request.SwiftAccountName`` | string | swift account name | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket`` | table | info on the bucket | no | no | yes | +| ``Request.Bucket`` | table | info on the bucket | no | no | no | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.Tenant`` | string | tenant of the bucket | no | no | no | +| ``Request.Bucket.Tenant`` | string | tenant of the bucket | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ | ``Request.Bucket.Name`` | string | bucket name | no | no | no | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.Marker`` | string | bucket marker (initial id) | no | no | no | +| ``Request.Bucket.Marker`` | string | bucket marker (initial id) | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.Id`` | string | bucket id | no | no | no | +| ``Request.Bucket.Id`` | string | bucket id | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.Count`` | integer | number of objects in the bucket | no | no | no | +| ``Request.Bucket.Count`` | integer | number of objects in the bucket | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.Size`` | integer | total size of objects in the bucket | no | no | no | +| ``Request.Bucket.Size`` | integer | total size of objects in the bucket | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.ZoneGroupId`` | string | zone group of the bucket | no | no | no | +| ``Request.Bucket.ZoneGroupId`` | string | zone group of the bucket | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.CreationTime`` | time | creation time of the bucket | no | no | no | +| ``Request.Bucket.CreationTime`` | time | creation time of the bucket | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.MTime`` | time | modification time of the bucket | no | no | no | +| ``Request.Bucket.MTime`` | time | modification time of the bucket | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.Quota`` | table | bucket quota | no | no | no | +| ``Request.Bucket.Quota`` | table | bucket quota | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ | ``Request.Bucket.Quota.MaxSize`` | integer | bucket quota max size | no | no | no | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ @@ -170,13 +170,13 @@ Request Fields +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ | ``Request.Bucket.Quota.Rounded`` | boolean | bucket quota is rounded to 4K | no | no | no | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.PlacementRule`` | table | bucket placement rule | no | no | no | +| ``Request.Bucket.PlacementRule`` | table | bucket placement rule | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ | ``Request.Bucket.PlacementRule.Name`` | string | bucket placement rule name | no | no | no | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ | ``Request.Bucket.PlacementRule.StorageClass`` | string | bucket placement rule storage class | no | no | no | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ -| ``Request.Bucket.User`` | table | bucket owner | no | no | no | +| ``Request.Bucket.User`` | table | bucket owner | no | no | yes | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ | ``Request.Bucket.User.Tenant`` | string | bucket owner tenant | no | no | no | +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+ diff --git a/src/rgw/rgw_lua_request.cc b/src/rgw/rgw_lua_request.cc index 2e971c329c87..d6021b2a91d9 100644 --- a/src/rgw/rgw_lua_request.cc +++ b/src/rgw/rgw_lua_request.cc @@ -170,14 +170,19 @@ struct BucketMetaTable : public EmptyMetaTable { static std::string TableName() {return "Bucket";} static std::string Name() {return TableName() + "Meta";} - using Type = rgw::sal::Bucket; - static int IndexClosure(lua_State* L) { - const auto bucket = reinterpret_cast(lua_touserdata(L, lua_upvalueindex(1))); + const auto s = reinterpret_cast(lua_touserdata(L, lua_upvalueindex(1))); + const auto bucket = s->bucket.get(); const char* index = luaL_checkstring(L, 2); - if (strcasecmp(index, "Tenant") == 0) { + if (rgw::sal::Bucket::empty(bucket)) { + if (strcasecmp(index, "Name") == 0) { + pushstring(L, s->init_state.url_bucket); + } else { + lua_pushnil(L); + } + } else if (strcasecmp(index, "Tenant") == 0) { pushstring(L, bucket->get_tenant()); } else if (strcasecmp(index, "Name") == 0) { pushstring(L, bucket->get_name()); @@ -731,7 +736,7 @@ struct RequestMetaTable : public EmptyMetaTable { lua_pushnil(L); } } else if (strcasecmp(index, "Bucket") == 0) { - create_metatable(L, false, s->bucket); + create_metatable(L, false, s); } else if (strcasecmp(index, "Object") == 0) { create_metatable(L, false, s->object); } else if (strcasecmp(index, "CopyFrom") == 0) {