]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgwlc: represent lc filter flags as XML elements
authorMatt Benjamin <mbenjamin@redhat.com>
Fri, 1 Jul 2022 12:54:32 +0000 (08:54 -0400)
committerMatt Benjamin <mbenjamin@redhat.com>
Sun, 17 Jul 2022 22:37:17 +0000 (18:37 -0400)
Suggested by Casey in review, this makes the XML prettier.

also: fix filter parsing, remove unused code

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_lc.cc
src/rgw/rgw_lc.h
src/rgw/rgw_lc_s3.cc
src/test/rgw/test_rgw_lc.cc

index 14e64bc952a433c686473d1f4dcfa9e5086f7119..f7d9f7cfa90d5edc2e4ffe7ca981e59f82914726 100644 (file)
@@ -56,31 +56,6 @@ const char* LC_STATUS[] = {
 
 using namespace librados;
 
-static inline std::string_view sv_trim(std::string_view str) {
-  while (isspace(str.front())) {
-    str.remove_prefix(1);
-  }
-  while (isspace(str.back())) {
-    str.remove_suffix(1);
-  }
-  return str;
-}
-
-uint32_t LCFilter::recognize_flags(const std::string& flag_expr)
-{
-  uint32_t flags = 0;
-  ceph::split sp_flags(flag_expr); // default separators are ,;=\t\n
-  for (auto it = sp_flags.begin(); it != sp_flags.end(); ++it) {
-    auto token = sv_trim(string_view{*it});
-    for (auto& flag_tok : LCFilter::filter_flags) {
-      if (token == flag_tok.name) {
-       flags |= LCFilter::make_flag(flag_tok.bit);
-      }
-    }
-  }
-  return flags;
-}
-
 bool LCRule::valid() const
 {
   if (id.length() > MAX_ID_LEN) {
index 81294bc95f332a23fe1bf276436dec15a09c110b..42f061d7a31023f4bcd58025aea2ffe1bdfb0b98 100644 (file)
@@ -201,7 +201,6 @@ protected:
   uint32_t flags;
 
 public:
-static uint32_t recognize_flags(const std::string& flag_expr);
 
   LCFilter() : flags(make_flag(LCFlagType::none))
     {}
index 4b966238e823bfac55c5d7bf54499c7f7b44799f..b815a6ecc6adf298f950d6ec4c558662d3245036 100644 (file)
@@ -146,10 +146,9 @@ void LCFilter_S3::decode_xml(XMLObj *obj)
 
   RGWXMLDecoder::decode_xml("Prefix", prefix, o);
 
-  /* parse optional flags (extension) */
-  auto flags_iter = o->find("Flag");
-  while (auto flag_xml = flags_iter.get_next()){
-    flags |= LCFilter::recognize_flags(flag_xml->get_data());
+  /* parse optional ArchiveZone flag (extension) */
+  if (o->find_first("ArchiveZone")) {
+    flags |= make_flag(LCFlagType::ArchiveZone);
   }
 
   obj_tags.clear(); // why is this needed?
index 2ff992862003c6fe925fe0530ae9555b97af7747..83a4cac676df9f67fcca9feabd8344d61ae03ca4 100644 (file)
@@ -47,12 +47,7 @@ TEST(TestLCFilterDecoder, XMLDoc1)
 static const char* xmldoc_2 =
 R"(<Filter>
    <And>
-      <Flag>
-         ArchiveZone
-      </Flag>
-      <Flag>
-         ArchiveZone
-      </Flag>
+      <ArchiveZone />
       <Tag>
          <Key>spongebob</Key>
          <Value>squarepants</Value>
@@ -69,12 +64,12 @@ TEST(TestLCFilterDecoder, XMLDoc2)
   LCFilter_S3 filter;
   auto result = RGWXMLDecoder::decode_xml("Filter", filter, &parser, true);
   ASSERT_TRUE(result);
-  /* check repeated Tag element */
+  /* check tags */
   auto tag_map = filter.get_tags().get_tags();
   auto val1 = tag_map.find("spongebob");
   ASSERT_EQ(val1->second, "squarepants");
   /* check our flags */
-  ASSERT_EQ(filter.get_flags(), uint32_t(LCFlagType::ArchiveZone));
+  ASSERT_EQ(filter.get_flags(), LCFilter::make_flag(LCFlagType::ArchiveZone));
 }
 
 // invalid And element placement