From bdda0d2ba1d0ef52b7a8b5edf1f2f70cacc38013 Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Tue, 29 Jun 2021 13:54:35 -0400 Subject: [PATCH] rgw: introduce new /{admin}/info api resource 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 --- doc/radosgw/adminops.rst | 48 ++++++++++++++++++++++++++++++++++++++++ src/rgw/CMakeLists.txt | 1 + src/rgw/rgw_common.cc | 1 + src/rgw/rgw_main.cc | 2 ++ src/rgw/rgw_rest_info.cc | 40 +++++++++++++++++++++++++++++++++ src/rgw/rgw_rest_info.h | 33 +++++++++++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 src/rgw/rgw_rest_info.cc create mode 100644 src/rgw/rgw_rest_info.h diff --git a/doc/radosgw/adminops.rst b/doc/radosgw/adminops.rst index 95af1e2d293..1752027e6e0 100644 --- a/doc/radosgw/adminops.rst +++ b/doc/radosgw/adminops.rst @@ -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 ========= diff --git a/src/rgw/CMakeLists.txt b/src/rgw/CMakeLists.txt index 0f1ddd9f5bc..f0889d7cdb6 100644 --- a/src/rgw/CMakeLists.txt +++ b/src/rgw/CMakeLists.txt @@ -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 diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 50e34f19549..ab8481a77df 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -2007,6 +2007,7 @@ bool RGWUserCaps::is_valid_cap_type(const string& tp) "users", "buckets", "metadata", + "info", "usage", "zone", "bilog", diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 159b3b316f0..5442d3d1175 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -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 index 00000000000..c69f46243b7 --- /dev/null +++ b/src/rgw/rgw_rest_info.cc @@ -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 index 00000000000..4beb65d8076 --- /dev/null +++ b/src/rgw/rgw_rest_info.h @@ -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); + } +}; -- 2.39.5