From 798ee840a8ddae5e1e4416825f8b90035eeccda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 4 May 2017 20:41:45 +0300 Subject: [PATCH] MXS-1220: Make /maxscale/ resource conform to JSON API The /maxscale/ resource now conforms to the JSON API and a test checks that it the returned JSON is valid. --- server/core/config.cc | 33 +++++++++++-------- .../test/rest-api/test/schema_validation.js | 1 + 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/server/core/config.cc b/server/core/config.cc index 6e59791a8..f20c5a818 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -40,6 +40,7 @@ #include #include #include +#include #include "maxscale/config.h" #include "maxscale/filter.h" @@ -3855,20 +3856,24 @@ int config_parse_server_list(const char *servers, char ***output_array) json_t* config_paths_to_json(const char* host) { + json_t* attr = json_object(); + json_object_set_new(attr, "libdir", json_string(get_libdir())); + json_object_set_new(attr, "datadir", json_string(get_datadir())); + json_object_set_new(attr, "process_datadir", json_string(get_process_datadir())); + json_object_set_new(attr, "cachedir", json_string(get_cachedir())); + json_object_set_new(attr, "configdir", json_string(get_configdir())); + json_object_set_new(attr, "config_persistdir", json_string(get_config_persistdir())); + json_object_set_new(attr, "module_configdir", json_string(get_module_configdir())); + json_object_set_new(attr, "piddir", json_string(get_piddir())); + json_object_set_new(attr, "logdir", json_string(get_logdir())); + json_object_set_new(attr, "langdir", json_string(get_langdir())); + json_object_set_new(attr, "execdir", json_string(get_execdir())); + json_object_set_new(attr, "connector_plugindir", json_string(get_connector_plugindir())); + json_t* obj = json_object(); + json_object_set_new(obj, CN_ATTRIBUTES, attr); + json_object_set_new(obj, CN_ID, json_string(CN_MAXSCALE)); + json_object_set_new(obj, CN_TYPE, json_string(CN_MAXSCALE)); - json_object_set_new(obj, "libdir", json_string(get_libdir())); - json_object_set_new(obj, "datadir", json_string(get_datadir())); - json_object_set_new(obj, "process_datadir", json_string(get_process_datadir())); - json_object_set_new(obj, "cachedir", json_string(get_cachedir())); - json_object_set_new(obj, "configdir", json_string(get_configdir())); - json_object_set_new(obj, "config_persistdir", json_string(get_config_persistdir())); - json_object_set_new(obj, "module_configdir", json_string(get_module_configdir())); - json_object_set_new(obj, "piddir", json_string(get_piddir())); - json_object_set_new(obj, "logdir", json_string(get_logdir())); - json_object_set_new(obj, "langdir", json_string(get_langdir())); - json_object_set_new(obj, "execdir", json_string(get_execdir())); - json_object_set_new(obj, "connector_plugindir", json_string(get_connector_plugindir())); - - return obj; + return mxs_json_resource(host, MXS_JSON_API_MAXSCALE, obj); } diff --git a/server/core/test/rest-api/test/schema_validation.js b/server/core/test/rest-api/test/schema_validation.js index 18b3c97c4..8035d24f2 100644 --- a/server/core/test/rest-api/test/schema_validation.js +++ b/server/core/test/rest-api/test/schema_validation.js @@ -38,6 +38,7 @@ describe("Individual Resources", function() { "/monitors/MySQL-Monitor", "/filters/Hint", "/sessions/1", + "/maxscale/", ] tests.forEach(function(endpoint) {