]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: introduce new /{admin}/info api resource
authorMatt Benjamin <mbenjamin@redhat.com>
Tue, 29 Jun 2021 17:54:35 +0000 (13:54 -0400)
committerMatt Benjamin <mbenjamin@redhat.com>
Thu, 9 Dec 2021 15:47:43 +0000 (10:47 -0500)
The new resource returns an array of informational data, which
currently consists of the RADOS cluster fsid as "cluster_fsid."

Fixes: https://tracker.ceph.com/issues/51432
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
doc/radosgw/adminops.rst
src/rgw/CMakeLists.txt
src/rgw/rgw_common.cc
src/rgw/rgw_main.cc
src/rgw/rgw_rest_info.cc [new file with mode: 0644]
src/rgw/rgw_rest_info.h [new file with mode: 0644]

index 95af1e2d2934474e95c6f629fbc4941566404f69..1752027e6e00a1aec17ebe391d493cc953176501 100644 (file)
@@ -10,6 +10,54 @@ mechanism. Some operations require that the user holds special administrative ca
 The response entity type (XML or JSON) may be specified as the 'format' option in the
 request and defaults to JSON if not specified.
 
+Info
+====
+
+Get RGW cluster/endpoint information.
+
+:caps: info=read
+
+
+Syntax
+~~~~~~
+
+::
+
+       GET /{admin}/info?format=json HTTP/1.1
+       Host: {fqdn}
+
+
+Request Parameters
+~~~~~~~~~~~~~~~~~~
+
+None.
+
+
+Response Entities
+~~~~~~~~~~~~~~~~~
+
+If successful, the response contains an ``info`` section.
+
+``info``
+
+:Description: A container for all returned information.
+:Type: Container
+
+``cluster_id``
+
+:Description: The (typically unique) identifier for the controlling
+             backing store for the RGW cluster.  In the typical case,
+             this is value returned from librados::rados::cluster_fsid().
+:Type: String
+:Parent: ``info``
+
+
+Special Error Responses
+~~~~~~~~~~~~~~~~~~~~~~~
+
+None.
+
+
 Get Usage
 =========
 
index 0f1ddd9f5bceec7b46a0cabddfe54df1eb6f47da..f0889d7cdb6e917eff4913278ddfe9889a1f764a 100644 (file)
@@ -270,6 +270,7 @@ set(rgw_a_srcs
   rgw_rest_realm.cc
   rgw_rest_swift.cc
   rgw_rest_usage.cc
+  rgw_rest_info.cc
   rgw_rest_user.cc
   rgw_swift_auth.cc
   rgw_usage.cc
index 50e34f1954936b41bc1ff89c8acbe5402b12381b..ab8481a77dfe85f0f1247d1dc6faf5a088745ae3 100644 (file)
@@ -2007,6 +2007,7 @@ bool RGWUserCaps::is_valid_cap_type(const string& tp)
                                     "users",
                                     "buckets",
                                     "metadata",
+                                    "info",
                                     "usage",
                                     "zone",
                                     "bilog",
index 159b3b316f025d9603684b5fb4f04725e9bc7da9..5442d3d117543540d6e6a3eef759c393067a4152 100644 (file)
@@ -23,6 +23,7 @@
 #include "rgw_rest_s3.h"
 #include "rgw_rest_swift.h"
 #include "rgw_rest_admin.h"
+#include "rgw_rest_info.h"
 #include "rgw_rest_usage.h"
 #include "rgw_rest_user.h"
 #include "rgw_rest_bucket.h"
@@ -499,6 +500,7 @@ int radosgw_Main(int argc, const char **argv)
 
   if (apis_map.count("admin") > 0) {
     RGWRESTMgr_Admin *admin_resource = new RGWRESTMgr_Admin;
+    admin_resource->register_resource("info", new RGWRESTMgr_Info);
     admin_resource->register_resource("usage", new RGWRESTMgr_Usage);
     admin_resource->register_resource("user", new RGWRESTMgr_User);
     /* XXX dang part of this is RADOS specific */
diff --git a/src/rgw/rgw_rest_info.cc b/src/rgw/rgw_rest_info.cc
new file mode 100644 (file)
index 0000000..c69f462
--- /dev/null
@@ -0,0 +1,40 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab ft=cpp
+
+#include "rgw_op.h"
+#include "rgw_rest_info.h"
+#include "rgw_sal.h"
+
+#define dout_subsys ceph_subsys_rgw
+
+class RGWOp_Info_Get : public RGWRESTOp {
+
+public:
+  RGWOp_Info_Get() {}
+
+  int check_caps(const RGWUserCaps& caps) override {
+    return caps.check_cap("info", RGW_CAP_READ);
+  }
+  void execute(optional_yield y) override;
+
+  const char* name() const override { return "get_info"; }
+};
+
+void RGWOp_Info_Get::execute(optional_yield y) {
+  Formatter *formatter = flusher.get_formatter();
+  flusher.start(0);
+
+  // extensible array of general info sections
+  formatter->open_object_section("dummy");
+  formatter->open_object_section("info");
+  formatter->dump_string("cluster_id", store->get_cluster_id(this, y));
+  formatter->close_section();
+  formatter->close_section();
+
+  flusher.flush();
+} /* RGWOp_Info_Get::execute */
+
+RGWOp *RGWHandler_Info::op_get()
+{
+  return new RGWOp_Info_Get;
+}
diff --git a/src/rgw/rgw_rest_info.h b/src/rgw/rgw_rest_info.h
new file mode 100644 (file)
index 0000000..4beb65d
--- /dev/null
@@ -0,0 +1,33 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab ft=cpp
+
+#pragma once
+
+#include "rgw_rest.h"
+#include "rgw_rest_s3.h"
+
+
+class RGWHandler_Info : public RGWHandler_Auth_S3 {
+protected:
+  RGWOp *op_get() override;
+public:
+  using RGWHandler_Auth_S3::RGWHandler_Auth_S3;
+  ~RGWHandler_Info() override = default;
+
+  int read_permissions(RGWOp*, optional_yield) override {
+    return 0;
+  }
+};
+
+class RGWRESTMgr_Info : public RGWRESTMgr {
+public:
+  RGWRESTMgr_Info() = default;
+  ~RGWRESTMgr_Info() override = default;
+
+  RGWHandler_REST* get_handler(rgw::sal::Store* store,
+                              struct req_state*,
+                               const rgw::auth::StrategyRegistry& auth_registry,
+                               const std::string&) override {
+    return new RGWHandler_Info(auth_registry);
+  }
+};