Add GitHub ping handling
Signed-off-by: Tiago Garcia <tiago.rgarcia@ua.pt>
This commit is contained in:
parent
d5a2353ded
commit
549444fd47
|
@ -10,6 +10,8 @@ class Routes {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
crow::SimpleApp app;
|
crow::SimpleApp app;
|
||||||
|
|
||||||
|
static bool check_ping(const crow::request &req);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,6 +11,8 @@ Routes::Routes(nlohmann::json config) {
|
||||||
const nlohmann::json config_run_actions = config["run-actions"];
|
const nlohmann::json config_run_actions = config["run-actions"];
|
||||||
const nlohmann::json config_tokens = config["tokens"];
|
const nlohmann::json config_tokens = config["tokens"];
|
||||||
|
|
||||||
|
Logger::info("[Routes] Creating server");
|
||||||
|
|
||||||
Logger::info("[Routes] Registering route \"/\"");
|
Logger::info("[Routes] Registering route \"/\"");
|
||||||
CROW_ROUTE(this->app, "/")
|
CROW_ROUTE(this->app, "/")
|
||||||
.methods("POST"_method, "GET"_method)
|
.methods("POST"_method, "GET"_method)
|
||||||
|
@ -28,6 +30,13 @@ Routes::Routes(nlohmann::json config) {
|
||||||
.methods("POST"_method)
|
.methods("POST"_method)
|
||||||
.name("Run Actions")
|
.name("Run Actions")
|
||||||
([&config_run_actions](const crow::request &req) {
|
([&config_run_actions](const crow::request &req) {
|
||||||
|
if (check_ping(req)) {
|
||||||
|
nlohmann::json response = {
|
||||||
|
{"status", 200},
|
||||||
|
{"message", "Pong"}
|
||||||
|
};
|
||||||
|
return crow::response(200, response.dump());
|
||||||
|
}
|
||||||
if (config_run_actions.is_null()) {
|
if (config_run_actions.is_null()) {
|
||||||
Logger::warn("[Routes] No run-actions configuration found");
|
Logger::warn("[Routes] No run-actions configuration found");
|
||||||
nlohmann::json response = {
|
nlohmann::json response = {
|
||||||
|
@ -53,6 +62,13 @@ Routes::Routes(nlohmann::json config) {
|
||||||
.methods("POST"_method)
|
.methods("POST"_method)
|
||||||
.name("Update Files")
|
.name("Update Files")
|
||||||
([&config_update_files, &config_tokens](const crow::request &req) {
|
([&config_update_files, &config_tokens](const crow::request &req) {
|
||||||
|
if (check_ping(req)) {
|
||||||
|
nlohmann::json response = {
|
||||||
|
{"status", 200},
|
||||||
|
{"message", "Pong"}
|
||||||
|
};
|
||||||
|
return crow::response(200, response.dump());
|
||||||
|
}
|
||||||
if (config_update_files.is_null()) {
|
if (config_update_files.is_null()) {
|
||||||
Logger::warn("[Routes] No update-files configuration found");
|
Logger::warn("[Routes] No update-files configuration found");
|
||||||
nlohmann::json response = {
|
nlohmann::json response = {
|
||||||
|
@ -92,3 +108,14 @@ Routes::Routes(nlohmann::json config) {
|
||||||
}
|
}
|
||||||
Logger::info("[Routes] Server stopped");
|
Logger::info("[Routes] Server stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Routes::check_ping(const crow::request &req) {
|
||||||
|
if (req.headers.find("X-GitHub-Event") == req.headers.end()) {
|
||||||
|
Logger::warn("[Routes] No X-GitHub-Event header found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (req.headers.find("X-GitHub-Event")->second == "ping") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue