-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CPP-HTTPLIB-based verson of the meta module
- Loading branch information
1 parent
45a19e4
commit df34e62
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* LSST Data Management System | ||
* | ||
* This product includes software developed by the | ||
* LSST Project (http://www.lsst.org/). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the LSST License Statement and | ||
* the GNU General Public License along with this program. If not, | ||
* see <http://www.lsstcorp.org/LegalNotices/>. | ||
*/ | ||
|
||
// Class header | ||
#include "http/ChttpMetaModule.h" | ||
|
||
// System headers | ||
#include <stdexcept> | ||
|
||
using namespace std; | ||
using json = nlohmann::json; | ||
|
||
namespace { | ||
// Authorization context is not required by this module | ||
lsst::qserv::http::AuthType const authType = lsst::qserv::http::AuthType::NONE; | ||
string const authKey; | ||
string const adminAuthKey; | ||
} // namespace | ||
|
||
namespace lsst::qserv::http { | ||
|
||
unsigned int const ChttpMetaModule::version = 35; | ||
|
||
void ChttpMetaModule::process(string const& context, nlohmann::json const& info, httplib::Request const& req, | ||
httplib::Response& resp, string const& subModuleName) { | ||
ChttpMetaModule module(context, info, req, resp); | ||
module.execute(subModuleName, ::authType); | ||
} | ||
|
||
ChttpMetaModule::ChttpMetaModule(string const& context, nlohmann::json const& info, | ||
httplib::Request const& req, httplib::Response& resp) | ||
: http::ChttpModule(::authKey, ::adminAuthKey, req, resp), _context(context), _info(info) { | ||
if (!_info.is_object()) { | ||
throw invalid_argument("ChttpMetaModule::" + string(__func__) + " parameter info must be an object."); | ||
} | ||
} | ||
|
||
json ChttpMetaModule::executeImpl(string const& subModuleName) { | ||
if (subModuleName == "VERSION") return _version(); | ||
throw invalid_argument(context() + "::" + string(__func__) + " unsupported sub-module: '" + | ||
subModuleName + "'"); | ||
} | ||
|
||
string ChttpMetaModule::context() const { return _context; } | ||
|
||
json ChttpMetaModule::_version() { | ||
debug(__func__); | ||
json result = _info; | ||
result["version"] = ChttpMetaModule::version; | ||
return result; | ||
} | ||
|
||
} // namespace lsst::qserv::http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* LSST Data Management System | ||
* | ||
* This product includes software developed by the | ||
* LSST Project (http://www.lsst.org/). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the LSST License Statement and | ||
* the GNU General Public License along with this program. If not, | ||
* see <http://www.lsstcorp.org/LegalNotices/>. | ||
*/ | ||
#ifndef LSST_QSERV_HTTP_CHTTPMETAMODULE_H | ||
#define LSST_QSERV_HTTP_CHTTPMETAMODULE_H | ||
|
||
// System headers | ||
#include <memory> | ||
#include <string> | ||
|
||
// Third party headers | ||
#include "nlohmann/json.hpp" | ||
|
||
// Qserv headers | ||
#include "http/ChttpModule.h" | ||
|
||
// This header declarations | ||
namespace lsst::qserv::http { | ||
|
||
/** | ||
* Class ChttpMetaModule implements a handler for the metadata queries on the REST API itself. | ||
* The service responds with an information object provided at the creation time of the module. | ||
*/ | ||
class ChttpMetaModule : public http::ChttpModule { | ||
public: | ||
typedef std::shared_ptr<ChttpMetaModule> Ptr; | ||
|
||
/// The current version of the REST API | ||
static unsigned int const version; | ||
|
||
/** | ||
* @note supported values for parameter 'subModuleName' are: | ||
* 'VERSION' - return a version of the REST API | ||
* | ||
* @param info The information object to be returned to clients of the service. | ||
* @throws std::invalid_argument for unknown values of parameter 'subModuleName' | ||
*/ | ||
static void process(std::string const& context, nlohmann::json const& info, httplib::Request const& req, | ||
httplib::Response& resp, std::string const& subModuleName); | ||
|
||
ChttpMetaModule() = delete; | ||
ChttpMetaModule(ChttpMetaModule const&) = delete; | ||
ChttpMetaModule& operator=(ChttpMetaModule const&) = delete; | ||
|
||
~ChttpMetaModule() final = default; | ||
|
||
protected: | ||
virtual nlohmann::json executeImpl(std::string const& subModuleName) final; | ||
virtual std::string context() const final; | ||
|
||
private: | ||
ChttpMetaModule(std::string const& context, nlohmann::json const& info, httplib::Request const& req, | ||
httplib::Response& resp); | ||
|
||
nlohmann::json _version(); | ||
|
||
std::string const _context; | ||
nlohmann::json const _info; | ||
}; | ||
|
||
} // namespace lsst::qserv::http | ||
|
||
#endif // LSST_QSERV_HTTP_CHTTPMETAMODULE_H |