|
2 | 2 | #include "commands/server_start_cmd.h" |
3 | 3 | #include "common/api_server_configuration.h" |
4 | 4 | #include "utils/curl_utils.h" |
| 5 | +#include "utils/file_manager_utils.h" |
5 | 6 | #include "utils/logging_utils.h" |
6 | 7 | #include "utils/string_utils.h" |
7 | 8 | #include "utils/url_parser.h" |
@@ -46,22 +47,40 @@ inline Json::Value NormalizeJson( |
46 | 47 | void commands::ConfigUpdCmd::Exec( |
47 | 48 | const std::string& host, int port, |
48 | 49 | const std::unordered_map<std::string, std::string>& options) { |
49 | | - if (!commands::IsServerAlive(host, port)) { |
50 | | - CLI_LOG("Starting server ..."); |
51 | | - commands::ServerStartCmd ssc; |
52 | | - if (!ssc.Exec(host, port)) { |
53 | | - return; |
54 | | - } |
55 | | - } |
56 | 50 |
|
57 | 51 | auto non_null_opts = std::unordered_map<std::string, std::string>(); |
58 | 52 | for (const auto& [key, value] : options) { |
59 | | - if (value.empty() && !CONFIGURATIONS.at(key).allow_empty) { |
| 53 | + // In case of api_keys, we allow empty value |
| 54 | + if (value.empty() && key != "api_keys") { |
60 | 55 | continue; |
61 | 56 | } |
62 | 57 | non_null_opts[key] = value; |
63 | 58 | } |
64 | 59 |
|
| 60 | + if (non_null_opts.size() == 1) { |
| 61 | + for (const auto& [key, value] : non_null_opts) { |
| 62 | + if (key == "api_keys") { |
| 63 | + auto config = file_manager_utils::GetCortexConfig(); |
| 64 | + config.apiKeys = string_utils::SplitBy(value, ","); |
| 65 | + auto result = file_manager_utils::UpdateCortexConfig(config); |
| 66 | + if (result.has_error()) { |
| 67 | + CLI_LOG_ERROR(result.error()); |
| 68 | + } else { |
| 69 | + CLI_LOG("Configuration updated successfully!"); |
| 70 | + } |
| 71 | + return; |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + if (!commands::IsServerAlive(host, port)) { |
| 77 | + CLI_LOG("Starting server ..."); |
| 78 | + commands::ServerStartCmd ssc; |
| 79 | + if (!ssc.Exec(host, port)) { |
| 80 | + return; |
| 81 | + } |
| 82 | + } |
| 83 | + |
65 | 84 | auto url = url_parser::Url{ |
66 | 85 | /* .protocol = */ "http", |
67 | 86 | /* .host = */ host + ":" + std::to_string(port), |
|
0 commit comments