Merge pull request #42102 from Matan-B/lua-request-userId

rgw: Added request field to lua scripting
This commit is contained in:
Yuval Lifshitz 2021-07-19 18:01:27 +03:00 committed by GitHub
commit 6fb6a8e3ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -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
--------------------

View File

@ -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());
}

View File

@ -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"(