Add api_key to the config file
This commit is contained in:
parent
1c911f36b0
commit
d1716a0c91
4 changed files with 14 additions and 7 deletions
|
@ -4,3 +4,4 @@ worker_threads=3
|
||||||
|
|
||||||
[rules]
|
[rules]
|
||||||
fetch_extra_delay=30
|
fetch_extra_delay=30
|
||||||
|
api_key=my_key_here
|
||||||
|
|
|
@ -38,6 +38,10 @@ namespace {
|
||||||
constexpr const char g_fetch_extra_delay[] = "fetch_extra_delay";
|
constexpr const char g_fetch_extra_delay[] = "fetch_extra_delay";
|
||||||
constexpr const char g_fetch_extra_delay_def[] = "30";
|
constexpr const char g_fetch_extra_delay_def[] = "30";
|
||||||
|
|
||||||
|
constexpr const char g_api_key_sect[] = "rules";
|
||||||
|
constexpr const char g_api_key[] = "api_key";
|
||||||
|
constexpr const char g_api_key_def[] = "";
|
||||||
|
|
||||||
std::string whole_ini() {
|
std::string whole_ini() {
|
||||||
std::ifstream input(g_config_file_path);
|
std::ifstream input(g_config_file_path);
|
||||||
input >> std::noskipws;
|
input >> std::noskipws;
|
||||||
|
@ -87,6 +91,10 @@ std::string_view AppConfig::db_path() const {
|
||||||
return value_ifp(m_ini, g_db_path_sect, g_db_path, g_def_sqlite_db_name, false);
|
return value_ifp(m_ini, g_db_path_sect, g_db_path, g_def_sqlite_db_name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string_view AppConfig::api_key() const {
|
||||||
|
return value_ifp(m_ini, g_api_key_sect, g_api_key, g_api_key_def, true);
|
||||||
|
}
|
||||||
|
|
||||||
std::size_t AppConfig::worker_threads() const {
|
std::size_t AppConfig::worker_threads() const {
|
||||||
std::string_view val = value_ifp(m_ini, g_worker_threads_sect, g_worker_threads, g_def_worker_threads, false);
|
std::string_view val = value_ifp(m_ini, g_worker_threads_sect, g_worker_threads, g_def_worker_threads, false);
|
||||||
if (val == "max") {
|
if (val == "max") {
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
~AppConfig() noexcept;
|
~AppConfig() noexcept;
|
||||||
|
|
||||||
std::string_view db_path() const;
|
std::string_view db_path() const;
|
||||||
|
std::string_view api_key() const;
|
||||||
std::size_t worker_threads() const;
|
std::size_t worker_threads() const;
|
||||||
std::size_t fetch_extra_delay() const;
|
std::size_t fetch_extra_delay() const;
|
||||||
|
|
||||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -41,16 +41,13 @@ namespace {
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if (2 != argc) {
|
|
||||||
std::cerr << "Please provide your API key\n";
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
oro::Api oro_api(duck::g_base_url, argv[1], "RESTC_CPP", "Testing");
|
duck::AppConfig app_conf;
|
||||||
|
std::string_view api_key = (2 == argc ? std::string_view(argv[1]) : app_conf.api_key());
|
||||||
|
oro::Api oro_api(duck::g_base_url, std::string(api_key), "RESTC_CPP", "Testing");
|
||||||
|
|
||||||
print_ping(oro_api);
|
print_ping(oro_api);
|
||||||
|
|
||||||
duck::AppConfig app_conf;
|
|
||||||
oro::OriginsDB db(app_conf.db_path());
|
oro::OriginsDB db(app_conf.db_path());
|
||||||
duck::test(
|
duck::test(
|
||||||
&oro_api,
|
&oro_api,
|
||||||
|
|
Loading…
Add table
Reference in a new issue