Jenkins compile fix

This commit is contained in:
Emil Axelsson
2018-03-29 09:12:49 +02:00
parent 04ff9d119b
commit 246f583119
2 changed files with 15 additions and 17 deletions
+8 -10
View File
@@ -43,24 +43,22 @@ public:
bool isDone();
/* https://httpstatuses.com/ */
static const struct Statuses {
enum StatusCode {
OK = 200,
Accepted = 202,
enum class StatusCode : int {
OK = 200,
Accepted = 202,
BadRequest = 400,
Unauthorized = 401,
NotAcceptable = 406,
BadRequest = 400,
Unauthorized = 401,
NotAcceptable = 406,
NotImplemented = 501
};
NotImplemented = 501
};
private:
bool _isAuthenticated;
const std::string getKey() const;
bool authorize(const std::string key);
nlohmann::json message(const std::string &message, const int &statusCode = Statuses::NotImplemented);
nlohmann::json message(const std::string &message, StatusCode statusCode = StatusCode::NotImplemented);
};
}
@@ -40,21 +40,21 @@ bool AuthorizationTopic::isDone() {
void AuthorizationTopic::handleJson(nlohmann::json json) {
if (isDone()) {
_connection->sendJson(message("Already authorized.", Statuses::OK));
_connection->sendJson(message("Already authorized.", StatusCode::OK));
} else {
try {
auto providedKey = json.at("key").get<std::string>();
if (authorize(providedKey)) {
_connection->sendJson(message("Authorization OK.", Statuses::Accepted));
_connection->sendJson(message("Authorization OK.", StatusCode::Accepted));
_connection->setAuthorized(true);
LINFO("Client successfully authorized.");
} else {
_connection->sendJson(message("Invalid key", Statuses::NotAcceptable));
_connection->sendJson(message("Invalid key", StatusCode::NotAcceptable));
}
} catch (const std::out_of_range& e) {
_connection->sendJson(message("Invalid request, key must be provided.", Statuses::BadRequest));
_connection->sendJson(message("Invalid request, key must be provided.", StatusCode::BadRequest));
} catch (const std::domain_error& e) {
_connection->sendJson(message("Invalid request, invalid key format.", Statuses::BadRequest));
_connection->sendJson(message("Invalid request, invalid key format.", StatusCode::BadRequest));
}
}
};
@@ -75,8 +75,8 @@ const std::string AuthorizationTopic::getKey() const {
return "17308";
}
nlohmann::json AuthorizationTopic::message(const std::string &message, const int &statusCode) {
nlohmann::json error = {{"message", message}, {"code", statusCode}};
nlohmann::json AuthorizationTopic::message(const std::string &message, StatusCode statusCode) {
nlohmann::json error = {{"message", message}, {"code", static_cast<int>(statusCode)}};
return error;
}