]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add permissions and bucket to es query
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 22 Mar 2017 21:01:34 +0000 (14:01 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 30 May 2017 20:24:41 +0000 (13:24 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_es_query.cc
src/rgw/rgw_es_query.h
src/rgw/rgw_sync_module_es_rest.cc

index dd4a2c57416f31a589e217987d9bed81166b61c0..a916b86ece822992ae47a3b38d31b963ac5a5237 100644 (file)
@@ -130,6 +130,7 @@ class ESQueryNode_Bool : public ESQueryNode {
   ESQueryNode *second{nullptr};
 public:
   ESQueryNode_Bool() {}
+  ESQueryNode_Bool(const string& _op, ESQueryNode *_first, ESQueryNode *_second) : op(_op), first(_first), second(_second) {}
   bool init(ESQueryStack *s) {
     bool valid = s->pop(&op);
     if (!valid) {
@@ -190,6 +191,11 @@ public:
 class ESQueryNode_Op_Equal : public ESQueryNode_Op {
 public:
   ESQueryNode_Op_Equal() {}
+  ESQueryNode_Op_Equal(const string& f, const string& v) {
+    op = "==";
+    field = f;
+    val = v;
+  }
 
   virtual void dump(Formatter *f) const {
     f->open_object_section("term");
@@ -466,6 +472,11 @@ bool ESQueryCompiler::compile() {
     return false;
   }
 
+  for (auto& c : eq_conds) {
+    ESQueryNode_Op_Equal *eq_node = new ESQueryNode_Op_Equal(c.first, c.second);
+    query_root = new ESQueryNode_Bool("and", eq_node, query_root);
+  }
+
   return true;
 }
 
index c8b83759db6b4785802c7f0f137d440982398a8d..9767725ae99a8981a8298fc637a53b5c59858391 100644 (file)
@@ -69,8 +69,14 @@ class ESQueryCompiler {
 
   bool convert(list<string>& infix);
 
+  list<pair<string, string> > eq_conds;
+
 public:
-  ESQueryCompiler(const string& query) : parser(query) {}
+  ESQueryCompiler(const string& query, list<pair<string, string> > *prepend_eq_conds) : parser(query) {
+    if (prepend_eq_conds) {
+      eq_conds = std::move(*prepend_eq_conds);
+    }
+  }
   ~ESQueryCompiler();
 
   bool compile();
index 458e0630265de56de1e9d709a9b8d8776fef760a..5b43977437ff68bf99b722d48ad5f67b67bd85b5 100644 (file)
@@ -131,7 +131,15 @@ void RGWMetadataSearchOp::execute()
   if (op_ret < 0)
     return;
 
-  ESQueryCompiler es_query(expression);
+  list<pair<string, string> > conds;
+
+  conds.push_back(make_pair("permissions", s->user->user_id.to_str()));
+
+  if (!s->bucket_name.empty()) {
+    conds.push_back(make_pair("bucket", s->bucket_name));
+  }
+
+  ESQueryCompiler es_query(expression, &conds);
   
   bool valid = es_query.compile();
   if (!valid) {
@@ -204,6 +212,7 @@ public:
     for (auto& i : response.hits.hits) {
       es_index_obj_response& e = i.source;
       s->formatter->open_object_section("Contents");
+      s->formatter->dump_string("Bucket", e.bucket);
       s->formatter->dump_string("Key", e.key.name);
       string instance = (!e.key.instance.empty() ? e.key.instance : "null");
       s->formatter->dump_string("Instance", instance.c_str());