]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add package version support to lua scripting 41927/head
authorMatan Breizman <Matan.Brz@gmail.com>
Tue, 29 Jun 2021 13:05:29 +0000 (13:05 +0000)
committerMatan Breizman <Matan.Brz@gmail.com>
Tue, 29 Jun 2021 13:05:29 +0000 (13:05 +0000)
This patch allows users to set the package version when adding packages
to rgw's luarocks package manager.

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

index 0f385c46fefa5b13631c0e4addd8c6d7627a498c..326eaf6a7a954b7899c5add536d4cc2d37ee4e3e 100644 (file)
@@ -57,6 +57,20 @@ To add a package to the allowlist:
   # radosgw-admin script-package add --package={package name} [--allow-compilation]
 
 
+To add a specific version of a package to the allowlist:
+
+::
+
+  # radosgw-admin script-package add --package='{package name} {package version}' [--allow-compilation]
+
+
+* When adding a diffrent version of a package which already exists in the list, the newly
+  added version will override the existing one.
+
+* When adding a package without a version specified, the latest version of the package
+  will be added.
+
+
 To remove a package from the allowlist:
 
 ::
@@ -64,6 +78,17 @@ To remove a package from the allowlist:
   # radosgw-admin script-package rm --package={package name}
 
 
+To remove a specific version of a package from the allowlist:
+
+::
+
+  # radosgw-admin script-package rm --package='{package name} {package version}'
+
+
+* When removing a package without a version specified, any existing versions of the
+  package will be removed.
+
+
 To print the list of packages in the allowlist:
 
 ::
index 7d5ba3635eda990eab5df952a04ea1a3d80b638e..946a6ff814184c1bed81d78dad10e8a2cb77ef82 100644 (file)
@@ -118,6 +118,13 @@ int add_package(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_
     return -EINVAL;
   }
   
+  //replace previous versions of the package
+  const std::string package_name_no_version = package_name.substr(0, package_name.find(" "));
+  ret = remove_package(dpp, store, y, package_name_no_version);
+  if (ret < 0) {
+    return ret;
+  }
+
   // add package to list
   const bufferlist empty_bl;
   std::map<std::string, bufferlist> new_package{{package_name, empty_bl}};
@@ -134,14 +141,34 @@ int add_package(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_
 
 int remove_package(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_yield y, const std::string& package_name) {
   librados::ObjectWriteOperation op;
-  op.omap_rm_keys(std::set<std::string>({package_name}));
-  const auto ret = rgw_rados_operate(dpp, *(static_cast<rgw::sal::RadosStore*>(store)->getRados()->get_lc_pool_ctx()),
-    PACKAGE_LIST_OBJECT_NAME, &op, y);
-
-  if (ret < 0) {
+  size_t pos = package_name.find(" ");
+  if (pos != string::npos) {
+    // remove specfic version of the the package
+    op.omap_rm_keys(std::set<std::string>({package_name}));
+    auto ret = rgw_rados_operate(dpp, *(static_cast<rgw::sal::RadosStore*>(store)->getRados()->get_lc_pool_ctx()),
+        PACKAGE_LIST_OBJECT_NAME, &op, y);
+    if (ret < 0) {
+        return ret;
+    }
+    return 0;
+  }
+  // otherwise, remove any existing versions of the package
+  packages_t packages;
+  auto ret = list_packages(dpp, store, y, packages);
+  if (ret < 0 && ret != -ENOENT) {
     return ret;
   }
-
+  for(const auto& package : packages) {
+    const std::string package_no_version = package.substr(0, package.find(" "));
+    if (package_no_version.compare(package_name) == 0) {
+        op.omap_rm_keys(std::set<std::string>({package}));
+        ret = rgw_rados_operate(dpp, *(static_cast<rgw::sal::RadosStore*>(store)->getRados()->get_lc_pool_ctx()),
+            PACKAGE_LIST_OBJECT_NAME, &op, y);
+        if (ret < 0) {
+            return ret;
+        }
+    }
+  }
   return 0;
 }
 
@@ -197,13 +224,11 @@ int install_packages(const DoutPrefixProvider *dpp, rgw::sal::Store* store, opti
   // the lua rocks install dir will be created by luarocks the first time it is called
   for (const auto& package : packages) {
     bp::ipstream is;
-    bp::child c(p, "install", "--lua-version", CEPH_LUA_VERSION, "--tree", luarocks_path, "--deps-mode", "one", package, 
-        bp::std_in.close(),
-        (bp::std_err & bp::std_out) > is);
+    const auto cmd = p.string() + " install --lua-version " + CEPH_LUA_VERSION + " --tree " + luarocks_path + " --deps-mode one " + package;
+    bp::child c(cmd, bp::std_in.close(), (bp::std_err & bp::std_out) > is);
 
     // once package reload is supported, code should yield when reading output
-    std::string line = "CMD: luarocks install --lua-version " + std::string(CEPH_LUA_VERSION) + std::string(" --tree ") + 
-      luarocks_path + " --deps-mode one " + package;
+    std::string line = std::string("CMD: ") + cmd;
 
     do {
       if (!line.empty()) {