]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_rest_client.h
import ceph quincy 17.2.6
[ceph.git] / ceph / src / rgw / rgw_rest_client.h
CommitLineData
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 3
9f95a23c 4#pragma once
7c673cae
FG
5
6#include "rgw_http_client.h"
7
8class RGWGetDataCB;
9
11fdf7f2 10class RGWHTTPSimpleRequest : public RGWHTTPClient {
7c673cae
FG
11protected:
12 int http_status;
13 int status;
14
11fdf7f2 15 using unique_lock = std::unique_lock<std::mutex>;
7c673cae 16
11fdf7f2 17 std::mutex out_headers_lock;
20effc67 18 std::map<std::string, std::string> out_headers;
7c673cae
FG
19 param_vec_t params;
20
21 bufferlist::iterator *send_iter;
22
23 size_t max_response; /* we need this as we don't stream out response */
24 bufferlist response;
25
20effc67
TL
26 virtual int handle_header(const std::string& name, const std::string& val);
27 void get_params_str(std::map<std::string, std::string>& extra_args, std::string& dest);
7c673cae 28
7c673cae 29public:
20effc67 30 RGWHTTPSimpleRequest(CephContext *_cct, const std::string& _method, const std::string& _url,
11fdf7f2
TL
31 param_vec_t *_headers, param_vec_t *_params) : RGWHTTPClient(_cct, _method, _url),
32 http_status(0), status(0),
33 send_iter(NULL),
7c673cae
FG
34 max_response(0) {
35 set_headers(_headers);
36 set_params(_params);
37 }
38
39 void set_headers(param_vec_t *_headers) {
40 if (_headers)
41 headers = *_headers;
42 }
43
44 void set_params(param_vec_t *_params) {
45 if (_params)
46 params = *_params;
47 }
48
49 int receive_header(void *ptr, size_t len) override;
11fdf7f2
TL
50 int receive_data(void *ptr, size_t len, bool *pause) override;
51 int send_data(void *ptr, size_t len, bool* pause=nullptr) override;
7c673cae
FG
52
53 bufferlist& get_response() { return response; }
54
20effc67 55 void get_out_headers(std::map<std::string, std::string> *pheaders); /* modifies out_headers */
7c673cae
FG
56
57 int get_http_status() { return http_status; }
58 int get_status();
59};
60
11fdf7f2 61class RGWRESTSimpleRequest : public RGWHTTPSimpleRequest {
20effc67 62 std::optional<std::string> api_name;
11fdf7f2 63public:
20effc67
TL
64 RGWRESTSimpleRequest(CephContext *_cct, const std::string& _method, const std::string& _url,
65 param_vec_t *_headers, param_vec_t *_params,
66 std::optional<std::string> _api_name) : RGWHTTPSimpleRequest(_cct, _method, _url, _headers, _params), api_name(_api_name) {}
11fdf7f2 67
39ae355f 68 int forward_request(const DoutPrefixProvider *dpp, const RGWAccessKey& key, req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y, std::string service="");
11fdf7f2 69};
7c673cae 70
11fdf7f2 71class RGWWriteDrainCB {
7c673cae 72public:
11fdf7f2
TL
73 RGWWriteDrainCB() = default;
74 virtual ~RGWWriteDrainCB() = default;
75 virtual void notify(uint64_t pending_size) = 0;
76};
7c673cae 77
20effc67 78class RGWRESTGenerateHTTPHeaders : public DoutPrefix {
11fdf7f2
TL
79 CephContext *cct;
80 RGWEnv *new_env;
81 req_info *new_info;
20effc67
TL
82 std::string region;
83 std::string service;
84 std::string method;
85 std::string url;
86 std::string resource;
7c673cae 87
11fdf7f2 88public:
20effc67
TL
89 RGWRESTGenerateHTTPHeaders(CephContext *_cct, RGWEnv *_env, req_info *_info);
90 void init(const std::string& method, const std::string& host,
91 const std::string& resource_prefix, const std::string& url,
92 const std::string& resource, const param_vec_t& params,
93 std::optional<std::string> api_name);
94 void set_extra_headers(const std::map<std::string, std::string>& extra_headers);
95 int set_obj_attrs(const DoutPrefixProvider *dpp, std::map<std::string, bufferlist>& rgw_attrs);
96 void set_http_attrs(const std::map<std::string, std::string>& http_attrs);
11fdf7f2 97 void set_policy(RGWAccessControlPolicy& policy);
20effc67 98 int sign(const DoutPrefixProvider *dpp, RGWAccessKey& key, const bufferlist *opt_content);
11fdf7f2 99
20effc67 100 const std::string& get_url() { return url; }
7c673cae
FG
101};
102
11fdf7f2
TL
103class RGWHTTPStreamRWRequest : public RGWHTTPSimpleRequest {
104public:
105 class ReceiveCB;
106
107private:
9f95a23c
TL
108 ceph::mutex lock =
109 ceph::make_mutex("RGWHTTPStreamRWRequest");
110 ceph::mutex write_lock =
111 ceph::make_mutex("RGWHTTPStreamRWRequest::write_lock");
11fdf7f2
TL
112 ReceiveCB *cb{nullptr};
113 RGWWriteDrainCB *write_drain_cb{nullptr};
7c673cae 114 bufferlist in_data;
11fdf7f2
TL
115 size_t chunk_ofs{0};
116 size_t ofs{0};
117 uint64_t write_ofs{0};
118 bool read_paused{false};
119 bool send_paused{false};
120 bool stream_writes{false};
121 bool write_stream_complete{false};
7c673cae 122protected:
20effc67
TL
123 bufferlist outbl;
124
125 int handle_header(const std::string& name, const std::string& val) override;
7c673cae 126public:
11fdf7f2
TL
127 int send_data(void *ptr, size_t len, bool *pause) override;
128 int receive_data(void *ptr, size_t len, bool *pause) override;
129
130 class ReceiveCB {
131 protected:
132 uint64_t extra_data_len{0};
133 public:
134 ReceiveCB() = default;
135 virtual ~ReceiveCB() = default;
136 virtual int handle_data(bufferlist& bl, bool *pause = nullptr) = 0;
137 virtual void set_extra_data_len(uint64_t len) {
138 extra_data_len = len;
139 }
140 };
141
20effc67 142 RGWHTTPStreamRWRequest(CephContext *_cct, const std::string& _method, const std::string& _url,
9f95a23c 143 param_vec_t *_headers, param_vec_t *_params) : RGWHTTPSimpleRequest(_cct, _method, _url, _headers, _params) {
7c673cae 144 }
20effc67 145 RGWHTTPStreamRWRequest(CephContext *_cct, const std::string& _method, const std::string& _url, ReceiveCB *_cb,
11fdf7f2 146 param_vec_t *_headers, param_vec_t *_params) : RGWHTTPSimpleRequest(_cct, _method, _url, _headers, _params),
9f95a23c 147 cb(_cb) {
11fdf7f2
TL
148 }
149 virtual ~RGWHTTPStreamRWRequest() override {}
7c673cae
FG
150
151 void set_outbl(bufferlist& _outbl) {
152 outbl.swap(_outbl);
153 }
154
11fdf7f2
TL
155 void set_in_cb(ReceiveCB *_cb) { cb = _cb; }
156 void set_write_drain_cb(RGWWriteDrainCB *_cb) { write_drain_cb = _cb; }
157
158 void unpause_receive();
159
160 void add_send_data(bufferlist& bl);
161
162 void set_stream_write(bool s);
163
164 uint64_t get_pending_send_size();
165
166 /* finish streaming writes */
167 void finish_write();
20effc67
TL
168
169 int complete_request(optional_yield y,
170 std::string *etag = nullptr,
171 real_time *mtime = nullptr,
172 uint64_t *psize = nullptr,
173 std::map<std::string, std::string> *pattrs = nullptr,
174 std::map<std::string, std::string> *pheaders = nullptr);
11fdf7f2
TL
175};
176
177class RGWRESTStreamRWRequest : public RGWHTTPStreamRWRequest {
20effc67
TL
178 std::optional<RGWAccessKey> sign_key;
179 std::optional<RGWRESTGenerateHTTPHeaders> headers_gen;
180 RGWEnv new_env;
181 req_info new_info;
182
11fdf7f2 183protected:
20effc67 184 std::optional<std::string> api_name;
11fdf7f2
TL
185 HostStyle host_style;
186public:
20effc67
TL
187 RGWRESTStreamRWRequest(CephContext *_cct, const std::string& _method, const std::string& _url, RGWHTTPStreamRWRequest::ReceiveCB *_cb,
188 param_vec_t *_headers, param_vec_t *_params,
189 std::optional<std::string> _api_name, HostStyle _host_style = PathStyle) :
190 RGWHTTPStreamRWRequest(_cct, _method, _url, _cb, _headers, _params),
191 new_info(_cct, &new_env),
192 api_name(_api_name), host_style(_host_style) {
11fdf7f2
TL
193 }
194 virtual ~RGWRESTStreamRWRequest() override {}
195
20effc67
TL
196 int send_prepare(const DoutPrefixProvider *dpp, RGWAccessKey *key, std::map<std::string, std::string>& extra_headers, const std::string& resource, bufferlist *send_data = nullptr /* optional input data */);
197 int send_prepare(const DoutPrefixProvider *dpp, RGWAccessKey& key, std::map<std::string, std::string>& extra_headers, const rgw_obj& obj);
11fdf7f2
TL
198 int send(RGWHTTPManager *mgr);
199
20effc67
TL
200 int send_request(const DoutPrefixProvider *dpp, RGWAccessKey& key, std::map<std::string, std::string>& extra_headers, const rgw_obj& obj, RGWHTTPManager *mgr);
201 int send_request(const DoutPrefixProvider *dpp, RGWAccessKey *key, std::map<std::string, std::string>& extra_headers, const std::string& resource, RGWHTTPManager *mgr, bufferlist *send_data = nullptr /* optional input data */);
11fdf7f2
TL
202
203 void add_params(param_vec_t *params);
204
205private:
20effc67 206 int do_send_prepare(const DoutPrefixProvider *dpp, RGWAccessKey *key, std::map<std::string, std::string>& extra_headers, const std::string& resource, bufferlist *send_data = nullptr /* optional input data */);
7c673cae
FG
207};
208
209class RGWRESTStreamReadRequest : public RGWRESTStreamRWRequest {
210public:
20effc67
TL
211 RGWRESTStreamReadRequest(CephContext *_cct, const std::string& _url, ReceiveCB *_cb, param_vec_t *_headers,
212 param_vec_t *_params, std::optional<std::string> _api_name,
213 HostStyle _host_style = PathStyle) : RGWRESTStreamRWRequest(_cct, "GET", _url, _cb, _headers, _params, _api_name, _host_style) {}
7c673cae
FG
214};
215
216class RGWRESTStreamHeadRequest : public RGWRESTStreamRWRequest {
217public:
20effc67
TL
218 RGWRESTStreamHeadRequest(CephContext *_cct, const std::string& _url, ReceiveCB *_cb, param_vec_t *_headers,
219 param_vec_t *_params, std::optional<std::string> _api_name) : RGWRESTStreamRWRequest(_cct, "HEAD", _url, _cb, _headers, _params, _api_name) {}
7c673cae
FG
220};
221
20effc67
TL
222class RGWRESTStreamSendRequest : public RGWRESTStreamRWRequest {
223public:
224 RGWRESTStreamSendRequest(CephContext *_cct, const std::string& method,
225 const std::string& _url,
226 ReceiveCB *_cb, param_vec_t *_headers, param_vec_t *_params,
227 std::optional<std::string> _api_name,
228 HostStyle _host_style = PathStyle) : RGWRESTStreamRWRequest(_cct, method, _url, _cb, _headers, _params, _api_name, _host_style) {}
229};
230
231class RGWRESTStreamS3PutObj : public RGWHTTPStreamRWRequest {
232 std::optional<std::string> api_name;
233 HostStyle host_style;
11fdf7f2
TL
234 RGWGetDataCB *out_cb;
235 RGWEnv new_env;
236 req_info new_info;
237 RGWRESTGenerateHTTPHeaders headers_gen;
238public:
20effc67
TL
239 RGWRESTStreamS3PutObj(CephContext *_cct, const std::string& _method, const std::string& _url, param_vec_t *_headers,
240 param_vec_t *_params, std::optional<std::string> _api_name,
241 HostStyle _host_style) : RGWHTTPStreamRWRequest(_cct, _method, _url, nullptr, _headers, _params),
242 api_name(_api_name), host_style(_host_style),
11fdf7f2
TL
243 out_cb(NULL), new_info(cct, &new_env), headers_gen(_cct, &new_env, &new_info) {}
244 ~RGWRESTStreamS3PutObj() override;
245
20effc67
TL
246 void send_init(rgw::sal::Object* obj);
247 void send_ready(const DoutPrefixProvider *dpp, RGWAccessKey& key, std::map<std::string, bufferlist>& rgw_attrs);
248 void send_ready(const DoutPrefixProvider *dpp, RGWAccessKey& key, const std::map<std::string, std::string>& http_attrs,
249 RGWAccessControlPolicy& policy);
250 void send_ready(const DoutPrefixProvider *dpp, RGWAccessKey& key);
11fdf7f2 251
20effc67 252 void put_obj_init(const DoutPrefixProvider *dpp, RGWAccessKey& key, rgw::sal::Object* obj, std::map<std::string, bufferlist>& attrs);
11fdf7f2
TL
253
254 RGWGetDataCB *get_out_cb() { return out_cb; }
255};