diff --git a/CMakeLists.txt b/CMakeLists.txt index 847ee10..09c14fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,13 +128,7 @@ add_plugin(running_avg) if(NOT WIN32) # Serial port plugin is not supported on Windows add_plugin(serial_reader SRCS ${SRC_DIR}/serialport.cpp) -endif() - -if(NOT MADS_NO_DEPS_ONLY) add_plugin(mqtt LIBS mosquittopp) - if (APPLE) - add_plugin(restway LIBS restclient-cpp) - endif() endif() add_loader(load_filter) diff --git a/amwcapture.p12 b/amwcapture.p12 deleted file mode 100644 index 6d6aebb..0000000 Binary files a/amwcapture.p12 and /dev/null differ diff --git a/file.crt.pem b/file.crt.pem deleted file mode 100644 index ebff6f7..0000000 --- a/file.crt.pem +++ /dev/null @@ -1,25 +0,0 @@ -Bag Attributes - localKeyID: 7B F6 20 60 B1 C7 D4 BF 90 09 67 34 74 87 79 40 9E 80 A9 40 -subject=CN=amwcapture, O=Siemens -issuer=CN=amwcapture, O=Siemens ------BEGIN CERTIFICATE----- -MIIDhDCCAmygAwIBAgIUDjLtNnEBbtCF/GdeZsHxLJd6W48wDQYJKoZIhvcNAQEN -BQAwJzETMBEGA1UEAwwKYW13Y2FwdHVyZTEQMA4GA1UECgwHU2llbWVuczAeFw0y -NDA2MDkxMTMzMjRaFw0yOTA2MTExMTMzMjRaMCcxEzARBgNVBAMMCmFtd2NhcHR1 -cmUxEDAOBgNVBAoMB1NpZW1lbnMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK -AoIBAQDJg462JQziCclRADzo761vY2vZlXJ0ZB+g10e189Dh67GoCt1ReYE3buu5 -5uvf/phaZmvllG0ku3VdOhUkCFP1HhAc+e5ZmYlFmIQ84NZBblKxFm51gtfRlvOW -RJ4Fa3a1KGGZSFP8xgD4QcjGffnm8uLqcmb4dSXl1dosvQiOzlApDybz53PUWgX4 -7UBYFf2tv+pbZFMyq9o7EZVuKX3D4Rmk/aNSlQM4NiXckI1FF9uKo56kPUsvhX9P -0GVc6+xnnQxQdLaliVVfPOIeVkknqRRdiVgCuh7npbXXIvAy3B4a5VHYwUGXc9x6 -PFe0f9x4yKIgd9qgp0HO7eaJ2N0FAgMBAAGjgacwgaQwDwYDVR0TAQH/BAUwAwEB -/zAOBgNVHQ8BAf8EBAMCAfYwHQYDVR0OBBYEFJ6y1xayYu9O6tbYVS7yUxreFGb5 -MGIGA1UdIwRbMFmAFJ6y1xayYu9O6tbYVS7yUxreFGb5oSukKTAnMRMwEQYDVQQD -DAphbXdjYXB0dXJlMRAwDgYDVQQKDAdTaWVtZW5zghQOMu02cQFu0IX8Z15mwfEs -l3pbjzANBgkqhkiG9w0BAQ0FAAOCAQEAtGb9kav6IHTCwp0FPSV94FHTSTgdSBlv -ITHIskRAVttFB8r/qO8rl+fYOTxptEoE5qm7p+oN88u4hy/tEop9TTzApbVMzevS -GzXFbcfpt1Cdjvl0jMTGbJ7j1OC8YkG0e9QkAMo9enQ6FZyMHKrkw9ZosrBC3eUL -AXpHT+gGx4fbhj2XXDuHMD1bLdqUoUK9RyoZteHzxfgKQt0h53kG7KcaPd6U0nyi -T1AWmn3Ztb5ug+EGo0Flc6i+GJQ5iMRu9SjztljAGydOC0qYXscLuuH1Z/GjnFO5 -KFOn1KM0LGt9gIWTIhoBxFwLtTkzv8xc1xgwyulhY6pRtPdBga+drA== ------END CERTIFICATE----- diff --git a/file.key.pem b/file.key.pem deleted file mode 100644 index 8823dd9..0000000 --- a/file.key.pem +++ /dev/null @@ -1,31 +0,0 @@ -Bag Attributes - localKeyID: 7B F6 20 60 B1 C7 D4 BF 90 09 67 34 74 87 79 40 9E 80 A9 40 -Key Attributes: ------BEGIN PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDJg462JQziCclR -ADzo761vY2vZlXJ0ZB+g10e189Dh67GoCt1ReYE3buu55uvf/phaZmvllG0ku3Vd -OhUkCFP1HhAc+e5ZmYlFmIQ84NZBblKxFm51gtfRlvOWRJ4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N190YNUSemPpaByYBYi+U5ts6itvJiZ42C0/nQjdHLJpAofBAoGBALpc -Ehe/wBnYwvnG2Rr4Jm8FlC3Md7PSNTZZlrDiI4dutz7EpSMe/SaofMeUHAHUPp9m -N1Dssxgo/2zBrHclxsmj31Ih3QFCRGtsAuHQ7CBdSXSvgLKKnG3E1i6p4iLZcifR -6lVW1W1EN2zJMk/5t01DHx0p38619NXq41lL1mT9AoGADp4+opSuxJ789kUHht69 -KTqMnK3R80x2bwUbb1Y02C4H7Fd1A7hC6J0N6K7M3O8KocSEh9O2EdfR4FGeXkfO -ku4Tsn2XkMpHH8K8kkUmQRCpRTnS2E4gKIfDcM08FCwFkbige545qFrJW5uJAWTN -8ln2LlOaEbqo1yhg+LEI1cs= ------END PRIVATE KEY----- diff --git a/src/plugin/restway.cpp b/src/plugin/restway.cpp deleted file mode 100644 index fb6603f..0000000 --- a/src/plugin/restway.cpp +++ /dev/null @@ -1,297 +0,0 @@ -/* - ____ _____ ____ _____ - | _ \| ____/ ___|_ _|_ ____ _ _ _ - | |_) | _| \___ \ | | \ \ /\ / / _` | | | | - | _ <| |___ ___) || | \ V V / (_| | |_| | - |_| \_\_____|____/ |_| \_/\_/ \__,_|\__, | - |___/ -A RESTful Gateway -*/ - -#include "../source.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#ifndef PLUGIN_NAME -#define PLUGIN_NAME "RESTway" -#endif - -#define API_PATH "/amw4analysis/job" - -using namespace std; -using namespace RestClient; -using json = nlohmann::json; - -// Plugin class. This shall be the only part that needs to be modified, -// implementing the actual functionality -class RESTway : public Source { - -public: - ~RESTway() { - RestClient::disable(); - delete _conn; - } - -private: - void conn_accept_json() { - RestClient::HeaderFields headers; - headers["Accept"] = "application/json"; - _conn->SetHeaders(headers); - } - - void conn_accept_binary() { - RestClient::HeaderFields headers; - headers["Accept"] = "application/octet-stream"; - _conn->SetHeaders(headers); - } - - void setup() { - RestClient::init(); - _conn = new RestClient::Connection(_params["url"]); - _conn->SetTimeout(5); - _conn->SetUserAgent("mads/restway"); - - // enable following of redirects (default is off) - _conn->FollowRedirects(true); - // and limit the number of redirects (default is -1, unlimited) - _conn->FollowRedirects(true, 3); - - // set headers - conn_accept_json(); - - // Set TSL options and certificates - _conn->SetVerifyPeer(false); - _conn->SetVerifyHost(false); - _conn->SetCertPath("./file.crt.pem"); - _conn->SetCertType("PEM"); - _conn->SetKeyPath("./file.key.pem"); - - _initialized = true; - } - - string get_jobId(string jobName) { - json result; - string path = API_PATH; - cout << "=> GET: " << path << endl; - conn_accept_json(); - _response = _conn->get(path); - if (_response.code != 200) { - throw runtime_error("REST Error getting job list"); - } - result = json::parse(_response.body); - for (auto &r : result) { - if (r["name"] == jobName) { - return r["id"]; - } - } - throw runtime_error("Job not found"); - } - - string get_jobRunId(string jobId) { - json result; - string path = API_PATH; - path += jobId; - path += "/run/all"; - cout << "=> GET: " << path << endl; - conn_accept_json(); - _response = _conn->get(path); - if (_response.code != 200) { - throw runtime_error("REST Error getting jobRun list"); - } - result = json::parse(_response.body); - return result[0]["jobRunId"]; - } - - string get_fileName(string jobId, string jobRunId) { - json result; - string path = API_PATH; - path += jobId; - path += "/run/"; - path += jobRunId; - path += "/file/all"; - cout << "=> GET: " << path << endl; - conn_accept_json(); - _response = _conn->get(path); - if (_response.code != 200) { - throw runtime_error("REST Error getting zip files"); - } - result = json::parse(_response.body); - return result[0]["fileName"]; - } - - void save_fileContent(string jobId, string jobRunId, string fileName) { - string path = API_PATH; - path += jobId; - path += "/run/"; - path += jobRunId; - path += "/file?fileName="; - path += fileName; - cout << "=> GET: " << path << endl; - conn_accept_binary(); - _response = _conn->get(path); - if (_response.code != 200) { - throw runtime_error("REST Error getting file content"); - } - ofstream file(fileName, ios::out | ios::binary); - file.write(_response.body.c_str(), _response.body.size()); - file.close(); - } - - void delete_jobRun(string jobId, string jobRunId) { - string path = API_PATH; - path += jobId; - path += "/run/"; - path += jobRunId; - cout << "=> DELETE: " << path << endl; - _response = _conn->del(path); - if (_response.code != 200) { - throw runtime_error("REST Error deleting jobRun"); - } - return; - } - -public: - - string kind() override { return PLUGIN_NAME; } - - return_type get_output(json &out, std::vector *blob = nullptr) override { - return_type rc = return_type::success; - string path = API_PATH; - string jobId, jobRunId, fileName; - json result; - if (!_initialized) { - setup(); - } - - try { - jobId = get_jobId(_params["jobId"][0]); - jobRunId = get_jobRunId(jobId); - fileName = get_fileName(jobId, jobRunId); - save_fileContent(jobId, jobRunId, fileName); - delete_jobRun(jobId, jobRunId); - } catch (runtime_error &e) { - cerr << "Error: " << e.what() << endl; - rc = return_type::error; - goto exit; - } - - return rc; - - // path += "/description?jobId="; - // path += _params["jobId"][0]; - // _response = _conn->get(path); - // cout << "RESTway: code " << _response.code << ", " << _response.body << endl; - // (*out)["code"] = _response.code; - // try { - // result = json::parse(_response.body); - // } catch (json::parse_error &e) { - // cerr << "Error parsing REST body as JSON: " << e.what() << endl; - // cerr << "when trying to parse: \"" << _response.body << "\"" << endl; - // rc = return_type::error; - // goto exit; - // } - // cout << "*** " << result[0]["fileName"] << " " << result[0]["fileSize"] << " bytes" << endl; - - // path = API_PATH; - - // out->clear(); - // (*out)["url"] = _params["url"]; - // (*out)["path"] = path; - // (*out)["headers"] = _response.headers; - - // if (_response.code != 200) { - // this_thread::sleep_for(chrono::milliseconds(_params["delay"])); - // goto exit; - // } - -exit: - this_thread::sleep_for(chrono::milliseconds(_params["delay"])); - return rc; - } - - void set_params(void const *params) override { - _params["url"] = string("https://192.168.1.55:5444"); - _params["jobId"] = {"MADS"}; - _params["description"] = "RESTway, a RESTful gateway"; - _params["page"] = 0; - _params["size"] = 20; - _params["id"] = 0; - _params["delay"] = 1000; - _params.merge_patch(*(json *)params); - } - - map info() override { - map info; - info["url"] = _params["url"]; - info["description"] = _params["description"]; - return info; - }; - -private: - json _data, _params; - Response _response; - RestClient::Connection *_conn; - bool _initialized = false; -}; - -/* - ____ _ _ _ _ - | _ \| |_ _ __ _(_)_ __ __| |_ __(_)_ _____ _ __ - | |_) | | | | |/ _` | | '_ \ / _` | '__| \ \ / / _ \ '__| - | __/| | |_| | (_| | | | | | | (_| | | | |\ V / __/ | - |_| |_|\__,_|\__, |_|_| |_| \__,_|_| |_| \_/ \___|_| - |___/ -Enable the class as plugin -*/ -INSTALL_SOURCE_DRIVER(RESTway, json) - -/* - _ - _ __ ___ __ _(_)_ __ - | '_ ` _ \ / _` | | '_ \ - | | | | | | (_| | | | | | - |_| |_| |_|\__,_|_|_| |_| - -For testing purposes, when directly executing the plugin -*/ -int main(int argc, char const *argv[]) { - RESTway source; - json output; - json params; - if (argc == 1) { - params["url"] = "https://192.168.1.55:5444"; - params["jobId"] = {"MADS"}; - params["description"] = "RESTway, a RESTful gateway"; - params["page"] = 0; - params["size"] = 20; - } else { - ifstream file(argv[1]); - try { - params = json::parse(file); - } catch (json::parse_error &e) { - cerr << "Error parsing parameters: " << e.what() << endl; - return 1; - } - file.close(); - } - source.set_params(¶ms); - for (auto &p : source.info()) { - cout << "_params[" << p.first << "]: " << p.second << endl; - } - - // Process data - source.get_output(output); - - // Produce output - cout << "REST returns: " << output << endl; - - return 0; -}