@@ -423,25 +423,25 @@ void ConfigGenerator::init(
423423
424424 // throws std::runtime_error, std::logic_error,
425425 connect_to_metadata_server (u, bootstrap_socket, bootstrap_options);
426- auto schema_version = mysqlrouter::get_metadata_schema_version (mysql_.get ());
426+ schema_version_ = mysqlrouter::get_metadata_schema_version (mysql_.get ());
427427
428- if (schema_version == mysqlrouter::kUpgradeInProgressMetadataVersion ) {
428+ if (schema_version_ == mysqlrouter::kUpgradeInProgressMetadataVersion ) {
429429 throw std::runtime_error (
430430 " Currently the cluster metadata update is in progress. Please rerun "
431431 " the bootstrap when it is finished." );
432432 }
433433
434434 if (!metadata_schema_version_is_compatible (kRequiredBootstrapSchemaVersion ,
435- schema_version )) {
435+ schema_version_ )) {
436436 throw std::runtime_error (mysqlrouter::string_format (
437437 " This version of MySQL Router is not compatible with the provided "
438438 " MySQL InnoDB cluster metadata. Expected metadata version %s, "
439439 " got %s" ,
440440 to_string (kRequiredBootstrapSchemaVersion ).c_str (),
441- to_string (schema_version ).c_str ()));
441+ to_string (schema_version_ ).c_str ()));
442442 }
443443
444- metadata_ = mysqlrouter::create_metadata (schema_version , mysql_.get (),
444+ metadata_ = mysqlrouter::create_metadata (schema_version_ , mysql_.get (),
445445 bootstrap_options);
446446
447447 // at this point we know the cluster type so let's do additional verifications
@@ -2020,6 +2020,42 @@ static void save_initial_dynamic_state(
20202020 mdc_dynamic_state.save (state_stream);
20212021}
20222022
2023+ /* *
2024+ * Add proper authentication backend section to the config based on the
2025+ * metadata version. If needed it creates an empty authentication password
2026+ * file used in the config.
2027+ *
2028+ * @param[in] datadir - path of a router data directory
2029+ * @param[in] auth_backend_name - authentication backend section name
2030+ * @param[in] schema_version - metadata schema version
2031+ *
2032+ * @return http_auth_backend config section string
2033+ */
2034+ static std::string create_http_auth_backend_section (
2035+ const mysql_harness::Path &datadir,
2036+ const std::string_view auth_backend_name,
2037+ const mysqlrouter::MetadataSchemaVersion schema_version) {
2038+ if (metadata_schema_version_is_compatible (kNewMetadataVersion ,
2039+ schema_version)) {
2040+ return mysql_harness::ConfigBuilder::build_section (
2041+ std::string{" http_auth_backend:" }.append (auth_backend_name),
2042+ {{" backend" , " metadata_cache" }});
2043+ } else {
2044+ const auto auth_backend_passwd_file =
2045+ datadir.join (" auth_backend_passwd_file" ).str ();
2046+ const auto open_res = open_ofstream (auth_backend_passwd_file);
2047+ if (!open_res) {
2048+ log_warning (" Cannot create file '%s': %s" ,
2049+ auth_backend_passwd_file.c_str (),
2050+ open_res.error ().message ().c_str ());
2051+ }
2052+
2053+ return mysql_harness::ConfigBuilder::build_section (
2054+ std::string{" http_auth_backend:" }.append (auth_backend_name),
2055+ {{" backend" , " file" }, {" filename" , auth_backend_passwd_file}});
2056+ }
2057+ }
2058+
20232059/* static*/ std::string ConfigGenerator::gen_metadata_cache_routing_section (
20242060 bool is_classic, bool is_writable, const Options::Endpoint endpoint,
20252061 const Options &options, const std::string &metadata_key) {
@@ -2203,9 +2239,8 @@ std::string ConfigGenerator::generate_config_for_rest(
22032239 config << mysql_harness::ConfigBuilder::build_section (" rest_api" , {});
22042240
22052241 config << " \n\n " ;
2206- config << mysql_harness::ConfigBuilder::build_section (
2207- " http_auth_backend:" + auth_backend_name,
2208- {{" backend" , " metadata_cache" }});
2242+ config << create_http_auth_backend_section (datadir_path, auth_backend_name,
2243+ schema_version_);
22092244
22102245 config << " \n\n " ;
22112246 config << mysql_harness::ConfigBuilder::build_section (
0 commit comments