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,
122 operator bool()
const {
return port > 0 || !
socket.empty(); }
148 std::chrono::milliseconds
ttl;
176 const std::map<std::string, std::string> &
options,
177 const std::string &owner)
const;
189 const std::map<std::string, std::string> &bootstrap_options);
206 const std::string &bootstrap_socket);
221 const URI &u,
const std::string &bootstrap_socket,
222 const std::map<std::string, std::string> &bootstrap_options);
245 const ExistingConfigOptions &existing_config_options);
248 const std::string &directory,
249 bool interactive_master_key,
250 const std::map<std::string, std::string> &
options);
253 const std::map<std::string, std::string> &
options);
257 const std::string &script_path,
258 const std::map<std::string, std::string> &
options);
262 const std::string &program_name, std::ostream &config_file,
265 const std::map<std::string, std::string> &
options,
266 const std::map<std::string, std::vector<std::string>> &multivalue_options,
268 bool directory_deployment,
AutoCleaner &auto_clean);
271 uint32_t &router_id, std::string &username, std::string &
password,
272 const std::string &router_name,
const ClusterInfo &cluster_info,
273 const std::map<std::string, std::string> &user_options,
274 const std::map<std::string, std::vector<std::string>> &multivalue_options,
278 std::ostream &config_file, std::ostream &state_file, uint32_t router_id,
279 const std::string &router_name,
const std::string &system_username,
280 const ClusterInfo &cluster_info,
const std::string &username,
283 const std::map<std::string, std::string> &config_overwrites,
284 const std::string &state_file_name =
"");
291 const std::string &router_name,
const std::string &metadata_cluster,
292 const std::string &cluster_type_name,
const std::string &hostname,
297 const std::map<std::string, std::string> &user_options,
322 &multivalue_options) noexcept;
349 const
std::
set<
std::
string> &hostnames, const
std::
string &username,
350 const
std::
string &
password,
bool password_change_ok);
381 const
std::
string &username, const
std::
set<
std::
string> &hostnames,
382 const
std::
string &
password,
bool password_change_ok,
bool if_not_exists);
402 const
std::
string &
password,
bool if_not_exists = false);
409 const
std::
string &username);
412 const
std::
string &username, const
std::
set<
std::
string> &hostnames,
421 const
std::
string &config_file_path,
437 uint32_t router_id, const
std::
string &username,
454 const
std::
string &hostname_override);
457 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
void give_grants_to_users(const std::string &new_accounts)
Definition: config_generator.cc:3081
std::string fetch_password_from_keyring(const std::string &username, uint32_t router_id)
Definition: config_generator.cc:1955
std::string cluster_initial_password_
Definition: config_generator.h:509
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:535
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:508
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:2915
std::unique_ptr< MySQLSession > mysql_
Definition: config_generator.h:498
std::string cluster_initial_socket_
Definition: config_generator.h:510
void create_stop_script(const std::string &directory, const std::map< std::string, std::string > &options)
Definition: config_generator.cc:3544
bool keyring_initialized_
Definition: config_generator.h:513
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:612
void set_keyring_info_real_paths(std::map< std::string, std::string > &options, const mysql_harness::Path &path)
Definition: config_generator.cc:1942
void set_file_owner(const std::map< std::string, std::string > &options, const std::string &owner) const
Definition: config_generator.cc:3648
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:3334
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:2006
std::ostream & out_stream_
Definition: config_generator.h:515
mysqlrouter::MetadataSchemaVersion schema_version_
Definition: config_generator.h:538
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="")
Definition: config_generator.cc:2439
void throw_account_exists(const MySQLSession::Error &e, const std::string &username)
Definition: config_generator.cc:2861
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:2762
std::unique_ptr< ClusterMetadata > metadata_
Definition: config_generator.h:499
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:629
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:2657
int connect_timeout_
Definition: config_generator.h:500
void print_bootstrap_start_msg(uint32_t router_id, bool directory_deployment, const mysql_harness::Path &config_file_path)
Definition: config_generator.cc:2634
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:3112
void undo_create_user_for_new_accounts() noexcept
Deletes Router accounts just created.
Definition: config_generator.cc:3181
std::string cluster_specific_id_
Definition: config_generator.h:505
void update_router_info(uint32_t router_id, const Options &options)
std::ostream & err_stream_
Definition: config_generator.h:516
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
std::string bootstrap_deployment(const std::string &program_name, std::ostream &config_file, std::ostream &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:1430
int read_timeout_
Definition: config_generator.h:501
void verify_router_account(const std::string &username, const std::string &password, bool strict)
Definition: config_generator.cc:1630
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:1256
void init_keyring_file(uint32_t router_id, bool create_if_needed=true)
Definition: config_generator.cc:2034
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:2971
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:518
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:3449
std::string cluster_initial_hostname_
Definition: config_generator.h:506
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:860
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:1290
KeyringInfo keyring_info_
Definition: config_generator.h:512
virtual void set_script_permissions(const std::string &script_path, const std::map< std::string, std::string > &options)
Definition: config_generator.cc:3431
unsigned int cluster_initial_port_
Definition: config_generator.h:507
uint32_t register_router(const std::string &router_name, const std::string &hostname_override, bool force)
Definition: config_generator.cc:1571
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:3132
void ensure_router_id_is_ours(uint32_t &router_id, const std::string &hostname_override)
Definition: config_generator.cc:1548
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:1983
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:1612
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:1865
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:3617
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:2812
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:116
static char * password
Definition: mysql_secure_installation.cc:56
static char * path
Definition: mysqldump.cc:137
constexpr pos_type Options
Definition: http_request.h:261
std::string dir
Double write files location.
Definition: buf0dblwr.cc:77
const std::string config_file_name
Definition: config.cc:64
Definition: options.cc:49
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:33
Definition: cluster_metadata.h:40
Definition: config_generator.h:235
uint32_t router_id
Definition: config_generator.h:237
bool valid
Definition: config_generator.h:236
uint16_t ro_x_port
Definition: config_generator.h:240
std::string username
Definition: config_generator.h:238
uint16_t rw_x_port
Definition: config_generator.h:239
Definition: config_generator.h:115
std::string socket
Definition: config_generator.h:117
int port
Definition: config_generator.h:116
Endpoint(const std::string &path)
Definition: config_generator.h:119
Endpoint()
Definition: config_generator.h:118
Endpoint(int port_)
Definition: config_generator.h:120
Definition: config_generator.h:114
std::string target_cluster_by_name
Definition: config_generator.h:172
Endpoint ro_x_endpoint
Definition: config_generator.h:129
std::string server_ssl_curves
Definition: config_generator.h:162
std::string client_ssl_dh_params
Definition: config_generator.h:159
std::string server_ssl_verify
Definition: config_generator.h:168
std::string target_cluster
Definition: config_generator.h:171
std::string keyring_master_key_file_path
Definition: config_generator.h:139
std::string override_logfilename
Definition: config_generator.h:132
std::string client_ssl_mode
Definition: config_generator.h:157
std::string keyring_master_key
Definition: config_generator.h:138
Endpoint ro_endpoint
Definition: config_generator.h:127
std::string bind_address
Definition: config_generator.h:141
mysqlrouter::SSLOptions ssl_options
Definition: config_generator.h:146
int connect_timeout
Definition: config_generator.h:143
std::string client_ssl_curves
Definition: config_generator.h:156
bool disable_rest
Definition: config_generator.h:151
std::string client_ssl_key
Definition: config_generator.h:158
std::string override_datadir
Definition: config_generator.h:134
std::string override_logdir
Definition: config_generator.h:131
Endpoint rw_x_endpoint
Definition: config_generator.h:128
std::string server_ssl_mode
Definition: config_generator.h:163
Endpoint rw_endpoint
Definition: config_generator.h:126
std::string server_ssl_cipher
Definition: config_generator.h:161
std::string client_ssl_cert
Definition: config_generator.h:154
int read_timeout
Definition: config_generator.h:144
std::string server_ssl_capath
Definition: config_generator.h:165
std::string https_port_str
Definition: config_generator.h:152
std::string keyring_file_path
Definition: config_generator.h:137
std::chrono::milliseconds ttl
Definition: config_generator.h:148
std::string socketsdir
Definition: config_generator.h:135
bool use_gr_notifications
Definition: config_generator.h:149
std::string override_rundir
Definition: config_generator.h:133
std::string client_ssl_cipher
Definition: config_generator.h:155
std::string server_ssl_crlpath
Definition: config_generator.h:167
std::string server_ssl_crl
Definition: config_generator.h:166
std::string server_ssl_ca
Definition: config_generator.h:164
Definition: config_generator.h:527
std::string router_key
Definition: config_generator.h:530
std::string router_cert
Definition: config_generator.h:531
std::string ca_key
Definition: config_generator.h:528
std::string ca_cert
Definition: config_generator.h:529
Definition: config_generator.h:518
@ kAllAccounts
Definition: config_generator.h:521
std::string accounts
Definition: config_generator.h:524
SSL connection related options.
Definition: datatypes.h:39