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