Skip to content

Commit

Permalink
Angus/1213 no runtime config (#1214) (#1221)
Browse files Browse the repository at this point in the history
* added no_runtime_config

* changelog updated

* Moved runtime config flag check to mappings in RegisterRoutes

Co-authored-by: Adrianna Pińska <[email protected]>

Co-authored-by: Angus Comrie <[email protected]>
  • Loading branch information
confluence and veggiesaurus authored Nov 24, 2022
1 parent 4e184ce commit bcafa3d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
* Added support for image fitting with field of view ([#150](https://github.com/CARTAvis/carta-backend/issues/150)).
* List frequency and velocity in file info for single channel image ([#1152](https://github.com/CARTAvis/carta-backend/issues/1152)).
* Added a debug config flag for disabling runtime config ([#1213](https://github.com/CARTAvis/carta-backend/issues/1213)).

### Changed
* Enhanced image fitting performance by switching the solver from qr to cholesky ([#1114](https://github.com/CARTAvis/carta-backend/pull/1114)).
Expand Down
17 changes: 14 additions & 3 deletions src/HttpServer/HttpServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ const std::string success_string = json({{"success", true}}).dump();
uint32_t HttpServer::_scripting_request_id = 0;

HttpServer::HttpServer(std::shared_ptr<SessionManager> session_manager, fs::path root_folder, fs::path user_directory,
std::string auth_token, bool read_only_mode, bool enable_frontend, bool enable_database, bool enable_scripting)
std::string auth_token, bool read_only_mode, bool enable_frontend, bool enable_database, bool enable_scripting,
bool enable_runtime_config)
: _session_manager(session_manager),
_http_root_folder(root_folder),
_auth_token(auth_token),
_read_only_mode(read_only_mode),
_config_folder(user_directory / "config"),
_enable_frontend(enable_frontend),
_enable_database(enable_database),
_enable_scripting(enable_scripting) {
_enable_scripting(enable_scripting),
_enable_runtime_config(enable_runtime_config) {
if (_enable_frontend && !root_folder.empty()) {
_frontend_found = IsValidFrontendFolder(root_folder);

Expand Down Expand Up @@ -71,7 +73,11 @@ void HttpServer::RegisterRoutes() {
}

if (_enable_frontend) {
app.get("/config", [&](auto res, auto req) { HandleGetConfig(res, req); });
if (_enable_runtime_config) {
app.get("/config", [&](auto res, auto req) { HandleGetConfig(res, req); });
} else {
app.get("/config", [&](auto res, auto req) { DefaultSuccess(res, req); });
}
// Static routes for all other files
app.get("/*", [&](Res* res, Req* req) { HandleStaticRequest(res, req); });
} else {
Expand Down Expand Up @@ -666,4 +672,9 @@ void HttpServer::NotImplemented(Res* res, Req* req) {
return;
}

void HttpServer::DefaultSuccess(Res* res, Req* req) {
res->writeStatus(HTTP_200)->end();
return;
}

} // namespace carta
5 changes: 4 additions & 1 deletion src/HttpServer/HttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ typedef std::function<bool(int&, uint32_t&, std::string&, std::string&, std::str
class HttpServer {
public:
HttpServer(std::shared_ptr<SessionManager> session_manager, fs::path root_folder, fs::path user_directory, std::string auth_token,
bool read_only_mode = false, bool enable_frontend = true, bool enable_database = true, bool enable_scripting = false);
bool read_only_mode = false, bool enable_frontend = true, bool enable_database = true, bool enable_scripting = false,
bool enable_runtime_config = true);
bool CanServeFrontend() {
return _frontend_found;
}
Expand Down Expand Up @@ -78,6 +79,7 @@ class HttpServer {
void HandleClearObject(const std::string& object_type, Res* res, Req* req);
void HandleScriptingAction(Res* res, Req* req);
void NotImplemented(Res* res, Req* req);
void DefaultSuccess(Res* res, Req* req);

fs::path _http_root_folder;
fs::path _config_folder;
Expand All @@ -87,6 +89,7 @@ class HttpServer {
bool _enable_frontend;
bool _enable_database;
bool _enable_scripting;
bool _enable_runtime_config;
std::shared_ptr<SessionManager> _session_manager;
static uint32_t _scripting_request_id;
};
Expand Down
5 changes: 3 additions & 2 deletions src/Main/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ int main(int argc, char* argv[]) {
}
}

http_server = std::make_unique<HttpServer>(session_manager, frontend_path, settings.user_directory, auth_token,
settings.read_only_mode, !settings.no_frontend, !settings.no_database, settings.enable_scripting);
http_server =
std::make_unique<HttpServer>(session_manager, frontend_path, settings.user_directory, auth_token, settings.read_only_mode,
!settings.no_frontend, !settings.no_database, settings.enable_scripting, !settings.no_runtime_config);
http_server->RegisterRoutes();

if (!settings.no_frontend && !http_server->CanServeFrontend()) {
Expand Down
2 changes: 2 additions & 0 deletions src/Main/ProgramSettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ void ProgramSettings::ApplyCommandLineSettings(int argc, char** argv) {

options.add_options("Deprecated and debug")
("debug_no_auth", "accept all incoming WebSocket connections on the specified port(s) (not secure; use with caution!)", cxxopts::value<bool>())
("no_runtime_config", "do not send a runtime config object to frontend clients", cxxopts::value<bool>())
("threads", "[deprecated] manually set number of event processing threads (no longer supported)", cxxopts::value<int>(), "<threads>")
("base", "[deprecated] set starting folder for data files (use the positional parameter instead)", cxxopts::value<string>(), "<dir>")
("root", "[deprecated] use 'top_level_folder' instead", cxxopts::value<string>(), "<dir>")
Expand Down Expand Up @@ -295,6 +296,7 @@ global configuration files, respectively.
no_database = result["no_database"].as<bool>();
no_frontend = result["no_frontend"].as<bool>();
debug_no_auth = result["debug_no_auth"].as<bool>();
no_runtime_config = result["no_runtime_config"].as<bool>();
no_browser = result["no_browser"].as<bool>();
read_only_mode = result["read_only_mode"].as<bool>();
enable_scripting = result["enable_scripting"].as<bool>();
Expand Down
4 changes: 3 additions & 1 deletion src/Main/ProgramSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct ProgramSettings {
bool no_http = false; // Deprecated
bool no_frontend = false;
bool no_database = false;
bool no_runtime_config = false;
bool debug_no_auth = false;
bool no_browser = false;
bool no_log = false;
Expand Down Expand Up @@ -87,7 +88,8 @@ struct ProgramSettings {
{"read_only_mode", &read_only_mode},
{"enable_scripting", &enable_scripting},
{"no_frontend", &no_frontend},
{"no_database", &no_database}
{"no_database", &no_database},
{"no_runtime_config", &no_runtime_config}
};

std::unordered_map<std::string, std::string*> strings_keys_map{
Expand Down

0 comments on commit bcafa3d

Please sign in to comment.