diff --git a/src/main.cpp b/src/main.cpp index d5ceea1..519bff8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,7 @@ #if defined(OROTOOL_WITH_RESTCCPP) # include #endif +#include namespace { void print_ping(oro::Api& oro_api) { @@ -67,6 +68,17 @@ namespace { constexpr const auto us = dhandy::bt::make_string("_"); return (name + us + app_version()); } + + void validate_key(std::string_view key) { + using std::string; + using std::logic_error; + + std::regex key_reg("^[a-z0-9]{32}$"); + if (not std::regex_match(key.begin(), key.end(), key_reg)) + throw logic_error("API key \"" + string(key) + "\" doesn't look valid"); + + return; + } } //unnamed namespace int main(int argc, char* argv[]) { @@ -81,6 +93,7 @@ int main(int argc, char* argv[]) { ); print_ping(*oro_api); + validate_key(app_conf.api_key()); std::unique_ptr db(oro::OriginsDB::make(app_conf.backend(), app_conf.db_path()));