@@ -253,7 +253,13 @@ void RunServer(std::optional<std::string> host, std::optional<int> port,
253253 auto validate_api_key = [config_service](const drogon::HttpRequestPtr& req) {
254254 auto api_keys = config_service->GetApiServerConfiguration ()->api_keys ;
255255 static const std::unordered_set<std::string> public_endpoints = {
256- " /openapi.json" , " /healthz" , " /processManager/destroy" };
256+ " /openapi.json" , " /healthz" , " /processManager/destroy" , " /events" };
257+
258+ if (req->getHeader (" Authorization" ).empty () &&
259+ req->path () == " /v1/configs" ) {
260+ CTL_WRN (" Require API key to access /v1/configs" );
261+ return false ;
262+ }
257263
258264 // If API key is not set, skip validation
259265 if (api_keys.empty ()) {
@@ -377,6 +383,7 @@ void print_help() {
377383 " ~/cortexcpp)\n " ;
378384 std::cout << " --host Host name (default: 127.0.0.1)\n " ;
379385 std::cout << " --port Port number (default: 39281)\n " ;
386+ std::cout << " --api_configs Keys to acess API endpoints\n " ;
380387 std::cout << " --ignore_cout Ignore cout output\n " ;
381388 std::cout << " --loglevel Set log level\n " ;
382389
@@ -405,6 +412,7 @@ int main(int argc, char* argv[]) {
405412
406413 std::optional<std::string> server_host;
407414 std::optional<int > server_port;
415+ std::optional<std::string> api_keys;
408416 bool ignore_cout_log = false ;
409417#if defined(_WIN32)
410418 for (int i = 0 ; i < argc; i++) {
@@ -421,6 +429,8 @@ int main(int argc, char* argv[]) {
421429 server_host = cortex::wc::WstringToUtf8 (argv[i + 1 ]);
422430 } else if (command == L" --port" ) {
423431 server_port = std::stoi (argv[i + 1 ]);
432+ } else if (command == L" --api_keys" ) {
433+ api_keys = cortex::wc::WstringToUtf8 (argv[i + 1 ]);
424434 } else if (command == L" --ignore_cout" ) {
425435 ignore_cout_log = true ;
426436 } else if (command == L" --loglevel" ) {
@@ -441,6 +451,8 @@ int main(int argc, char* argv[]) {
441451 server_host = argv[i + 1 ];
442452 } else if (strcmp (argv[i], " --port" ) == 0 ) {
443453 server_port = std::stoi (argv[i + 1 ]);
454+ } else if (strcmp (argv[i], " --api_keys" ) == 0 ) {
455+ api_keys = argv[i + 1 ];
444456 } else if (strcmp (argv[i], " --ignore_cout" ) == 0 ) {
445457 ignore_cout_log = true ;
446458 } else if (strcmp (argv[i], " --loglevel" ) == 0 ) {
@@ -476,6 +488,15 @@ int main(int argc, char* argv[]) {
476488 }
477489 }
478490
491+ if (api_keys) {
492+ auto config = file_manager_utils::GetCortexConfig ();
493+ config.apiKeys = string_utils::SplitBy (*api_keys, " ," );
494+ auto result = file_manager_utils::UpdateCortexConfig (config);
495+ if (result.has_error ()) {
496+ CTL_ERR (result.error ());
497+ }
498+ }
499+
479500 // check if migration is needed
480501 if (auto res = cortex::migr::MigrationManager (
481502 cortex::db::Database::GetInstance ().db ())
0 commit comments