Throw if api key looks wrong
This commit is contained in:
parent
abc5441a50
commit
2221aef77c
1 changed files with 13 additions and 0 deletions
13
src/main.cpp
13
src/main.cpp
|
@ -28,6 +28,7 @@
|
|||
#if defined(OROTOOL_WITH_RESTCCPP)
|
||||
# include <restc-cpp/error.h>
|
||||
#endif
|
||||
#include <regex>
|
||||
|
||||
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<oro::OriginsDB> db(oro::OriginsDB::make(app_conf.backend(), app_conf.db_path()));
|
||||
|
||||
|
|
Loading…
Reference in a new issue