MXS-1390: Add missing self-link to module command output

The module commands now produce functional self-links. The links most
often require parameters so they are not of great use.
This commit is contained in:
Markus Mäkelä
2017-09-07 21:16:38 +03:00
parent 6cf90ceb15
commit 5abb30c357
3 changed files with 33 additions and 10 deletions

View File

@ -39,6 +39,14 @@ json_t* mxs_json_resource(const char* host, const char* self, json_t* data)
return rval;
}
json_t* mxs_json_metadata(const char* host, const char* self, json_t* data)
{
json_t* rval = json_object();
json_object_set_new(rval, CN_LINKS, self_link(host, self));
json_object_set_new(rval, CN_META, data);
return rval;
}
json_t* mxs_json_relationship(const char* host, const char* endpoint)
{
json_t* rel = json_object();

View File

@ -667,14 +667,15 @@ HttpResponse cb_modulecmd(const HttpRequest& request)
{
if (output)
{
rc = MHD_HTTP_OK;
/** Store the command output in the meta field. This allows
/**
* Store the command output in the meta field. This allows
* all the commands to conform to the JSON API even though
* the content of the field can vary from command to command. */
json_t* obj = json_object();
json_object_set_new(obj, CN_META, output);
output = obj;
* the content of the field can vary from command to command.
*/
rc = MHD_HTTP_OK;
std::string self = "/"; // The uri_segment doesn't have the leading slash
self += request.uri_segment(0, request.uri_part_count());
output = mxs_json_metadata(request.host(), self.c_str(), output);
}
else
{