]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
swift /info implementation.
authorPritha Srivastava <prsrivas@redhat.com>
Wed, 8 Jun 2016 06:21:32 +0000 (11:51 +0530)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 14 Jul 2016 13:47:11 +0000 (15:47 +0200)
Implementation for swift /info API.

Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
Conflicts:
src/rgw/rgw_common.h
src/rgw/rgw_main.cc
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_rest_swift.h

src/rgw/rgw_common.h
src/rgw/rgw_main.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest.cc
src/rgw/rgw_rest.h
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_rest_swift.h

index 2c581f0536e6ac474a058c772b9902d737107707..64d0e3ac14a989bab87cd56de8e68fd6e87fb5c4 100644 (file)
@@ -426,6 +426,7 @@ enum RGWOpType {
   RGW_OP_SET_ATTRS,
   RGW_OP_GET_CROSS_DOMAIN_POLICY,
   RGW_OP_GET_HEALTH_CHECK,
+  RGW_OP_GET_INFO,
 
   /* rgw specific */
   RGW_OP_ADMIN_SET_METADATA
index 227dc7a4c79eac1e92c7d1353baa88d73a80db0e..c66e96e5ecd8e02c4d4f21de56610115d4841cee 100644 (file)
@@ -366,6 +366,9 @@ int main(int argc, const char **argv)
     swift_resource->register_resource("healthcheck",
                           set_logging(new RGWRESTMgr_SWIFT_HealthCheck));
 
+    RGWRESTMgr* const swift_info_resource = new RGWRESTMgr_SWIFT_Info;
+    rest.register_resource("info", set_logging(swift_info_resource));
+
     if (! swift_at_root) {
       rest.register_resource(g_conf->rgw_swift_url_prefix,
                           set_logging(swift_resource));
index 67240443f918325149dd964373915295b4943d29..102002d16861a42d771874b554fea0c50f57d870 100644 (file)
@@ -1394,6 +1394,17 @@ public:
   virtual uint32_t op_mask() { return RGW_OP_TYPE_DELETE; }
 };
 
+class RGWInfo: public RGWOp {
+public:
+  RGWInfo() = default;
+  ~RGWInfo() = default;
+
+  int verify_permission() override { return 0; }
+  const string name() override { return "get info"; }
+  RGWOpType get_type() override { return RGW_OP_GET_INFO; }
+  uint32_t op_mask() override { return RGW_OP_TYPE_READ; }
+};
+
 class RGWHandler {
 protected:
   RGWRados *store;
index 848e99efd854efb4129136b0ef605c749430316b..7e21a75bb52039eee7dd38f2aaabad053f0a9e0b 100644 (file)
@@ -1478,7 +1478,7 @@ int RGWHandler_REST::validate_bucket_name(const string& bucket)
     // Name too short
     return -ERR_INVALID_BUCKET_NAME;
   }
-  else if (len > 255) {
+  else if (len > MAX_BUCKET_NAME_LEN) {
     // Name too long
     return -ERR_INVALID_BUCKET_NAME;
   }
@@ -1493,7 +1493,7 @@ int RGWHandler_REST::validate_bucket_name(const string& bucket)
 int RGWHandler_REST::validate_object_name(const string& object)
 {
   int len = object.size();
-  if (len > 1024) {
+  if (len > MAX_OBJ_NAME_LEN) {
     // Name too long
     return -ERR_INVALID_OBJECT_NAME;
   }
index d9c1f0e1e3b4d2c2e3d2ad9390e77c96c4797f00..f4d079cd5fb2af4c7649a5f46d780e9679a87476 100644 (file)
@@ -364,6 +364,12 @@ public:
   virtual int get_params();
 };
 
+class RGWInfo_ObjStore : public RGWInfo {
+public:
+    RGWInfo_ObjStore() = default;
+    ~RGWInfo_ObjStore() = default;
+};
+
 class RGWRESTOp : public RGWOp {
 protected:
   int http_ret;
@@ -395,6 +401,9 @@ protected:
   static int allocate_formatter(struct req_state *s, int default_formatter,
                                bool configurable);
 public:
+  static constexpr int MAX_BUCKET_NAME_LEN = 255;
+  static constexpr int MAX_OBJ_NAME_LEN = 1024;
+
   RGWHandler_REST() {}
   virtual ~RGWHandler_REST() {}
 
index b7ec921cf02674c688ccb896c8b91141737e4029..3669b87d371da33dfcd66f4bed33c1d21c802129 100644 (file)
@@ -5,6 +5,7 @@
 #include <boost/utility/in_place_factory.hpp>
 
 #include "include/assert.h"
+#include "ceph_ver.h"
 
 #include "common/Formatter.h"
 #include "common/utf8.h"
@@ -1377,6 +1378,133 @@ void RGWGetHealthCheck_ObjStore_SWIFT::send_response()
   }
 }
 
+const vector<pair<string, RGWInfo_ObjStore_SWIFT::info>> RGWInfo_ObjStore_SWIFT::swift_info =
+{
+    {"bulk_delete", {false, nullptr}},
+    {"container_quotas", {false, nullptr}},
+    {"swift", {false, RGWInfo_ObjStore_SWIFT::list_swift_data}},
+    {"tempurl", { false, RGWInfo_ObjStore_SWIFT::list_tempurl_data}},
+    {"slo", {false, RGWInfo_ObjStore_SWIFT::list_slo_data}},
+    {"account_quotas", {false, nullptr}},
+    {"staticweb", {false, nullptr}},
+    {"tempauth", {false, nullptr}},
+};
+
+void RGWInfo_ObjStore_SWIFT::execute()
+{
+  bool is_admin_info_enabled = false;
+
+  const string& swiftinfo_sig = s->info.args.get("swiftinfo_sig");
+  const string& swiftinfo_expires = s->info.args.get("swiftinfo_expires");
+
+  if (!swiftinfo_sig.empty() &&
+      !swiftinfo_expires.empty() &&
+      !is_expired(swiftinfo_expires, s->cct)) {
+    is_admin_info_enabled = true;
+  }
+
+  s->formatter->open_object_section("info");
+
+  for (const auto& pair : swift_info) {
+    if(!is_admin_info_enabled && pair.second.is_admin_info)
+      continue;
+
+    if (!pair.second.list_data) {
+      s->formatter->open_object_section((pair.first).c_str());
+      s->formatter->close_section();
+    }
+    else {
+      pair.second.list_data(*(s->formatter), *(s->cct->_conf), *store);
+    }
+  }
+
+  s->formatter->close_section();
+}
+
+void RGWInfo_ObjStore_SWIFT::send_response()
+{
+  if (op_ret <  0) {
+    op_ret = STATUS_NO_CONTENT;
+  }
+  set_req_state_err(s, op_ret);
+  dump_errno(s);
+  end_header(s, this);
+  rgw_flush_formatter_and_reset(s, s->formatter);
+}
+
+void RGWInfo_ObjStore_SWIFT::list_swift_data(Formatter& formatter,
+                                              const md_config_t& config,
+                                              RGWRados& store)
+{
+  formatter.open_object_section("swift");
+  formatter.dump_int("max_file_size", config.rgw_max_put_size);
+  formatter.dump_int("container_listing_limit", RGW_LIST_BUCKETS_LIMIT_MAX);
+
+  string ceph_version(CEPH_GIT_NICE_VER);
+  formatter.dump_string("version", ceph_version);
+  formatter.dump_int("max_meta_name_length", 81);
+
+  formatter.open_array_section("policies");
+  RGWZoneGroup& zonegroup = store.get_zonegroup();
+
+  for (const auto& placement_targets : zonegroup.placement_targets) {
+    formatter.open_object_section("policy");
+    if (placement_targets.second.name.compare(zonegroup.default_placement) == 0)
+      formatter.dump_bool("default", true);
+    formatter.dump_string("name", placement_targets.second.name.c_str());
+    formatter.close_section();
+  }
+  formatter.close_section();
+
+  formatter.dump_int("max_object_name_size", RGWHandler_REST::MAX_OBJ_NAME_LEN);
+  formatter.dump_bool("strict_cors_mode", true);
+  formatter.dump_int("max_container_name_length", RGWHandler_REST::MAX_BUCKET_NAME_LEN);
+  formatter.close_section();
+}
+
+void RGWInfo_ObjStore_SWIFT::list_tempurl_data(Formatter& formatter,
+                                                const md_config_t& config,
+                                                RGWRados& store)
+{
+  formatter.open_object_section("tempurl");
+  formatter.open_array_section("methods");
+  formatter.dump_string("methodname", "GET");
+  formatter.dump_string("methodname", "HEAD");
+  formatter.dump_string("methodname", "PUT");
+  formatter.dump_string("methodname", "POST");
+  formatter.dump_string("methodname", "DELETE");
+  formatter.close_section();
+  formatter.close_section();
+}
+
+void RGWInfo_ObjStore_SWIFT::list_slo_data(Formatter& formatter,
+                                            const md_config_t& config,
+                                            RGWRados& store)
+{
+  formatter.open_object_section("slo");
+  formatter.dump_int("max_manifest_segments", config.rgw_max_slo_entries);
+  formatter.close_section();
+}
+
+bool RGWInfo_ObjStore_SWIFT::is_expired(const std::string& expires, CephContext* cct)
+{
+  string err;
+  const utime_t now = ceph_clock_now(cct);
+  const uint64_t expiration = (uint64_t)strict_strtoll(expires.c_str(),
+                                                       10, &err);
+  if (!err.empty()) {
+    ldout(cct, 5) << "failed to parse siginfo_expires: " << err << dendl;
+    return true;
+  }
+
+  if (expiration <= (uint64_t)now.sec()) {
+    ldout(cct, 5) << "siginfo expired: " << expiration << " <= " << now.sec() << dendl;
+    return true;
+  }
+
+  return false;
+}
+
 RGWOp *RGWHandler_REST_Service_SWIFT::op_get()
 {
   return new RGWListBuckets_ObjStore_SWIFT;
@@ -1403,6 +1531,11 @@ RGWOp *RGWHandler_REST_Service_SWIFT::op_delete()
   return NULL;
 }
 
+RGWOp* RGWHandler_REST_SWIFT_Info::op_get() {
+
+  return new RGWInfo_ObjStore_SWIFT;
+}
+
 RGWOp *RGWHandler_REST_Bucket_SWIFT::get_obj_op(bool get_data)
 {
   if (is_acl_op()) {
@@ -1784,12 +1917,23 @@ int RGWHandler_REST_SWIFT::init_from_header(struct req_state *s)
     blen = sprintf(buf, "/%s/v1%s",
                    g_conf->rgw_swift_url_prefix.c_str(), tenant_path.c_str());
   }
-  if (s->decoded_uri[0] != '/' ||
-    s->decoded_uri.compare(0, blen, buf) !=  0) {
-    return -ENOENT;
+
+  string uri = "/info";
+  if ((s->decoded_uri[0] != '/' ||
+    s->decoded_uri.compare(0, blen, buf) !=  0) &&
+    s->decoded_uri.compare(uri) != 0) {
+        return -ENOENT;
+  }
+
+  int ret;
+  //Set the formatter to JSON by default for /info api
+  if (s->decoded_uri.compare(uri) == 0) {
+    ret = allocate_formatter(s, RGW_FORMAT_JSON, false);
+  }
+  else {
+    ret = allocate_formatter(s, RGW_FORMAT_PLAIN, true);
   }
 
-  int ret = allocate_formatter(s, RGW_FORMAT_PLAIN, true);
   if (ret < 0)
     return ret;
 
@@ -1895,3 +2039,13 @@ RGWHandler_REST* RGWRESTMgr_SWIFT::get_handler(struct req_state *s)
 
   return new RGWHandler_REST_Obj_SWIFT;
 }
+
+RGWHandler_REST* RGWRESTMgr_SWIFT_Info::get_handler(struct req_state *s)
+{
+  int ret = RGWHandler_REST_SWIFT::init_from_header(s);
+  if (ret < 0) {
+    return nullptr;
+  }
+
+  return new RGWHandler_REST_SWIFT_Info;
+}
index 568881cedab5fb512fd6646cd118d0f3ad1e1427..3c837c98cd8ab3599e9725b01c4ae339cf080c24 100644 (file)
@@ -185,8 +185,30 @@ public:
   void send_response();
 };
 
+class RGWInfo_ObjStore_SWIFT : public RGWInfo_ObjStore {
+protected:
+  struct info
+  {
+    bool is_admin_info;
+    function<void (Formatter&, const md_config_t&, RGWRados&)> list_data;
+  };
+
+  static const vector<pair<string, struct info>> swift_info;
+public:
+  RGWInfo_ObjStore_SWIFT() {}
+  ~RGWInfo_ObjStore_SWIFT() {}
+
+  void execute() override;
+  void send_response() override;
+  static void list_swift_data(Formatter& formatter, const md_config_t& config, RGWRados& store);
+  static void list_tempurl_data(Formatter& formatter, const md_config_t& config, RGWRados& store);
+  static void list_slo_data(Formatter& formatter, const md_config_t& config, RGWRados& store);
+  static bool is_expired(const std::string& expires, CephContext* cct);
+};
+
 class RGWHandler_REST_SWIFT : public RGWHandler_REST {
   friend class RGWRESTMgr_SWIFT;
+  friend class RGWRESTMgr_SWIFT_Info;
 protected:
   virtual bool is_acl_op() {
     return false;
@@ -218,6 +240,14 @@ public:
   virtual ~RGWHandler_REST_Service_SWIFT() {}
 };
 
+class RGWHandler_REST_SWIFT_Info : public RGWHandler_REST_SWIFT {
+protected:
+  RGWOp *op_get();
+public:
+  RGWHandler_REST_SWIFT_Info() = default;
+  virtual ~RGWHandler_REST_SWIFT_Info() = default;
+};
+
 class RGWHandler_REST_Bucket_SWIFT : public RGWHandler_REST_SWIFT {
 protected:
   bool is_obj_update_op() {
@@ -395,4 +425,11 @@ public:
 };
 
 
+class RGWRESTMgr_SWIFT_Info : public RGWRESTMgr {
+public:
+  RGWRESTMgr_SWIFT_Info() = default;
+  virtual ~RGWRESTMgr_SWIFT_Info() = default;
+  virtual RGWHandler_REST *get_handler(struct req_state *s) override;
+};
+
 #endif