-
Notifications
You must be signed in to change notification settings - Fork 92
feat(core)!: Replace YAML config with CLI args and env vars for metadata DB (resolves #1146). #1148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
21944b9
bbce2fc
849b6b4
5806785
144f74a
eece9aa
6d534b3
0cd45e3
cb43f62
8ea2f0a
90353c1
d4c17f4
d3d2146
a0687a5
1bc0502
690e035
e3a24b0
de68007
d21506b
1647e0b
04923b8
aedebe1
5dc87d1
968221c
cae4ce5
aedca2b
9c63298
47fb5d2
54e3483
e39e1d7
7b39750
2ba751d
87cc885
1aa27fe
dc0c899
a4fd245
ea9765f
06bc482
eba4952
b06d71a
e647fcf
ba0c2c5
3745ca2
fe3115c
015f583
67f2d49
bec5805
aab68bf
6279484
230629e
dfde4fa
ae6d1e0
667dce6
57cf478
0f6ca85
8df0d2f
f07d036
3e7637c
7f52c1f
8f6aaf9
e154899
85e00ce
4e829ff
8c0ff24
ba9a0ac
91fe771
179df88
d7e6afb
04c30ea
9648484
1b9d318
c9834f3
4971191
edb6810
20c61a6
71ed500
e3eecde
b8cbe0a
7d1a273
baf993f
399e1bd
a686b54
b2ad166
e0a6ecc
ea08810
e14eb39
a03cf80
dbe94d3
9cf11c3
510bf1e
26f9a56
b886c33
2c10dbb
69b99da
9d5c7ab
5156dc9
f2855e4
9600944
00b22b8
b368802
e524ed7
9807fb2
4a2790e
ab36b4d
2cb4751
602436b
e93131b
87c3524
7ccf42e
f605611
32b06fe
e2ca0b8
e7fd723
0ac028e
5267b9f
a54eae2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,110 +1,185 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "GlobalMetadataDBConfig.hpp" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #include <cstdlib> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <istream> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <stdexcept> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <string_view> | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #include <boost/program_options/options_description.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <boost/program_options/value_semantic.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <fmt/core.h> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include <yaml-cpp/yaml.h> | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| using std::exception; | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "GlobalMySQLMetadataDB.hpp" | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "type_utils.hpp" | ||||||||||||||||||||||||||||||||||||||||||||||
|
junhaoliao marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| using std::invalid_argument; | ||||||||||||||||||||||||||||||||||||||||||||||
| using std::string; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| static exception get_yaml_missing_key_exception(string const& key_name) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument(fmt::format("Missing key '{}'", key_name)); | ||||||||||||||||||||||||||||||||||||||||||||||
| namespace { | ||||||||||||||||||||||||||||||||||||||||||||||
| // Constants | ||||||||||||||||||||||||||||||||||||||||||||||
| constexpr clp::GlobalMetadataDBConfig::MetadataDBType cDefaultMetadataDbType{ | ||||||||||||||||||||||||||||||||||||||||||||||
| clp::GlobalMetadataDBConfig::MetadataDBType::SQLite | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
| constexpr std::string_view cDefaultMetadataDbHost{"127.0.0.1"}; | ||||||||||||||||||||||||||||||||||||||||||||||
| constexpr int cDefaultMetadataDbPort{3306}; | ||||||||||||||||||||||||||||||||||||||||||||||
| constexpr std::string_view cDefaultMetadataDbName{"clp-db"}; | ||||||||||||||||||||||||||||||||||||||||||||||
| constexpr std::string_view cDefaultMetadataTablePrefix{"clp_"}; | ||||||||||||||||||||||||||||||||||||||||||||||
| constexpr int cMinPort{1}; | ||||||||||||||||||||||||||||||||||||||||||||||
| constexpr int cMaxPort{65'535}; | ||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| namespace clp { | ||||||||||||||||||||||||||||||||||||||||||||||
| auto operator>>(std::istream& in, GlobalMetadataDBConfig::MetadataDBType& metadata_db_type) | ||||||||||||||||||||||||||||||||||||||||||||||
| -> std::istream& { | ||||||||||||||||||||||||||||||||||||||||||||||
| string db_type_string; | ||||||||||||||||||||||||||||||||||||||||||||||
| in >> db_type_string; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| for (size_t i = 0; i < GlobalMetadataDBConfig::cMetadataDBTypeNames.size(); ++i) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (GlobalMetadataDBConfig::cMetadataDBTypeNames.at(i) == db_type_string) { | ||||||||||||||||||||||||||||||||||||||||||||||
| metadata_db_type = static_cast<GlobalMetadataDBConfig::MetadataDBType>(i); | ||||||||||||||||||||||||||||||||||||||||||||||
| return in; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument(fmt::format("Unknown database type: {}", db_type_string)); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Optional: replace linear scan with a small lookup map. Not critical given two types, but a map avoids iteration and reads more declaratively. - for (size_t i = 0; i < GlobalMetadataDBConfig::cMetadataDBTypeNames.size(); ++i) {
- if (GlobalMetadataDBConfig::cMetadataDBTypeNames.at(i) == db_type_string) {
- metadata_db_type = static_cast<GlobalMetadataDBConfig::MetadataDBType>(i);
- return in;
- }
- }
+ static const std::unordered_map<std::string, GlobalMetadataDBConfig::MetadataDBType> kMap{
+ {std::string(GlobalMetadataDBConfig::cMetadataDBTypeNames[enum_to_underlying_type(GlobalMetadataDBConfig::MetadataDBType::SQLite)]),
+ GlobalMetadataDBConfig::MetadataDBType::SQLite},
+ {std::string(GlobalMetadataDBConfig::cMetadataDBTypeNames[enum_to_underlying_type(GlobalMetadataDBConfig::MetadataDBType::MySQL)]),
+ GlobalMetadataDBConfig::MetadataDBType::MySQL},
+ };
+ if (auto it = kMap.find(db_type_string); it != kMap.end()) {
+ metadata_db_type = it->second;
+ return in;
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| static exception | ||||||||||||||||||||||||||||||||||||||||||||||
| get_yaml_unconvertable_value_exception(string const& key_name, string const& destination_type) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument( | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt::format("'{}' could not be converted to type '{}'", key_name, destination_type) | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| GlobalMetadataDBConfig::GlobalMetadataDBConfig( | ||||||||||||||||||||||||||||||||||||||||||||||
| boost::program_options::options_description& options_description | ||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| std::string_view const cMetadataDbTypeMysqlOptDescPrefix{fmt::format( | ||||||||||||||||||||||||||||||||||||||||||||||
| "(--db-type={} only)", | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDBTypeNames[enum_to_underlying_type(MetadataDBType::MySQL)] | ||||||||||||||||||||||||||||||||||||||||||||||
| )}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // clang-format off | ||||||||||||||||||||||||||||||||||||||||||||||
| options_description.add_options() | ||||||||||||||||||||||||||||||||||||||||||||||
|
haiqi96 marked this conversation as resolved.
kirkrodrigues marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||||||||||||||||||
| "db-type", | ||||||||||||||||||||||||||||||||||||||||||||||
| boost::program_options::value<MetadataDBType>(&m_metadata_db_type) | ||||||||||||||||||||||||||||||||||||||||||||||
| ->default_value( | ||||||||||||||||||||||||||||||||||||||||||||||
| cDefaultMetadataDbType, | ||||||||||||||||||||||||||||||||||||||||||||||
| string( | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDBTypeNames[ | ||||||||||||||||||||||||||||||||||||||||||||||
| enum_to_underlying_type(cDefaultMetadataDbType) | ||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt::format( | ||||||||||||||||||||||||||||||||||||||||||||||
| "Database type [{} | {}]", | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDBTypeNames[enum_to_underlying_type(MetadataDBType::SQLite)], | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDBTypeNames[enum_to_underlying_type(MetadataDBType::MySQL)] | ||||||||||||||||||||||||||||||||||||||||||||||
| ).c_str() | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||||||||||||||||||
| "db-host", | ||||||||||||||||||||||||||||||||||||||||||||||
| boost::program_options::value<string>(&m_metadata_db_host) | ||||||||||||||||||||||||||||||||||||||||||||||
| ->default_value(string(cDefaultMetadataDbHost)), | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt::format( | ||||||||||||||||||||||||||||||||||||||||||||||
| "{} Database host", | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDbTypeMysqlOptDescPrefix | ||||||||||||||||||||||||||||||||||||||||||||||
| ).c_str() | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||||||||||||||||||
| "db-port", | ||||||||||||||||||||||||||||||||||||||||||||||
| boost::program_options::value<int>(&m_metadata_db_port) | ||||||||||||||||||||||||||||||||||||||||||||||
| ->default_value(cDefaultMetadataDbPort), | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt::format( | ||||||||||||||||||||||||||||||||||||||||||||||
| "{} Database port", | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDbTypeMysqlOptDescPrefix | ||||||||||||||||||||||||||||||||||||||||||||||
| ).c_str() | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||||||||||||||||||
| "db-name", | ||||||||||||||||||||||||||||||||||||||||||||||
| boost::program_options::value<string>(&m_metadata_db_name) | ||||||||||||||||||||||||||||||||||||||||||||||
| ->default_value(string(cDefaultMetadataDbName)), | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt::format( | ||||||||||||||||||||||||||||||||||||||||||||||
| "{} Database name", | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDbTypeMysqlOptDescPrefix | ||||||||||||||||||||||||||||||||||||||||||||||
| ).c_str() | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||||||||||||||||||||||||
| "db-table-prefix", | ||||||||||||||||||||||||||||||||||||||||||||||
| boost::program_options::value<string>(&m_metadata_table_prefix) | ||||||||||||||||||||||||||||||||||||||||||||||
| ->default_value(string(cDefaultMetadataTablePrefix)), | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt::format( | ||||||||||||||||||||||||||||||||||||||||||||||
| "{} Database table prefix", | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDbTypeMysqlOptDescPrefix | ||||||||||||||||||||||||||||||||||||||||||||||
| ).c_str() | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| // clang-format on | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| namespace clp { | ||||||||||||||||||||||||||||||||||||||||||||||
| void GlobalMetadataDBConfig::parse_config_file(string const& config_file_path) { | ||||||||||||||||||||||||||||||||||||||||||||||
| YAML::Node config = YAML::LoadFile(config_file_path); | ||||||||||||||||||||||||||||||||||||||||||||||
| auto GlobalMetadataDBConfig::read_credentials_from_env_if_needed() -> void { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (MetadataDBType::SQLite == m_metadata_db_type) { | ||||||||||||||||||||||||||||||||||||||||||||||
| // SQLite doesn't require extra parameters. | ||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Minor: Inconsistent comment style with contraction For consistency with professional documentation style, consider using "does not" instead of "doesn't" in the comments. - // SQLite doesn't require extra parameters.
+ // SQLite does not require extra parameters.Also applies to: 135-135 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+114
to
+118
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Minor wording consistency in comments. Prefer “does not” over “doesn't” for consistency. - // SQLite doesn't require extra parameters.
+ // SQLite does not require extra parameters.(Apply in both locations.) Also applies to: 131-134 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+114
to
119
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Consistency nit: prefer “does not” over “doesn't” in comments. Keep comment tone consistent throughout the file. - // SQLite doesn't require extra parameters.
+ // SQLite does not require extra parameters.(Apply similarly at Line 134.) Also applies to: 132-147 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| if (!config["type"]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_missing_key_exception("type"); | ||||||||||||||||||||||||||||||||||||||||||||||
| // Silence the check since this class won't be used in a multithreaded context. | ||||||||||||||||||||||||||||||||||||||||||||||
| // NOLINTNEXTLINE(concurrency-mt-unsafe) | ||||||||||||||||||||||||||||||||||||||||||||||
| if (auto const* db_username{std::getenv("CLP_DB_USER")}; nullptr != db_username) { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_username.emplace(db_username); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| auto db_type_string = config["type"].as<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| if ("sqlite" == db_type_string) { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_type = MetadataDBType::SQLite; | ||||||||||||||||||||||||||||||||||||||||||||||
| } else if ("mysql" == db_type_string) { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_type = MetadataDBType::MySQL; | ||||||||||||||||||||||||||||||||||||||||||||||
| // Silence the check since this class won't be used in a multithreaded context. | ||||||||||||||||||||||||||||||||||||||||||||||
| // NOLINTNEXTLINE(concurrency-mt-unsafe) | ||||||||||||||||||||||||||||||||||||||||||||||
| if (auto const* db_password{std::getenv("CLP_DB_PASS")}; nullptr != db_password) { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_password.emplace(db_password); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!config["host"]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_missing_key_exception("host"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_host = config["host"].as<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (YAML::BadConversion& e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_unconvertable_value_exception("host", "string"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_db_host.empty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Database 'host' not specified or empty."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| auto GlobalMetadataDBConfig::validate() const -> void { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_db_type == MetadataDBType::SQLite) { | ||||||||||||||||||||||||||||||||||||||||||||||
| // SQLite doesn't require extra parameters. | ||||||||||||||||||||||||||||||||||||||||||||||
| if (cDefaultMetadataDbHost != m_metadata_db_host | ||||||||||||||||||||||||||||||||||||||||||||||
| || cDefaultMetadataDbPort != m_metadata_db_port | ||||||||||||||||||||||||||||||||||||||||||||||
| || cDefaultMetadataDbName != m_metadata_db_name | ||||||||||||||||||||||||||||||||||||||||||||||
| || cDefaultMetadataTablePrefix != m_metadata_table_prefix | ||||||||||||||||||||||||||||||||||||||||||||||
| || m_metadata_db_username.has_value() || m_metadata_db_password.has_value()) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument( | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt::format( | ||||||||||||||||||||||||||||||||||||||||||||||
| "MySQL-specific parameters cannot be used with --db-type={}." | ||||||||||||||||||||||||||||||||||||||||||||||
| " Please remove them or set '--db-type={}'.", | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDBTypeNames[enum_to_underlying_type(m_metadata_db_type)], | ||||||||||||||||||||||||||||||||||||||||||||||
| cMetadataDBTypeNames[enum_to_underlying_type(MetadataDBType::MySQL)] | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!config["port"]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_missing_key_exception("port"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_port = config["port"].as<int>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (YAML::BadConversion& e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_unconvertable_value_exception("port", "int"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_db_port < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Database 'port' cannot be negative."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_db_host.empty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Database '--db-host' is empty."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!config["name"]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_missing_key_exception("name"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_name = config["name"].as<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (YAML::BadConversion& e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_unconvertable_value_exception("name", "string"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_db_name.empty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Database 'name' not specified or empty."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (cMinPort > m_metadata_db_port || cMaxPort < m_metadata_db_port) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument( | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt::format( | ||||||||||||||||||||||||||||||||||||||||||||||
| "Database '--db-port' is out of range [{}, {}]: {}", | ||||||||||||||||||||||||||||||||||||||||||||||
| cMinPort, | ||||||||||||||||||||||||||||||||||||||||||||||
| cMaxPort, | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_port | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!config["username"]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_missing_key_exception("username"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_username = config["username"].as<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (YAML::BadConversion& e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_unconvertable_value_exception("username", "string"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_db_username.empty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Database 'username' not specified or empty."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_db_name.empty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Database '--db-name' is empty."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!config["password"]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_missing_key_exception("password"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_db_password = config["password"].as<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (YAML::BadConversion& e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_unconvertable_value_exception("password", "string"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_db_password.empty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Database 'password' not specified or empty."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_table_prefix.empty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Database '--db-table_prefix' is empty."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!config["table_prefix"]) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_missing_key_exception("table_prefix"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| m_metadata_table_prefix = config["table_prefix"].as<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (YAML::BadConversion& e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw get_yaml_unconvertable_value_exception("table_prefix", "string"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (m_metadata_table_prefix.empty()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Database 'table_prefix' not specified or empty."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Unknown type"); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (false == m_metadata_db_username.has_value()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Environment variable 'CLP_DB_USER' not set."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (false == m_metadata_db_password.has_value()) { | ||||||||||||||||||||||||||||||||||||||||||||||
| throw invalid_argument("Environment variable 'CLP_DB_PASS' not set."); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace clp | ||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.