]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: configurable list of object attributes
authorYehuda Sadeh <yehuda@inktank.com>
Fri, 30 Nov 2012 07:07:26 +0000 (23:07 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 12 Dec 2012 21:45:21 +0000 (13:45 -0800)
Fixes: #3535
New object attributes are now configurable. A list
can be specified via the 'rgw extended http attrs'
config param.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
doc/radosgw/config-ref.rst
src/common/config_opts.h
src/rgw/rgw_main.cc
src/rgw/rgw_rest.cc
src/rgw/rgw_rest.h

index 564270aa602dc04d4cadb3f18d7417cc643856c2..6a7fa46e74382df2959153ee0c76f3220b6c750b 100644 (file)
@@ -228,3 +228,9 @@ set automatically.
 :Description: Total backlog data size for unix domain socket operations logging
 :Type: Integer
 :Default: ``5ul << 20``
+
+``rgw extended http attrs``
+:Description: Add new set of attributes that could be set on an object
+:Type: String
+:Default: N/A
+:Example: "content_foo, content_bar"
index a9a2a159ca86ebae8f78a6df13384c8363699e8a..b9e317b82dc2031ea152f4f3de553bc324395f10 100644 (file)
@@ -486,6 +486,7 @@ OPTION(rgw_gc_processor_period, OPT_INT, 3600)  // gc processor cycle time
 OPTION(rgw_s3_success_create_obj_status, OPT_INT, 0) // alternative success status response for create-obj (0 - default)
 OPTION(rgw_resolve_cname, OPT_BOOL, false)  // should rgw try to resolve hostname as a dns cname record
 OPTION(rgw_obj_stripe_size, OPT_INT, 4 << 20)
+OPTION(rgw_extended_http_attrs, OPT_STR, "") // list of extended attrs that can be set on objects (beyond the default)
 
 OPTION(mutex_perf_counter, OPT_BOOL, false) // enable/disable mutex perf counter
 
index 5f52dde228d7205c10b00db6c6dc2a5f18502cf8..29c10dd0eeb842fa2706bbcf44e84ad4c170f6af 100644 (file)
@@ -433,7 +433,7 @@ int main(int argc, const char **argv)
   rgw_tools_init(g_ceph_context);
 
   rgw_init_resolver();
-  rgw_rest_init();
+  rgw_rest_init(g_ceph_context);
   
   curl_global_init(CURL_GLOBAL_ALL);
   
index 9d978d1a4f13aed6e794c07547641f489e5e3698..c8c0bacf0a0cc561a3f83c2e1787a847f2b3a521 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "common/Formatter.h"
 #include "common/utf8.h"
+#include "include/str_list.h"
 #include "rgw_common.h"
 #include "rgw_rados.h"
 #include "rgw_formats.h"
@@ -37,15 +38,6 @@ static struct rgw_http_attr rgw_to_http_attr_list[] = {
 };
 
 
-map<string, string> rgw_to_http_attrs;
-
-void rgw_rest_init()
-{
-  for (struct rgw_http_attr *attr = rgw_to_http_attr_list; attr->rgw_attr; attr++) {
-    rgw_to_http_attrs[attr->rgw_attr] = attr->http_attr;
-  }
-}
-
 struct generic_attr {
   const char *http_header;
   const char *rgw_attr;
@@ -64,6 +56,106 @@ struct generic_attr generic_attrs[] = {
   { NULL, NULL },
 };
 
+map<string, string> rgw_to_http_attrs;
+static map<string, string> generic_attrs_map;
+
+/*
+ * make attrs look_like_this
+ */
+string lowercase_http_attr(const string& orig)
+{
+  const char *s = orig.c_str();
+  char buf[orig.size() + 1];
+  buf[orig.size()] = '\0';
+
+  for (size_t i = 0; i < orig.size(); ++i, ++s) {
+    switch (*s) {
+      case '-':
+       buf[i] = '_';
+       break;
+      default:
+       buf[i] = tolower(*s);
+    }
+  }
+  return string(buf);
+}
+
+/*
+ * make attrs LOOK_LIKE_THIS
+ */
+string uppercase_http_attr(const string& orig)
+{
+  const char *s = orig.c_str();
+  char buf[orig.size() + 1];
+  buf[orig.size()] = '\0';
+
+  for (size_t i = 0; i < orig.size(); ++i, ++s) {
+    switch (*s) {
+      case '-':
+       buf[i] = '_';
+       break;
+      default:
+       buf[i] = toupper(*s);
+    }
+  }
+  return string(buf);
+}
+
+/*
+ * make attrs Look-Like-This
+ */
+string camelcase_dash_http_attr(const string& orig)
+{
+  const char *s = orig.c_str();
+  char buf[orig.size() + 1];
+  buf[orig.size()] = '\0';
+
+  bool last_sep = true;
+
+  for (size_t i = 0; i < orig.size(); ++i, ++s) {
+    switch (*s) {
+      case '_':
+       buf[i] = '-';
+       last_sep = true;
+       break;
+      default:
+       if (last_sep)
+         buf[i] = toupper(*s);
+       else
+         buf[i] = tolower(*s);
+       last_sep = false;
+    }
+  }
+  return string(buf);
+}
+
+void rgw_rest_init(CephContext *cct)
+{
+  for (struct rgw_http_attr *attr = rgw_to_http_attr_list; attr->rgw_attr; attr++) {
+    rgw_to_http_attrs[attr->rgw_attr] = attr->http_attr;
+  }
+
+  for (struct generic_attr *gen_attr = generic_attrs; gen_attr->http_header; gen_attr++) {
+    generic_attrs_map[gen_attr->http_header] = gen_attr->rgw_attr;
+  }
+
+  list<string> extended_http_attrs;
+  get_str_list(cct->_conf->rgw_extended_http_attrs, extended_http_attrs);
+
+  list<string>::iterator iter;
+  for (iter = extended_http_attrs.begin(); iter != extended_http_attrs.end(); ++iter) {
+    string rgw_attr = RGW_ATTR_PREFIX;
+    rgw_attr.append(lowercase_http_attr(*iter));
+
+    rgw_to_http_attrs[rgw_attr] = camelcase_dash_http_attr(*iter);
+
+    string http_header = "HTTP_";
+    http_header.append(uppercase_http_attr(*iter));
+
+    generic_attrs_map[http_header] = rgw_attr;
+  }
+}
+
 static void dump_status(struct req_state *s, const char *status)
 {
   int r = s->cio->print("Status: %s\n", status);
@@ -1075,10 +1167,11 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio)
     s->content_length = atoll(s->length);
   }
 
-  for (int i = 0; generic_attrs[i].http_header; i++) {
-    const char *env = s->env->get(generic_attrs[i].http_header);
+  map<string, string>::iterator giter;
+  for (giter = generic_attrs_map.begin(); giter != generic_attrs_map.end(); ++giter) {
+    const char *env = s->env->get(giter->first.c_str());
     if (env) {
-      s->generic_attrs[generic_attrs[i].rgw_attr] = env;
+      s->generic_attrs[giter->second] = env;
     }
   }
 
index 35c34a6cdba351277fd7ad0f1f4e9f83e5f552b8..00ad584575eb170901664266cc09a8fc9b910e2e 100644 (file)
@@ -8,7 +8,7 @@
 
 extern std::map<std::string, std::string> rgw_to_http_attrs;
 
-extern void rgw_rest_init();
+extern void rgw_rest_init(CephContext *cct);
 
 extern void rgw_flush_formatter_and_reset(struct req_state *s,
                                         ceph::Formatter *formatter);