summaryrefslogtreecommitdiffstats
path: root/src/rgw/rgw_loadgen.cc
blob: e13520dd8c7ea005416f060a643ae29da6275193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#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(RGWAccessKey& access_key)
{
  meta_map_t meta_map;
  map<string, string> sub_resources;

  string canonical_header;
  string digest;

  rgw_create_s3_canonical_header(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 boost::string_ref& name,
                                 const boost::string_ref& value)
{
  return 0;
}

size_t RGWLoadGenIO::complete_header()
{
  return 0;
}

size_t RGWLoadGenIO::send_content_length(const uint64_t len)
{
  return 0;
}