]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Allow creation of buckets starting with underscore in RGW
authorcaleb miles <caleb.miles@inktank.com>
Fri, 5 Apr 2013 16:31:56 +0000 (09:31 -0700)
committercaleb miles <caleb.miles@inktank.com>
Fri, 5 Apr 2013 17:26:29 +0000 (10:26 -0700)
Signed-off-by caleb miles <caleb.miles@inktank.com>

src/common/config_opts.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3.h

index fbb6e083b62e757d929ff6f9e5ecf658ce4f099f..cb2fd391fc9130f62f19a36257ebb3139514abc9 100644 (file)
@@ -573,6 +573,7 @@ OPTION(rgw_extended_http_attrs, OPT_STR, "") // list of extended attrs that can
 OPTION(rgw_exit_timeout_secs, OPT_INT, 120) // how many seconds to wait for process to go down before exiting unconditionally
 OPTION(rgw_get_obj_window_size, OPT_INT, 16 << 20) // window size in bytes for single get obj request
 OPTION(rgw_get_obj_max_req_size, OPT_INT, 4 << 20) // max length of a single get obj rados op
+OPTION(rgw_relaxed_s3_bucket_names, OPT_BOOL, false) // enable relaxed bucket name rules for US region buckets
 
 OPTION(mutex_perf_counter, OPT_BOOL, false) // enable/disable mutex perf counter
 
index 78efa72aa5545263305cf67c099235978de7f079..b46ff8146630ec6a31cbdfcf6199b2a06c985838 100644 (file)
@@ -1742,7 +1742,7 @@ static bool looks_like_ip_address(const char *bucket)
   return (num_periods == 3);
 }
 
-int RGWHandler_ObjStore_S3::validate_bucket_name(const string& bucket)
+int RGWHandler_ObjStore_S3::validate_bucket_name(const string& bucket, bool relaxed_names)
 {
   int ret = RGWHandler_ObjStore::validate_bucket_name(bucket);
   if (ret < 0)
@@ -1751,10 +1751,13 @@ int RGWHandler_ObjStore_S3::validate_bucket_name(const string& bucket)
   if (bucket.size() == 0)
     return 0;
 
+  // bucket names must start with a number, letter, or underscore
   if (!(isalpha(bucket[0]) || isdigit(bucket[0]))) {
-    // bucket names must start with a number or letter
-    return -ERR_INVALID_BUCKET_NAME;
-  }
+    if (!relaxed_names)
+      return -ERR_INVALID_BUCKET_NAME;
+    else if (!(bucket[0] == '_' || bucket[0] == '.' || bucket[0] == '-'))
+      return -ERR_INVALID_BUCKET_NAME;
+  } 
 
   for (const char *s = bucket.c_str(); *s; ++s) {
     char c = *s;
@@ -1778,7 +1781,8 @@ int RGWHandler_ObjStore_S3::init(RGWRados *store, struct req_state *s, RGWClient
 {
   dout(10) << "s->object=" << (s->object ? s->object : "<NULL>") << " s->bucket=" << (s->bucket_name ? s->bucket_name : "<NULL>") << dendl;
 
-  int ret = validate_bucket_name(s->bucket_name_str);
+  bool relaxed_names = s->cct->_conf->rgw_relaxed_s3_bucket_names;
+  int ret = validate_bucket_name(s->bucket_name_str, relaxed_names);
   if (ret)
     return ret;
   ret = validate_object_name(s->object_str);
index 277ebf1ffb8569ae63dd4f5ece271bedc906097f..204bee84456c806c978544dd5b9567fd26f69490 100644 (file)
@@ -261,7 +261,10 @@ public:
   RGWHandler_Auth_S3() : RGWHandler_ObjStore() {}
   virtual ~RGWHandler_Auth_S3() {}
 
-  virtual int validate_bucket_name(const string& bucket) { return 0; }
+  virtual int validate_bucket_name(const string& bucket) {
+    return 0;
+  }
+
   virtual int validate_object_name(const string& bucket) { return 0; }
 
   virtual int init(RGWRados *store, struct req_state *state, RGWClientIO *cio);
@@ -278,7 +281,7 @@ public:
   RGWHandler_ObjStore_S3() : RGWHandler_ObjStore() {}
   virtual ~RGWHandler_ObjStore_S3() {}
 
-  int validate_bucket_name(const string& bucket);
+  int validate_bucket_name(const string& bucket, bool relaxed_names);
 
   virtual int init(RGWRados *store, struct req_state *state, RGWClientIO *cio);
   virtual int authorize() {