]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: Adding missing field to lua scripting
authorMatan Breizman <Matan.Brz@gmail.com>
Tue, 29 Jun 2021 15:01:23 +0000 (15:01 +0000)
committerMatan Breizman <Matan.Brz@gmail.com>
Thu, 1 Jul 2021 14:54:50 +0000 (14:54 +0000)
adding "User Identity" field to lua scripting

Signed-off-by: Matan Breizman <Matan.Brz@gmail.com>
doc/radosgw/lua-scripting.rst
src/rgw/rgw_lua_request.cc
src/test/rgw/test_rgw_lua.cc

index 0f385c46fefa5b13631c0e4addd8c6d7627a498c..b36e2244a2629d0a6d93236099f1bd8deb361286 100644 (file)
@@ -257,6 +257,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
 --------------------
index ce7e9235219ffa8b47fa991ecf3ecc648abe4582..a8ea4ee19b2c9f4a3b88c24cd051c145ceb0a063 100644 (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());
     }
index 9908ff8e5e9e0bc10ded67b4bcf6857301dd36f2..d8cc355c6303d32816d831343626c273bb9f9af7 100644 (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"(