]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_loadgen.cc
update sources to v12.2.4
[ceph.git] / ceph / src / rgw / rgw_loadgen.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include <algorithm>
5#include <sstream>
6#include <string.h>
7
8#include "rgw_loadgen.h"
9#include "rgw_auth_s3.h"
10
11
12#define dout_subsys ceph_subsys_rgw
13
14void RGWLoadGenRequestEnv::set_date(utime_t& tm)
15{
c07f9fc5 16 date_str = rgw_to_asctime(tm);
7c673cae
FG
17}
18
19int RGWLoadGenRequestEnv::sign(RGWAccessKey& access_key)
20{
21 map<string, string> meta_map;
22 map<string, string> sub_resources;
23
24 string canonical_header;
25 string digest;
26
27 rgw_create_s3_canonical_header(request_method.c_str(),
28 nullptr, /* const char *content_md5 */
29 content_type.c_str(),
30 date_str.c_str(),
31 meta_map,
32 uri.c_str(),
33 sub_resources,
34 canonical_header);
35
31f18b77
FG
36 headers["HTTP_DATE"] = date_str;
37 try {
38 /* FIXME(rzarzynski): kill the dependency on g_ceph_context. */
39 const auto signature = static_cast<std::string>(
40 rgw::auth::s3::get_v2_signature(g_ceph_context, canonical_header,
41 access_key.key));
42 headers["HTTP_AUTHORIZATION"] = \
43 std::string("AWS ") + access_key.id + ":" + signature;
44 } catch (int ret) {
7c673cae
FG
45 return ret;
46 }
47
7c673cae
FG
48 return 0;
49}
50
51size_t RGWLoadGenIO::write_data(const char* const buf,
52 const size_t len)
53{
54 return len;
55}
56
57size_t RGWLoadGenIO::read_data(char* const buf, const size_t len)
58{
59 const size_t read_len = std::min(left_to_read,
60 static_cast<uint64_t>(len));
61 left_to_read -= read_len;
62 return read_len;
63}
64
65void RGWLoadGenIO::flush()
66{
67}
68
69size_t RGWLoadGenIO::complete_request()
70{
71 return 0;
72}
73
3a9019d9 74int RGWLoadGenIO::init_env(CephContext *cct)
7c673cae
FG
75{
76 env.init(cct);
77
78 left_to_read = req->content_length;
79
80 char buf[32];
81 snprintf(buf, sizeof(buf), "%lld", (long long)req->content_length);
82 env.set("CONTENT_LENGTH", buf);
83
84 env.set("CONTENT_TYPE", req->content_type.c_str());
85 env.set("HTTP_DATE", req->date_str.c_str());
86
87 for (map<string, string>::iterator iter = req->headers.begin(); iter != req->headers.end(); ++iter) {
88 env.set(iter->first.c_str(), iter->second.c_str());
89 }
90
91 env.set("REQUEST_METHOD", req->request_method.c_str());
92 env.set("REQUEST_URI", req->uri.c_str());
93 env.set("QUERY_STRING", req->query_string.c_str());
94 env.set("SCRIPT_URI", req->uri.c_str());
95
96 char port_buf[16];
97 snprintf(port_buf, sizeof(port_buf), "%d", req->port);
98 env.set("SERVER_PORT", port_buf);
3a9019d9 99 return 0;
7c673cae
FG
100}
101
102size_t RGWLoadGenIO::send_status(const int status,
103 const char* const status_name)
104{
105 return 0;
106}
107
108size_t RGWLoadGenIO::send_100_continue()
109{
110 return 0;
111}
112
113size_t RGWLoadGenIO::send_header(const boost::string_ref& name,
114 const boost::string_ref& value)
115{
116 return 0;
117}
118
119size_t RGWLoadGenIO::complete_header()
120{
121 return 0;
122}
123
124size_t RGWLoadGenIO::send_content_length(const uint64_t len)
125{
126 return 0;
127}