Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
e3f158e0
Commit
e3f158e0
authored
Nov 05, 2020
by
Michael Ott
Browse files
Add /version query to REST API
parent
923d8efd
Changes
5
Show whitespace changes
Inline
Side-by-side
collectagent/CARestAPI.cpp
View file @
e3f158e0
...
...
@@ -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!"
;
...
...
collectagent/CARestAPI.h
View file @
e3f158e0
...
...
@@ -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"
*
...
...
common/src/RESTHttpsServer.cpp
View file @
e3f158e0
...
...
@@ -259,8 +259,8 @@ bool RESTHttpsServer::validateUser(const http::request<Body>& req, Send&& send)
res
.
body
()
=
"Unauthorized access!
\n
"
;
res
.
prepare_payload
();
//GET /help do
es
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
;
}
...
...
dcdbpusher/RestAPI.cpp
View file @
e3f158e0
...
...
@@ -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"
)
{
...
...
dcdbpusher/RestAPI.h
View file @
e3f158e0
...
...
@@ -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"
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment