MySQL 9.4.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
39
40class HttpRequest;
41
42namespace mysqlrouter {
43class MySQLSession;
44} // namespace mysqlrouter
45
46namespace mrs {
47
48namespace http {
49class Error;
50} // namespace http
51
52namespace rest {
53struct RequestContext;
54} // namespace rest
55
56namespace interface {
57
58class AuthorizeManager;
59
60using Parameters = std::map<std::string, std::string>;
61
62class ReqRes {
63 public:
64 bool header_{false};
65 bool body_{false};
66};
67
68class Request : public ReqRes {
69 public:
70};
71
72class Response : public ReqRes {
73 public:
74 bool detailed_errors_{false};
75};
76
77class Options {
78 public:
80
82
84 public:
86
88 std::vector<std::string> allowed_origins;
90
91 class Debug {
92 public:
93 Debug() {}
94
95 class Http {
96 public:
97 Http() {}
101 bool log_exceptions{false};
103
104 class Metadata {
105 public:
107
108 bool gtid{true};
110
111 class Query {
112 public:
113 uint64_t wait{1};
114 bool embed_wait{false};
115 uint64_t timeout{0};
116
117 // query db with MySQL Internal auth user
120
121 class MysqlTask {
122 public:
124
126
127 std::string name;
129 std::string event_schema;
131 std::vector<std::string> monitoring_sql;
133
134 class Result {
135 public:
136 bool include_links{true};
137 uint64_t cache_ttl_ms{0};
139};
140
141class RestHandler : public std::enable_shared_from_this<RestHandler> {
142 public:
147
149
151 public:
152 virtual ~Configuration() = default;
153
154 virtual bool may_log_request() const { return false; }
155 };
156
157 public:
158 virtual ~RestHandler() = default;
159
160 virtual void initialize(const Configuration &configuration) = 0;
161 virtual bool may_check_access() const = 0;
163
164 virtual const std::string &get_url_host() const = 0;
165 virtual const std::string &get_protocol() const = 0;
166 virtual const std::string &get_service_path() const = 0;
167 virtual const std::string &get_schema_path() const = 0;
168 virtual const std::string &get_db_object_path() const = 0;
169 virtual UniversalId get_service_id() const = 0;
170 virtual UniversalId get_db_object_id() const = 0;
171 virtual UniversalId get_schema_id() const = 0;
172 virtual uint32_t get_access_rights() const = 0;
173 virtual const Options &get_options() const = 0;
174
175 virtual void authorization(RequestContext *ctxt) = 0;
176 virtual bool request_begin(RequestContext *ctxt) = 0;
177 virtual void request_end(RequestContext *ctxt) = 0;
178 virtual bool request_error(RequestContext *ctxt, const http::Error &e) = 0;
181 const std::vector<uint8_t> &document) = 0;
184};
185
186} // namespace interface
187} // namespace mrs
188
189#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:83
std::vector< std::string > allowed_origins
Definition: rest_handler.h:88
AllowedOriginsType
Definition: rest_handler.h:85
@ AllowSpecified
Definition: rest_handler.h:85
@ AllowAll
Definition: rest_handler.h:85
@ AllowNone
Definition: rest_handler.h:85
AllowedOriginsType type
Definition: rest_handler.h:87
Definition: rest_handler.h:95
Request request
Definition: rest_handler.h:98
Http()
Definition: rest_handler.h:97
Response response
Definition: rest_handler.h:99
Definition: rest_handler.h:91
Debug()
Definition: rest_handler.h:93
class mrs::interface::Options::Debug::Http http
bool log_exceptions
Definition: rest_handler.h:101
Definition: rest_handler.h:104
bool gtid
Definition: rest_handler.h:108
Metadata()
Definition: rest_handler.h:106
Definition: rest_handler.h:121
DriverType driver
Definition: rest_handler.h:128
std::vector< std::string > monitoring_sql
Definition: rest_handler.h:131
std::string event_schema
Definition: rest_handler.h:129
mrs::database::entry::ColumnType ColumnType
Definition: rest_handler.h:123
DriverType
Definition: rest_handler.h:125
std::string name
Definition: rest_handler.h:127
std::string status_data_json_schema
Definition: rest_handler.h:130
Definition: rest_handler.h:111
uint64_t wait
Definition: rest_handler.h:113
bool embed_wait
Definition: rest_handler.h:114
uint64_t timeout
Definition: rest_handler.h:115
bool passthrough_db_user
Definition: rest_handler.h:118
Definition: rest_handler.h:134
bool include_links
Definition: rest_handler.h:136
uint64_t cache_ttl_ms
Definition: rest_handler.h:137
Definition: rest_handler.h:77
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:79
class mrs::interface::Options::Debug debug
Parameters parameters_
Definition: rest_handler.h:81
class mrs::interface::Options::AllowedOrigins allowed_origins
Definition: rest_handler.h:62
bool header_
Definition: rest_handler.h:64
bool body_
Definition: rest_handler.h:65
Definition: rest_handler.h:68
Definition: rest_handler.h:72
bool detailed_errors_
Definition: rest_handler.h:74
Definition: rest_handler.h:150
virtual bool may_log_request() const
Definition: rest_handler.h:154
Definition: rest_handler.h:141
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:148
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:145
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:56
ColumnType
Definition: column_type.h:48
::http::base::Request HttpRequest
Definition: utilities.h:37
std::map< std::string, std::string > Parameters
Definition: rest_handler.h:60
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