MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
rest_handler.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2025, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_INCLUDE_MRS_INTERFACE_REST_HANDLER_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_INCLUDE_MRS_INTERFACE_REST_HANDLER_H_
28
29#include <map>
30#include <memory>
31#include <optional>
32#include <string>
33#include <utility>
34#include <vector>
35
38
39class HttpRequest;
40
41namespace mysqlrouter {
42class MySQLSession;
43} // namespace mysqlrouter
44
45namespace mrs {
46
47namespace http {
48class Error;
49} // namespace http
50
51namespace rest {
52struct RequestContext;
53} // namespace rest
54
55namespace interface {
56
57class AuthorizeManager;
58
59using Parameters = std::map<std::string, std::string>;
60
61class ReqRes {
62 public:
63 bool header_{false};
64 bool body_{false};
65};
66
67class Request : public ReqRes {
68 public:
69};
70
71class Response : public ReqRes {
72 public:
73 bool detailed_errors_{false};
74};
75
76class Options {
77 public:
79
81
83 public:
85
87 std::vector<std::string> allowed_origins;
89
90 class Debug {
91 public:
92 Debug() {}
93
94 class Http {
95 public:
96 Http() {}
100 bool log_exceptions{false};
102
103 class Metadata {
104 public:
106
107 bool gtid{true};
109
110 class Query {
111 public:
112 uint64_t wait{1};
113 bool embed_wait{false};
114 uint64_t timeout{0};
116
117 class MysqlTask {
118 public:
120
121 std::string name;
123 std::string event_schema;
125 std::vector<std::string> monitoring_sql;
127
128 class Result {
129 public:
130 bool include_links{true};
131 uint64_t cache_ttl_ms{0};
133};
134
135class RestHandler : public std::enable_shared_from_this<RestHandler> {
136 public:
141
143
145 public:
146 virtual ~Configuration() = default;
147
148 virtual bool may_log_request() const { return false; }
149 };
150
151 public:
152 virtual ~RestHandler() = default;
153
154 virtual void initialize(const Configuration &configuration) = 0;
155 virtual bool may_check_access() const = 0;
157
158 virtual const std::string &get_url_host() const = 0;
159 virtual const std::string &get_protocol() const = 0;
160 virtual const std::string &get_service_path() const = 0;
161 virtual const std::string &get_schema_path() const = 0;
162 virtual const std::string &get_db_object_path() const = 0;
163 virtual UniversalId get_service_id() const = 0;
164 virtual UniversalId get_db_object_id() const = 0;
165 virtual UniversalId get_schema_id() const = 0;
166 virtual uint32_t get_access_rights() const = 0;
167 virtual const Options &get_options() const = 0;
168
169 virtual void authorization(RequestContext *ctxt) = 0;
170 virtual bool request_begin(RequestContext *ctxt) = 0;
171 virtual void request_end(RequestContext *ctxt) = 0;
172 virtual bool request_error(RequestContext *ctxt, const http::Error &e) = 0;
175 const std::vector<uint8_t> &document) = 0;
178};
179
180} // namespace interface
181} // namespace mrs
182
183#endif // ROUTER_SRC_MYSQL_REST_SERVICE_INCLUDE_MRS_INTERFACE_REST_HANDLER_H_
mysqlrouter::MySQLSession MySQLSession
Definition: bootstrap_mysql_account.cc:41
Class representing an error.
Definition: error.h:48
Definition: error.h:37
Definition: rest_handler.h:82
std::vector< std::string > allowed_origins
Definition: rest_handler.h:87
AllowedOriginsType
Definition: rest_handler.h:84
@ AllowSpecified
Definition: rest_handler.h:84
@ AllowAll
Definition: rest_handler.h:84
@ AllowNone
Definition: rest_handler.h:84
AllowedOriginsType type
Definition: rest_handler.h:86
Definition: rest_handler.h:94
Request request
Definition: rest_handler.h:97
Http()
Definition: rest_handler.h:96
Response response
Definition: rest_handler.h:98
Definition: rest_handler.h:90
Debug()
Definition: rest_handler.h:92
class mrs::interface::Options::Debug::Http http
bool log_exceptions
Definition: rest_handler.h:100
Definition: rest_handler.h:103
bool gtid
Definition: rest_handler.h:107
Metadata()
Definition: rest_handler.h:105
Definition: rest_handler.h:117
DriverType driver
Definition: rest_handler.h:122
std::vector< std::string > monitoring_sql
Definition: rest_handler.h:125
std::string event_schema
Definition: rest_handler.h:123
DriverType
Definition: rest_handler.h:119
std::string name
Definition: rest_handler.h:121
std::string status_data_json_schema
Definition: rest_handler.h:124
Definition: rest_handler.h:110
uint64_t wait
Definition: rest_handler.h:112
bool embed_wait
Definition: rest_handler.h:113
uint64_t timeout
Definition: rest_handler.h:114
Definition: rest_handler.h:128
bool include_links
Definition: rest_handler.h:130
uint64_t cache_ttl_ms
Definition: rest_handler.h:131
Definition: rest_handler.h:76
class mrs::interface::Options::Metadata metadata
class mrs::interface::Options::Query query
class mrs::interface::Options::MysqlTask mysql_task
class mrs::interface::Options::Result result
Options()
Definition: rest_handler.h:78
class mrs::interface::Options::Debug debug
Parameters parameters_
Definition: rest_handler.h:80
class mrs::interface::Options::AllowedOrigins allowed_origins
Definition: rest_handler.h:61
bool header_
Definition: rest_handler.h:63
bool body_
Definition: rest_handler.h:64
Definition: rest_handler.h:67
Definition: rest_handler.h:71
bool detailed_errors_
Definition: rest_handler.h:73
Definition: rest_handler.h:144
virtual bool may_log_request() const
Definition: rest_handler.h:148
Definition: rest_handler.h:135
virtual const std::string & get_protocol() const =0
virtual const std::string & get_url_host() const =0
virtual HttpResult handle_post(RequestContext *ctxt, const std::vector< uint8_t > &document)=0
virtual Authorization requires_authentication() const =0
virtual bool request_begin(RequestContext *ctxt)=0
virtual void request_end(RequestContext *ctxt)=0
virtual HttpResult handle_get(RequestContext *ctxt)=0
virtual UniversalId get_schema_id() const =0
virtual uint32_t get_access_rights() const =0
virtual const Options & get_options() const =0
virtual HttpResult handle_put(RequestContext *ctxt)=0
virtual void authorization(RequestContext *ctxt)=0
virtual HttpResult handle_delete(RequestContext *ctxt)=0
virtual bool may_check_access() const =0
virtual void initialize(const Configuration &configuration)=0
virtual const std::string & get_service_path() const =0
Authorization
Definition: rest_handler.h:142
virtual const std::string & get_db_object_path() const =0
virtual ~RestHandler()=default
virtual UniversalId get_db_object_id() const =0
mrs::interface::Parameters Parameters
Definition: rest_handler.h:139
virtual bool request_error(RequestContext *ctxt, const http::Error &e)=0
virtual UniversalId get_service_id() const =0
virtual const std::string & get_schema_path() const =0
Definition: mysql_session.h:157
mrs::rest::Handler::HttpResult HttpResult
Definition: handler_content_file.cc:43
Definition: connection.h:55
::http::base::Request HttpRequest
Definition: utilities.h:37
std::map< std::string, std::string > Parameters
Definition: rest_handler.h:59
Definition: authorize_manager.h:48
mrs::database::entry::UniversalId UniversalId
Definition: universal_id.h:33
Definition: base64.h:43
required string configuration
Definition: replication_asynchronous_connection_failover.proto:49
Definition: http_result.h:37
Definition: request_context.h:47