+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
| ``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 |
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
}
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 {
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"(