-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
1,092 additions
and
514 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
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
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
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,67 @@ | ||
/* | ||
* 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 "czar/ChttpModule.h" | ||
|
||
// System headers | ||
#include <stdexcept> | ||
|
||
// Qserv headers | ||
#include "cconfig/CzarConfig.h" | ||
#include "http/Exceptions.h" | ||
#include "http/RequestBodyJSON.h" | ||
#include "http/RequestQuery.h" | ||
|
||
using namespace std; | ||
|
||
namespace lsst::qserv::czar { | ||
|
||
ChttpModule::ChttpModule(string const& context, httplib::Request const& req, httplib::Response& resp) | ||
: http::ChttpModule(cconfig::CzarConfig::instance()->replicationAuthKey(), | ||
cconfig::CzarConfig::instance()->replicationAdminAuthKey(), req, resp), | ||
_context(context) {} | ||
|
||
string ChttpModule::context() const { return _context; } | ||
|
||
void ChttpModule::enforceCzarName(string const& func) const { | ||
string const czarNameAttrName = "czar"; | ||
string czarName; | ||
if (method() == "GET") { | ||
if (!query().has(czarNameAttrName)) { | ||
throw http::Error(func, "No Czar identifier was provided in the request query."); | ||
} | ||
czarName = query().requiredString(czarNameAttrName); | ||
} else { | ||
if (!body().has(czarNameAttrName)) { | ||
throw http::Error(func, "No Czar identifier was provided in the request body."); | ||
} | ||
czarName = body().required<string>(czarNameAttrName); | ||
} | ||
string const expectedCzarName = cconfig::CzarConfig::instance()->name(); | ||
if (expectedCzarName != czarName) { | ||
string const msg = "Requested Czar identifier '" + czarName + "' does not match the one '" + | ||
expectedCzarName + "' of the current Czar."; | ||
throw http::Error(func, msg); | ||
} | ||
} | ||
|
||
} // namespace lsst::qserv::czar |
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,69 @@ | ||
/* | ||
* 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_CZAR_CHTTPMODULE_H | ||
#define LSST_QSERV_CZAR_CHTTPMODULE_H | ||
|
||
// System headers | ||
#include <string> | ||
|
||
// Qserv headers | ||
#include "http/ChttpModule.h" | ||
|
||
// Forward declarations | ||
namespace httplib { | ||
class Request; | ||
class Response; | ||
} // namespace httplib | ||
|
||
// This header declarations | ||
namespace lsst::qserv::czar { | ||
|
||
/** | ||
* Class ChttpModule is an intermediate base class of the Qserv Czar modules. | ||
*/ | ||
class ChttpModule : public http::ChttpModule { | ||
public: | ||
ChttpModule() = delete; | ||
ChttpModule(ChttpModule const&) = delete; | ||
ChttpModule& operator=(ChttpModule const&) = delete; | ||
|
||
virtual ~ChttpModule() = default; | ||
|
||
protected: | ||
ChttpModule(std::string const& context, httplib::Request const& req, httplib::Response& resp); | ||
|
||
virtual std::string context() const final; | ||
|
||
/** | ||
* Check if Czar identifier is present in a request and if so then the identifier | ||
* is the same as the one of the current Czar. Throw an exception in case of mismatch. | ||
* @param func The name of the calling context (it's used for error reporting). | ||
* @throws std::invalid_argument If the dentifiers didn't match. | ||
*/ | ||
void enforceCzarName(std::string const& func) const; | ||
|
||
private: | ||
std::string const _context; | ||
}; | ||
|
||
} // namespace lsst::qserv::czar | ||
|
||
#endif // LSST_QSERV_CZAR_CHTTPMODULE_H |
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
Oops, something went wrong.