1
0
mirror of https://github.com/ceph/ceph synced 2024-12-23 11:54:11 +00:00

rgw/lua: allow bucket name override in pre request

Signed-off-by: Yuval Lifshitz <ylifshit@redhat.com>
This commit is contained in:
Yuval Lifshitz 2022-06-12 20:58:40 +03:00
parent 05976ab9fb
commit 89ef51a81b
3 changed files with 49 additions and 1 deletions

View File

@ -149,7 +149,7 @@ Request Fields
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
| ``Request.Bucket.Tenant`` | string | tenant of the bucket | no | no | yes |
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
| ``Request.Bucket.Name`` | string | bucket name | no | no | no |
| ``Request.Bucket.Name`` | string | bucket name (writeable only in `preRequest` context) | no | yes | no |
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
| ``Request.Bucket.Marker`` | string | bucket marker (initial id) | no | no | yes |
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+

View File

@ -324,6 +324,21 @@ struct BucketMetaTable : public EmptyMetaTable {
}
return ONE_RETURNVAL;
}
static int NewIndexClosure(lua_State* L) {
const auto s = reinterpret_cast<req_state*>(lua_touserdata(L, lua_upvalueindex(FIRST_UPVAL)));
const auto bucket = s->bucket.get();
const char* index = luaL_checkstring(L, 2);
if (rgw::sal::Bucket::empty(bucket)) {
if (strcasecmp(index, "Name") == 0) {
s->init_state.url_bucket = luaL_checkstring(L, 3);
return NO_RETURNVAL;
}
}
return error_unknown_field(L, index, TableName());
}
};
struct ObjectMetaTable : public EmptyMetaTable {

View File

@ -343,6 +343,39 @@ TEST(TestRGWLua, Bucket)
ASSERT_EQ(rc, 0);
}
TEST(TestRGWLua, WriteBucket)
{
const std::string script = R"(
assert(Request.Bucket)
assert(Request.Bucket.Name == "myname")
Request.Bucket.Name = "othername"
)";
DEFINE_REQ_STATE;
s.init_state.url_bucket = "myname";
const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, "put_obj", script);
ASSERT_EQ(rc, 0);
ASSERT_EQ(s.init_state.url_bucket, "othername");
}
TEST(TestRGWLua, WriteBucketFail)
{
const std::string script = R"(
assert(Request.Bucket)
assert(Request.Bucket.Name == "myname")
Request.Bucket.Name = "othername"
)";
DEFINE_REQ_STATE;
rgw_bucket b;
b.name = "myname";
s.bucket.reset(new sal::RadosBucket(nullptr, b));
const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, "put_obj", script);
ASSERT_NE(rc, 0);
}
TEST(TestRGWLua, GenericAttributes)
{
const std::string script = R"(