diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/rgw/rgw_loadgen.cc | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/rgw/rgw_loadgen.cc')
-rw-r--r-- | src/rgw/rgw_loadgen.cc | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/rgw/rgw_loadgen.cc b/src/rgw/rgw_loadgen.cc new file mode 100644 index 000000000..22c133864 --- /dev/null +++ b/src/rgw/rgw_loadgen.cc @@ -0,0 +1,129 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab ft=cpp + +#include <algorithm> +#include <sstream> +#include <string.h> + +#include "rgw_loadgen.h" +#include "rgw_auth_s3.h" + + +#define dout_subsys ceph_subsys_rgw + +void RGWLoadGenRequestEnv::set_date(utime_t& tm) +{ + date_str = rgw_to_asctime(tm); +} + +int RGWLoadGenRequestEnv::sign(const DoutPrefixProvider *dpp, RGWAccessKey& access_key) +{ + meta_map_t meta_map; + map<string, string> sub_resources; + + string canonical_header; + string digest; + + rgw_create_s3_canonical_header(dpp, + request_method.c_str(), + nullptr, /* const char *content_md5 */ + content_type.c_str(), + date_str.c_str(), + meta_map, + meta_map_t{}, + uri.c_str(), + sub_resources, + canonical_header); + + headers["HTTP_DATE"] = date_str; + try { + /* FIXME(rzarzynski): kill the dependency on g_ceph_context. */ + const auto signature = static_cast<std::string>( + rgw::auth::s3::get_v2_signature(g_ceph_context, canonical_header, + access_key.key)); + headers["HTTP_AUTHORIZATION"] = \ + std::string("AWS ") + access_key.id + ":" + signature; + } catch (int ret) { + return ret; + } + + return 0; +} + +size_t RGWLoadGenIO::write_data(const char* const buf, + const size_t len) +{ + return len; +} + +size_t RGWLoadGenIO::read_data(char* const buf, const size_t len) +{ + const size_t read_len = std::min(left_to_read, + static_cast<uint64_t>(len)); + left_to_read -= read_len; + return read_len; +} + +void RGWLoadGenIO::flush() +{ +} + +size_t RGWLoadGenIO::complete_request() +{ + return 0; +} + +int RGWLoadGenIO::init_env(CephContext *cct) +{ + env.init(cct); + + left_to_read = req->content_length; + + char buf[32]; + snprintf(buf, sizeof(buf), "%lld", (long long)req->content_length); + env.set("CONTENT_LENGTH", buf); + + env.set("CONTENT_TYPE", req->content_type.c_str()); + env.set("HTTP_DATE", req->date_str.c_str()); + + for (map<string, string>::iterator iter = req->headers.begin(); iter != req->headers.end(); ++iter) { + env.set(iter->first.c_str(), iter->second.c_str()); + } + + env.set("REQUEST_METHOD", req->request_method.c_str()); + env.set("REQUEST_URI", req->uri.c_str()); + env.set("QUERY_STRING", req->query_string.c_str()); + env.set("SCRIPT_URI", req->uri.c_str()); + + char port_buf[16]; + snprintf(port_buf, sizeof(port_buf), "%d", req->port); + env.set("SERVER_PORT", port_buf); + return 0; +} + +size_t RGWLoadGenIO::send_status(const int status, + const char* const status_name) +{ + return 0; +} + +size_t RGWLoadGenIO::send_100_continue() +{ + return 0; +} + +size_t RGWLoadGenIO::send_header(const std::string_view& name, + const std::string_view& value) +{ + return 0; +} + +size_t RGWLoadGenIO::complete_header() +{ + return 0; +} + +size_t RGWLoadGenIO::send_content_length(const uint64_t len) +{ + return 0; +} |