MySQL 9.3.0
Source Code Documentation
bootstrap_configurator.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 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_BOOTSTRAP_SRC_BOOTSTRAP_CONFIGURATOR_H_
27#define ROUTER_SRC_BOOTSTRAP_SRC_BOOTSTRAP_CONFIGURATOR_H_
28
29#include <memory>
30#include <set>
31#include <string>
32#include <utility>
33#include <vector>
34
36#include "keyring_handler.h"
38#include "mysql/harness/vt100.h"
39#include "mysqlrouter/uri.h"
42
43using String = std::string;
44using Strings = std::vector<std::string>;
45using UniqueStrings = std::set<std::string>;
46
48 public:
49 BootstrapConfigurator(std::ostream &out_stream, std::ostream &err_stream);
50
51 void init(int argc, char **argv);
52 void run();
53
55 bool raw_mode = false);
56
57 private:
59 public:
61 std::ostream &out_stream, std::ostream &err_stream,
62 std::vector<std::string> &configs_)
63 : MySQLRouterConf(keyring_info, out_stream, err_stream),
65 config_files_{configs_} {}
66
68 CmdArgHandler &arg_handler,
69 const std::string &bootstrap_uri = "") noexcept override {
70 MySQLRouterConf::prepare_command_options(arg_handler, bootstrap_uri);
71 using OptionNames = CmdOption::OptionNames;
72
73#ifndef _WIN32
74 arg_handler.add_option(
75 OptionNames({"-u", "--user"}),
76 "Run the mysqlrouter as the user having the name user_name.",
78 [this](const std::string &username) {
79 this->bootstrap_options_["_username"] = username;
80 },
81 [this](const std::string &) {
82 if (this->bootstrap_uri_.empty()) {
83 this->bootstrap_options_["user_cmd_line"] =
84 this->bootstrap_options_["_username"];
85 } else {
86 check_user(this->bootstrap_options_["_username"], true,
88 this->bootstrap_options_["user"] =
89 this->bootstrap_options_["_username"];
90 // Remove temporary meta-options.
91 this->bootstrap_options_.erase("_username");
92 }
93 });
94#endif
95
96 arg_handler.add_option(
97 OptionNames({"-c", "--config"}),
98 "Only read configuration from given file.",
100 [this](const std::string &value) {
101 if (!config_files_.empty()) {
102 throw std::runtime_error(
103 "Option -c/--config can only be used once; "
104 "use -a/--extra-config instead.");
105 }
106
108 });
109 }
110 bool is_legacy() const override { return is_legacy_; }
111
112 private:
113 void check_and_add_conf(std::vector<std::string> &configs,
114 const std::string &value);
116 std::vector<std::string> &config_files_;
117 };
118
122
125
128 std::string mrs_secret_;
131 bool bootstrap_mrs_{false};
132 bool is_legacy_{true};
133 bool showing_info_{false};
134 std::vector<std::string> config_files_;
135
137 std::string key;
139 };
140 std::pair<RoutingConfig, RoutingConfig> get_config_classic_sections() const;
141
143
144 void parse_command_options(std::vector<std::string> arguments);
145 void prepare_command_options(const std::string &bootstrap_uri);
146
147 std::string get_version_line() noexcept;
148 void show_help();
149 void show_usage() noexcept;
150
151 void configure_mrs(
152 mysqlrouter::MySQLSession *session, const std::string &config_path,
153 const std::map<std::string, std::string> &config_cmdln_options);
154
155 void check_mrs_metadata(mysqlrouter::MySQLSession *session) const;
156
157 void load_configuration(const std::string &path);
158
159 bool can_configure_mrs(const std::string &config_path) const;
160
162 uint64_t mrs_router_id);
165 const std::string &config_path, uint64_t mrs_router_id,
166 const std::map<std::string, std::string> &config_cmdln_options);
168
169 std::string get_configured_rest_endpoint() const;
170
172 uint64_t mrs_router_id,
173 const std::string &developer_name);
175 uint64_t mrs_router_id,
176 const std::string &key,
177 const std::string &user,
178 const std::vector<std::string> &hosts);
179};
180
181#endif // ROUTER_SRC_BOOTSTRAP_SRC_BOOTSTRAP_CONFIGURATOR_H_
std::vector< std::string > Strings
Definition: bootstrap_configurator.h:44
std::set< std::string > UniqueStrings
Definition: bootstrap_configurator.h:45
Definition: bootstrap_configurator.h:58
bool is_legacy() const override
Definition: bootstrap_configurator.h:110
std::vector< std::string > & config_files_
Definition: bootstrap_configurator.h:116
void prepare_command_options(CmdArgHandler &arg_handler, const std::string &bootstrap_uri="") noexcept override
Definition: bootstrap_configurator.h:67
bool & is_legacy_
Definition: bootstrap_configurator.h:115
void check_and_add_conf(std::vector< std::string > &configs, const std::string &value)
Definition: bootstrap_configurator.cc:158
MySQLRouterAndMrsConf(bool &is_legacy, KeyringInfo &keyring_info, std::ostream &out_stream, std::ostream &err_stream, std::vector< std::string > &configs_)
Definition: bootstrap_configurator.h:60
Definition: bootstrap_configurator.h:47
bool bootstrap_mrs_
Definition: bootstrap_configurator.h:131
void store_mrs_account_metadata(mysqlrouter::MySQLSession *session, uint64_t mrs_router_id, const std::string &key, const std::string &user, const std::vector< std::string > &hosts)
Definition: bootstrap_configurator.cc:891
void prepare_command_options(const std::string &bootstrap_uri)
Definition: bootstrap_configurator.cc:367
void init(int argc, char **argv)
Definition: bootstrap_configurator.cc:239
void check_mrs_metadata(mysqlrouter::MySQLSession *session) const
Definition: bootstrap_configurator.cc:692
bool is_legacy_
Definition: bootstrap_configurator.h:132
std::string bootstrap_mrs_developer_debug_port_
Definition: bootstrap_configurator.h:130
std::string mrs_secret_
Definition: bootstrap_configurator.h:128
uint64_t register_mrs_router_instance(mysqlrouter::MySQLSession *session)
Definition: bootstrap_configurator.cc:841
CmdArgHandler arg_handler_
Definition: bootstrap_configurator.h:121
void parse_command_options(std::vector< std::string > arguments)
Definition: bootstrap_configurator.cc:346
std::string get_version_line() noexcept
Definition: bootstrap_configurator.cc:455
void store_mrs_developer(mysqlrouter::MySQLSession *session, uint64_t mrs_router_id, const std::string &developer_name)
Definition: bootstrap_configurator.cc:912
KeyringHandler keyring_
Definition: bootstrap_configurator.h:123
void create_mrs_users(mysqlrouter::MySQLSession *session, uint64_t mrs_router_id)
Definition: bootstrap_configurator.cc:591
bool can_configure_mrs(const std::string &config_path) const
Definition: bootstrap_configurator.cc:719
bool showing_info_
Definition: bootstrap_configurator.h:133
BootstrapCredentials mrs_data_account_
Definition: bootstrap_configurator.h:127
mysql_harness::Config config_
Definition: bootstrap_configurator.h:142
std::pair< RoutingConfig, RoutingConfig > get_config_classic_sections() const
Definition: bootstrap_configurator.cc:809
void store_mrs_configuration(const std::string &config_path, uint64_t mrs_router_id, const std::map< std::string, std::string > &config_cmdln_options)
Definition: bootstrap_configurator.cc:750
std::vector< std::string > config_files_
Definition: bootstrap_configurator.h:134
std::string router_program_name_
Definition: bootstrap_configurator.h:119
BootstrapCredentials mrs_metadata_account_
Definition: bootstrap_configurator.h:126
void configure_mrs(mysqlrouter::MySQLSession *session, const std::string &config_path, const std::map< std::string, std::string > &config_cmdln_options)
Definition: bootstrap_configurator.cc:302
BootstrapConfigurator(std::ostream &out_stream, std::ostream &err_stream)
Definition: bootstrap_configurator.cc:181
static void init_main_logger(mysql_harness::LoaderConfig &config, bool raw_mode=false)
Definition: bootstrap_configurator.cc:186
std::string bootstrap_mrs_developer_
Definition: bootstrap_configurator.h:129
void show_help()
Definition: bootstrap_configurator.cc:559
void load_configuration(const std::string &path)
Definition: bootstrap_configurator.cc:586
MySQLRouterAndMrsConf bootstrapper_
Definition: bootstrap_configurator.h:124
void run()
Definition: bootstrap_configurator.cc:275
mysql_harness::Path origin_
Definition: bootstrap_configurator.h:120
void show_usage() noexcept
Definition: bootstrap_configurator.cc:486
std::string get_configured_rest_endpoint() const
Definition: bootstrap_configurator.cc:734
void store_mrs_data_in_keyring()
Definition: bootstrap_configurator.cc:654
Definition: bootstrap_credentials.h:31
Handles command line arguments.
Definition: arg_handler.h:141
void add_option(const CmdOption::OptionNames &names, const std::string &description, const CmdOptionValueReq &value_req, const std::string &metavar, CmdOption::ActionFunc action, CmdOption::AtEndActionFunc at_end_action=[](const std::string &) { }) noexcept
Adds a command line option.
Definition: arg_handler.cc:54
Definition: keyring_handler.h:34
KeyringInfo class encapsulates loading and storing master key using master-key-reader and master-key-...
Definition: keyring_info.h:76
Definition: router_conf.h:52
virtual void prepare_command_options(CmdArgHandler &arg_handler, const std::string &bootstrap_uri="") noexcept
Definition: router_conf.cc:212
std::map< std::string, std::string > bootstrap_options_
key/value map of additional configuration options for bootstrap
Definition: router_conf.h:117
std::string bootstrap_uri_
Value of the argument passed to the -B or –bootstrap command line option for bootstrapping.
Definition: router_conf.h:109
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
Configuration.
Definition: config_parser.h:253
static constexpr unsigned int allow_keys
Flags for construction of configurations.
Definition: config_parser.h:265
Configuration file handler for the loader.
Definition: loader_config.h:46
Class representing a path in a file system.
Definition: filesystem.h:63
Definition: mysql_session.h:157
static SysUserOperations * instance()
Definition: sys_user_operations.cc:49
char * user
Definition: mysqladmin.cc:67
static PasswdValue check_user(const char *user)
Definition: mysqld.cc:3015
static char * path
Definition: mysqldump.cc:150
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Definition: base64.h:43
Definition: gcs_xcom_synode.h:64
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2876
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2894
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Defining the main class MySQLRouter.
Definition: bootstrap_configurator.h:136
bool is_metadata_cache
Definition: bootstrap_configurator.h:138
std::string key
Definition: bootstrap_configurator.h:137
std::vector< std::string > OptionNames
Definition: arg_handler.h:58