26#ifndef ROUTER_CONFIG_GENERATOR_INCLUDED
27#define ROUTER_CONFIG_GENERATOR_INCLUDED
48#include "unique_ptr.h"
57class SysUserOperationsBase;
58class SysUserOperations;
64 std::ostream &out_stream = std::cout, std::ostream &err_stream = std::cerr
82 void init(
const std::string &server_url,
83 const std::map<std::string, std::string> &bootstrap_options);
98 const std::string &program_name,
const std::string &config_file_path,
99 const std::string &state_file_path,
100 const std::map<std::string, std::string> &
options,
101 const std::map<std::string, std::vector<std::string>> &multivalue_options,
105 const std::string &program_name,
const std::string &directory,
106 const std::map<std::string, std::string> &
options,
107 const std::map<std::string, std::vector<std::string>> &multivalue_options,
124 operator bool()
const {
return port > 0 || !
socket.empty(); }
152 std::chrono::milliseconds
ttl;
180 const std::map<std::string, std::string> &
options,
181 const std::string &owner)
const;
193 const std::map<std::string, std::string> &bootstrap_options);
210 const std::string &bootstrap_socket);
225 const URI &u,
const std::string &bootstrap_socket,
226 const std::map<std::string, std::string> &bootstrap_options);
249 const ExistingConfigOptions &existing_config_options);
252 const std::string &directory,
253 bool interactive_master_key,
254 const std::map<std::string, std::string> &
options);
257 const std::map<std::string, std::string> &
options);
261 const std::string &script_path,
262 const std::map<std::string, std::string> &
options);
266 const std::string &program_name, std::ofstream &config_file,
269 const std::map<std::string, std::string> &
options,
270 const std::map<std::string, std::vector<std::string>> &multivalue_options,
272 bool directory_deployment,
AutoCleaner &auto_clean);
275 uint32_t &router_id, std::string &username, std::string &
password,
276 const std::string &router_name,
const ClusterInfo &cluster_info,
277 const std::map<std::string, std::string> &user_options,
278 const std::map<std::string, std::vector<std::string>> &multivalue_options,
282 std::ostream &config_file, std::ostream &state_file, uint32_t router_id,
283 const std::string &router_name,
const std::string &system_username,
284 const ClusterInfo &cluster_info,
const std::string &username,
287 const std::map<std::string, std::string> &config_overwrites,
288 const std::string &state_file_name,
const bool full);
295 const std::string &router_name,
const std::string &metadata_cluster,
296 const std::string &cluster_type_name,
const std::string &hostname,
301 const std::map<std::string, std::string> &user_options,
326 &multivalue_options) noexcept;
353 const
std::
set<
std::
string> &hostnames, const
std::
string &username,
354 const
std::
string &
password,
bool password_change_ok);
385 const
std::
string &username, const
std::
set<
std::
string> &hostnames,
386 const
std::
string &
password,
bool password_change_ok,
bool if_not_exists);
406 const
std::
string &
password,
bool if_not_exists = false);
413 const
std::
string &username);
416 const
std::
string &username, const
std::
set<
std::
string> &hostnames,
425 const
std::
string &config_file_path,
441 uint32_t router_id, const
std::
string &username,
458 const
std::
string &hostname_override);
461 const
std::
string &hostname_override,
bool force);
Class representing an error.
Definition: error.h:48
KeyringInfo class encapsulates loading and storing master key using master-key-reader and master-key-...
Definition: keyring_info.h:76
A helper class for handling file paths.
Definition: path.h:38
Class representing a path in a file system.
Definition: filesystem.h:63
Automatic cleanup on scope exit utility class.
Definition: auto_cleaner.h:62
Definition: config_generator.h:61
std::string plugin_folder_
Definition: config_generator.h:544
std::string bootstrap_deployment(const std::string &program_name, std::ofstream &config_file, std::ofstream &state_file, const mysql_harness::Path &config_file_path, const mysql_harness::Path &state_file_path, const std::string &name, const std::map< std::string, std::string > &options, const std::map< std::string, std::vector< std::string > > &multivalue_options, const std::map< std::string, std::string > &default_paths, bool directory_deployment, AutoCleaner &auto_clean)
Definition: config_generator.cc:1459
void give_grants_to_users(const std::string &new_accounts)
Definition: config_generator.cc:3220
std::string fetch_password_from_keyring(const std::string &username, uint32_t router_id)
Definition: config_generator.cc:1998
std::string cluster_initial_password_
Definition: config_generator.h:513
void connect_to_metadata_server(const URI &u, const std::string &bootstrap_socket, const std::map< std::string, std::string > &bootstrap_options)
init() calls this to connect to metadata server; sets mysql_ (connection) object.
Definition: config_generator.cc:387
SysUserOperationsBase * sys_user_operations_
Definition: config_generator.h:539
void init(const std::string &server_url, const std::map< std::string, std::string > &bootstrap_options)
first part of the bootstrap process
Definition: config_generator.cc:422
std::string cluster_initial_username_
Definition: config_generator.h:512
void create_users(const std::string &username, const std::set< std::string > &hostnames, const std::string &password, bool if_not_exists)
Definition: config_generator.cc:3053
std::unique_ptr< MySQLSession > mysql_
Definition: config_generator.h:502
void create_config(std::ostream &config_file, std::ostream &state_file, uint32_t router_id, const std::string &router_name, const std::string &system_username, const ClusterInfo &cluster_info, const std::string &username, const Options &options, const std::map< std::string, std::string > &default_paths, const std::map< std::string, std::string > &config_overwrites, const std::string &state_file_name, const bool full)
Definition: config_generator.cc:2532
std::string cluster_initial_socket_
Definition: config_generator.h:514
void create_stop_script(const std::string &directory, const std::map< std::string, std::string > &options)
Definition: config_generator.cc:3684
bool keyring_initialized_
Definition: config_generator.h:517
bool datadir_contains_allowed_files(const mysql_harness::Directory &dir) const
Check if datadir directory contains only files that are allowed before the bootstrap.
Definition: config_generator.cc:608
void set_keyring_info_real_paths(std::map< std::string, std::string > &options, const mysql_harness::Path &path)
Definition: config_generator.cc:1985
void set_file_owner(const std::map< std::string, std::string > &options, const std::string &owner) const
Definition: config_generator.cc:3788
ExistingConfigOptions get_options_from_config_if_it_exists(const std::string &config_file_path, const mysqlrouter::ClusterInfo &cluster_info, bool forcing_overwrite)
Get selected configuration options from the existing Router configuration file.
Definition: config_generator.cc:3474
void init_keyring_and_master_key(AutoCleaner &auto_clean, const std::map< std::string, std::string > &user_options, uint32_t router_id)
Definition: config_generator.cc:2049
std::ostream & out_stream_
Definition: config_generator.h:519
mysqlrouter::MetadataSchemaVersion schema_version_
Definition: config_generator.h:542
void throw_account_exists(const MySQLSession::Error &e, const std::string &username)
Definition: config_generator.cc:2999
std::string create_router_accounts(const std::map< std::string, std::string > &user_options, const std::set< std::string > &hostnames, const std::string &username, const std::string &password, bool password_change_ok)
Creates Router accounts.
Definition: config_generator.cc:2900
std::unique_ptr< ClusterMetadata > metadata_
Definition: config_generator.h:503
void bootstrap_directory_deployment(const std::string &program_name, const std::string &directory, const std::map< std::string, std::string > &options, const std::map< std::string, std::vector< std::string > > &multivalue_options, const std::map< std::string, std::string > &default_paths)
Create a self-contained deployment of the Router in a directory.
Definition: config_generator.cc:625
std::string get_bootstrap_report_text(const std::string &program_name, const std::string &config_file_name, const std::string &router_name, const std::string &metadata_cluster, const std::string &cluster_type_name, const std::string &hostname, bool is_system_deployment, const Options &options)
Definition: config_generator.cc:2776
int connect_timeout_
Definition: config_generator.h:504
void print_bootstrap_start_msg(uint32_t router_id, bool directory_deployment, const mysql_harness::Path &config_file_path)
Definition: config_generator.cc:2753
void init_gr_data(const URI &u, const std::string &bootstrap_socket)
init() calls this to set GR-related member fields.
Definition: config_generator.cc:410
std::string make_account_list(const std::string username, const std::set< std::string > &hostnames)
Definition: config_generator.cc:3251
void undo_create_user_for_new_accounts() noexcept
Deletes Router accounts just created.
Definition: config_generator.cc:3320
std::string cluster_specific_id_
Definition: config_generator.h:509
void update_router_info(uint32_t router_id, const Options &options)
std::ostream & err_stream_
Definition: config_generator.h:520
bool warn_on_no_ssl(const std::map< std::string, std::string > &options)
logs warning and returns false if SSL mode is set to PREFERRED and SSL is not being used,...
Definition: config_generator.cc:240
ConfigGenerator(std::ostream &out_stream=std::cout, std::ostream &err_stream=std::cerr, SysUserOperationsBase *sys_user_operations=SysUserOperations::instance())
Definition: config_generator.cc:189
int read_timeout_
Definition: config_generator.h:505
void verify_router_account(const std::string &username, const std::string &password, bool strict)
Definition: config_generator.cc:1700
URI parse_server_uri(const std::string &server_uri, const std::string &bootstrap_socket)
init() calls this to validate and extract metadata server info from server URI, including user creden...
Definition: config_generator.cc:329
struct mysqlrouter::ConfigGenerator::UndoCreateAccountList undo_create_account_list_
void set_log_file_permissions(const std::map< std::string, std::string > &default_paths, const std::map< std::string, std::string > &user_options, const Options &options)
Definition: config_generator.cc:1285
void set_plugin_folder(const std::string &val)
Definition: config_generator.h:114
void init_keyring_file(uint32_t router_id, bool create_if_needed=true)
Definition: config_generator.cc:2077
std::set< std::string > get_hostnames_of_created_accounts(const std::string &username, const std::set< std::string > &hostnames, bool if_not_exists)
Definition: config_generator.cc:3110
void bootstrap_system_deployment(const std::string &program_name, const std::string &config_file_path, const std::string &state_file_path, const std::map< std::string, std::string > &options, const std::map< std::string, std::vector< std::string > > &multivalue_options, const std::map< std::string, std::string > &default_paths)
Definition: config_generator.cc:515
void parse_bootstrap_options(const std::map< std::string, std::string > &bootstrap_options)
init() calls this to read and validate several command-line options; results are stored in member fie...
Definition: config_generator.cc:284
const struct mysqlrouter::ConfigGenerator::TLS_filenames tls_filenames_
void create_start_script(const std::string &program_name, const std::string &directory, bool interactive_master_key, const std::map< std::string, std::string > &options)
Definition: config_generator.cc:3589
std::string cluster_initial_hostname_
Definition: config_generator.h:510
Options fill_options(const std::map< std::string, std::string > &user_options, const std::map< std::string, std::string > &default_paths, const ExistingConfigOptions &existing_config_options)
Definition: config_generator.cc:855
void prepare_ssl_certificate_files(const std::map< std::string, std::string > &user_options, const std::map< std::string, std::string > &default_paths, AutoCleaner *auto_cleaner) const
Prepare X.509 certificates for the Router.
Definition: config_generator.cc:1319
KeyringInfo keyring_info_
Definition: config_generator.h:516
virtual void set_script_permissions(const std::string &script_path, const std::map< std::string, std::string > &options)
Definition: config_generator.cc:3571
unsigned int cluster_initial_port_
Definition: config_generator.h:511
uint32_t register_router(const std::string &router_name, const std::string &hostname_override, bool force)
Definition: config_generator.cc:1641
void create_accounts(const std::string &username, const std::set< std::string > &hostnames, const std::string &password, bool if_not_exists=false)
Creates Router account (low-level function)
Definition: config_generator.cc:3271
void ensure_router_id_is_ours(uint32_t &router_id, const std::string &hostname_override)
Definition: config_generator.cc:1618
void store_credentials_in_keyring(AutoCleaner &auto_clean, const std::map< std::string, std::string > &user_options, uint32_t router_id, const std::string &username, const std::string &password, Options &options)
Definition: config_generator.cc:2026
static std::set< std::string > get_account_host_args(const std::map< std::string, std::vector< std::string > > &multivalue_options) noexcept
Finds all hostnames given on command-line.
Definition: config_generator.cc:1682
static void set_ssl_options(MySQLSession *sess, const std::map< std::string, std::string > &options)
Definition: config_generator.cc:211
std::tuple< std::string > try_bootstrap_deployment(uint32_t &router_id, std::string &username, std::string &password, const std::string &router_name, const ClusterInfo &cluster_info, const std::map< std::string, std::string > &user_options, const std::map< std::string, std::vector< std::string > > &multivalue_options, const Options &options)
Definition: config_generator.cc:1904
bool backup_config_file_if_different(const mysql_harness::Path &config_path, const std::string &new_file_path, const std::map< std::string, std::string > &options, AutoCleaner *auto_cleaner=nullptr)
Definition: config_generator.cc:3757
virtual ~ConfigGenerator()
std::string create_accounts_with_compliant_password(const std::map< std::string, std::string > &user_options, const std::string &username, const std::set< std::string > &hostnames, const std::string &password, bool password_change_ok, bool if_not_exists)
Creates Router account with compliant password.
Definition: config_generator.cc:2950
void set_keyring_info(const KeyringInfo &keyring_info)
Definition: config_generator.h:110
Definition: mysql_session.h:153
Base class to allow multiple SysUserOperations implementations.
Definition: sys_user_operations.h:45
static SysUserOperations * instance()
Definition: sys_user_operations.cc:49
Parse and create URIs according to RFC3986.
Definition: uri.h:70
static std::map< string, enum_variable_source > default_paths
Defines mapping between config files names and its corresponding enum values.
Definition: my_default.cc:120
static char * password
Definition: mysql_secure_installation.cc:58
static char * path
Definition: mysqldump.cc:149
std::string dir
Double write files location.
Definition: buf0dblwr.cc:77
constexpr pos_type Options
Definition: method.h:48
const std::string config_file_name
Definition: config.cc:64
Definition: options.cc:57
Definition: gcs_xcom_synode.h:64
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2874
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2882
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2892
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2438
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:29
Definition: cluster_metadata.h:40
Definition: config_generator.h:239
uint32_t router_id
Definition: config_generator.h:241
bool valid
Definition: config_generator.h:240
uint16_t ro_x_port
Definition: config_generator.h:244
std::string username
Definition: config_generator.h:242
uint16_t rw_x_port
Definition: config_generator.h:243
Definition: config_generator.h:117
std::string socket
Definition: config_generator.h:119
int port
Definition: config_generator.h:118
Endpoint(const std::string &path)
Definition: config_generator.h:121
Endpoint()
Definition: config_generator.h:120
Endpoint(int port_)
Definition: config_generator.h:122
Definition: config_generator.h:116
std::string target_cluster_by_name
Definition: config_generator.h:176
Endpoint ro_x_endpoint
Definition: config_generator.h:132
std::string server_ssl_curves
Definition: config_generator.h:166
std::string client_ssl_dh_params
Definition: config_generator.h:163
std::string server_ssl_verify
Definition: config_generator.h:172
std::string target_cluster
Definition: config_generator.h:175
std::string keyring_master_key_file_path
Definition: config_generator.h:143
std::string override_logfilename
Definition: config_generator.h:136
Endpoint rw_split_endpoint
Definition: config_generator.h:130
std::string client_ssl_mode
Definition: config_generator.h:161
std::string keyring_master_key
Definition: config_generator.h:142
Endpoint ro_endpoint
Definition: config_generator.h:129
std::string bind_address
Definition: config_generator.h:145
mysqlrouter::SSLOptions ssl_options
Definition: config_generator.h:150
int connect_timeout
Definition: config_generator.h:147
bool disable_rw_split_endpoint
Definition: config_generator.h:133
std::string client_ssl_curves
Definition: config_generator.h:160
bool disable_rest
Definition: config_generator.h:155
std::string client_ssl_key
Definition: config_generator.h:162
std::string override_datadir
Definition: config_generator.h:138
std::string override_logdir
Definition: config_generator.h:135
Endpoint rw_x_endpoint
Definition: config_generator.h:131
std::string server_ssl_mode
Definition: config_generator.h:167
Endpoint rw_endpoint
Definition: config_generator.h:128
std::string server_ssl_cipher
Definition: config_generator.h:165
std::string client_ssl_cert
Definition: config_generator.h:158
int read_timeout
Definition: config_generator.h:148
std::string server_ssl_capath
Definition: config_generator.h:169
std::string https_port_str
Definition: config_generator.h:156
std::string keyring_file_path
Definition: config_generator.h:141
std::chrono::milliseconds ttl
Definition: config_generator.h:152
std::string socketsdir
Definition: config_generator.h:139
bool use_gr_notifications
Definition: config_generator.h:153
std::string override_rundir
Definition: config_generator.h:137
std::string client_ssl_cipher
Definition: config_generator.h:159
std::string server_ssl_crlpath
Definition: config_generator.h:171
std::string server_ssl_crl
Definition: config_generator.h:170
std::string server_ssl_ca
Definition: config_generator.h:168
Definition: config_generator.h:531
std::string router_key
Definition: config_generator.h:534
std::string router_cert
Definition: config_generator.h:535
std::string ca_key
Definition: config_generator.h:532
std::string ca_cert
Definition: config_generator.h:533
Definition: config_generator.h:522
@ kAllAccounts
Definition: config_generator.h:525
std::string accounts
Definition: config_generator.h:528
SSL connection related options.
Definition: datatypes.h:39