Commit e3f158e0 authored by Michael Ott's avatar Michael Ott
Browse files

Add /version query to REST API

parent 923d8efd
......@@ -26,6 +26,9 @@
//================================================================================
#include "CARestAPI.h"
#include <dcdb/version.h>
#include "version.h"
#include <boost/beast/http/field.hpp>
#define stdBind(fun) std::bind(&CARestAPI::fun, \
......@@ -48,6 +51,7 @@ CARestAPI::CARestAPI(serverSettings_t settings,
_mqttServer(mqttServer) {
addEndpoint("/help", {http::verb::get, stdBind(GET_help)});
addEndpoint("/version", {http::verb::get, stdBind(GET_version)});
addEndpoint("/hosts", {http::verb::get, stdBind(GET_hosts)});
addEndpoint("/average", {http::verb::get, stdBind(GET_average)});
addEndpoint("/quit", {http::verb::put, stdBind(PUT_quit)});
......@@ -69,6 +73,11 @@ void CARestAPI::GET_help(endpointArgs) {
res.result(http::status::ok);
}
void CARestAPI::GET_version(endpointArgs) {
res.body() = "CollectAgent " + std::string(VERSION) + " (libdcdb " + DCDB::Version::getVersion() + ")";
res.result(http::status::ok);
}
void CARestAPI::GET_hosts(endpointArgs) {
if (!_mqttServer) {
res.body() = "The MQTT server is not initialized!";
......
......@@ -82,6 +82,18 @@ private:
*/
void GET_help(endpointArgs);
/**
* GET "/version"
*
* @brief Return version number.
*
* Queries | key | possible values | explanation
* -------------------------------------------------------------------------
* Required | - | - | -
* Optional | - | - | -
*/
void GET_version(endpointArgs);
/**
* GET "/hosts"
*
......
......@@ -259,8 +259,8 @@ bool RESTHttpsServer::validateUser(const http::request<Body>& req, Send&& send)
res.body() = "Unauthorized access!\n";
res.prepare_payload();
//GET /help does not need any authorization
if (req.target() == "/help" && req.method() == http::verb::get) {
//GET /help and /version do not need any authorization
if ((req.method() == http::verb::get) && ((req.target() == "/help") || (req.target() == "/version"))) {
return true;
}
......
......@@ -30,6 +30,7 @@
#include <sstream>
#include <string>
#include <signal.h>
#include "version.h"
#include <boost/property_tree/ptree.hpp>
......@@ -51,6 +52,7 @@ RestAPI::RestAPI(serverSettings_t settings,
_io(io) {
addEndpoint("/help", {http::verb::get, stdBind(GET_help)});
addEndpoint("/version", {http::verb::get, stdBind(GET_version)});
addEndpoint("/plugins", {http::verb::get, stdBind(GET_plugins)});
addEndpoint("/sensors", {http::verb::get, stdBind(GET_sensors)});
addEndpoint("/average", {http::verb::get, stdBind(GET_average)});
......@@ -76,6 +78,11 @@ void RestAPI::GET_help(endpointArgs) {
res.result(http::status::ok);
}
void RestAPI::GET_version(endpointArgs) {
res.body() = "dcdbpusher " + std::string(VERSION);
res.result(http::status::ok);
}
void RestAPI::GET_plugins(endpointArgs) {
std::ostringstream data;
if (getQuery("json", queries) == "true") {
......
......@@ -89,6 +89,18 @@ class RestAPI : public RESTHttpsServer {
*/
void GET_help(endpointArgs);
/**
* GET "/version"
*
* @brief Return version number
*
* Queries | key | possible values | explanation
* -------------------------------------------------------------------------
* Required | - | - | -
* Optional | - | - | -
*/
void GET_version(endpointArgs);
/**
* GET "/plugins"
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment