summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2012-11-29 23:07:26 -0800
committerYehuda Sadeh <yehuda@inktank.com>2012-12-12 13:45:21 -0800
commit3a95d97648e60f4eb167ea72eef991067c728581 (patch)
tree53178df89a36e3661a7b95d1ca0125fa631b1656
parent870872455789a3ab3f490ef50f6bc5bc09a3d8e5 (diff)
downloadceph-3a95d97648e60f4eb167ea72eef991067c728581.tar.gz
rgw: configurable list of object attributes
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>
-rw-r--r--doc/radosgw/config-ref.rst6
-rw-r--r--src/common/config_opts.h1
-rw-r--r--src/rgw/rgw_main.cc2
-rw-r--r--src/rgw/rgw_rest.cc117
-rw-r--r--src/rgw/rgw_rest.h2
5 files changed, 114 insertions, 14 deletions
diff --git a/doc/radosgw/config-ref.rst b/doc/radosgw/config-ref.rst
index 564270aa602..6a7fa46e743 100644
--- a/doc/radosgw/config-ref.rst
+++ b/doc/radosgw/config-ref.rst
@@ -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"
diff --git a/src/common/config_opts.h b/src/common/config_opts.h
index a9a2a159ca8..b9e317b82dc 100644
--- a/src/common/config_opts.h
+++ b/src/common/config_opts.h
@@ -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
diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc
index 5f52dde228d..29c10dd0eeb 100644
--- a/src/rgw/rgw_main.cc
+++ b/src/rgw/rgw_main.cc
@@ -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);
diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc
index 9d978d1a4f1..c8c0bacf0a0 100644
--- a/src/rgw/rgw_rest.cc
+++ b/src/rgw/rgw_rest.cc
@@ -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;
}
}
diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h
index 35c34a6cdba..00ad584575e 100644
--- a/src/rgw/rgw_rest.h
+++ b/src/rgw/rgw_rest.h
@@ -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);