mirror of
https://github.com/ceph/ceph
synced 2025-02-22 02:27:29 +00:00
Merge pull request #42102 from Matan-B/lua-request-userId
rgw: Added request field to lua scripting
This commit is contained in:
commit
6fb6a8e3ea
@ -282,6 +282,12 @@ Request Fields
|
||||
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
|
||||
| ``Request.Tags`` | table | object tags map | yes | no | no |
|
||||
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
|
||||
| ``Request.User`` | table | user that triggered the request | no | no | no |
|
||||
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
|
||||
| ``Request.User.Tenant`` | string | triggering user tenant | no | no | no |
|
||||
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
|
||||
| ``Request.User.Id`` | string | triggering user id | no | no | no |
|
||||
+----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
|
||||
|
||||
Request Functions
|
||||
--------------------
|
||||
|
@ -761,6 +761,12 @@ struct RequestMetaTable : public EmptyMetaTable {
|
||||
pushstring(L, s->trans_id);
|
||||
} else if (strcasecmp(index, "Tags") == 0) {
|
||||
create_metatable<StringMapMetaTable<RGWObjTags::tag_map_t>>(L, false, &(s->tagset.get_tags()));
|
||||
} else if (strcasecmp(index, "User") == 0) {
|
||||
if (!s->user) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
create_metatable<UserMetaTable>(L, false, const_cast<rgw_user*>(&(s->user->get_id())));
|
||||
}
|
||||
} else {
|
||||
return error_unknown_field(L, index, TableName());
|
||||
}
|
||||
|
@ -494,6 +494,26 @@ TEST(TestRGWLua, Acl)
|
||||
ASSERT_EQ(rc, 0);
|
||||
}
|
||||
|
||||
TEST(TestRGWLua, User)
|
||||
{
|
||||
const std::string script = R"(
|
||||
assert(Request.User)
|
||||
assert(Request.User.Id == "myid")
|
||||
assert(Request.User.Tenant == "mytenant")
|
||||
)";
|
||||
|
||||
DEFINE_REQ_STATE;
|
||||
|
||||
rgw_user u;
|
||||
u.tenant = "mytenant";
|
||||
u.id = "myid";
|
||||
s.user.reset(new sal::RadosUser(nullptr, u));
|
||||
|
||||
const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, "put_obj", script);
|
||||
ASSERT_EQ(rc, 0);
|
||||
}
|
||||
|
||||
|
||||
TEST(TestRGWLua, UseFunction)
|
||||
{
|
||||
const std::string script = R"(
|
||||
|
Loading…
Reference in New Issue
Block a user