2020-05-28 11:07:32 +00:00
|
|
|
#include "auth.hpp"
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace llarp::service
|
|
|
|
{
|
|
|
|
/// maybe get auth result from string
|
|
|
|
std::optional<AuthResult>
|
|
|
|
ParseAuthResult(std::string data)
|
|
|
|
{
|
2020-06-30 16:02:29 +00:00
|
|
|
static std::unordered_map<std::string, AuthResult> values = {
|
2020-05-28 11:07:32 +00:00
|
|
|
{"OKAY", AuthResult::eAuthAccepted},
|
|
|
|
{"REJECT", AuthResult::eAuthRejected},
|
|
|
|
{"PAYME", AuthResult::eAuthPaymentRequired},
|
|
|
|
{"LIMITED", AuthResult::eAuthRateLimit}};
|
|
|
|
auto itr = values.find(data);
|
|
|
|
if (itr == values.end())
|
|
|
|
return std::nullopt;
|
|
|
|
return itr->second;
|
|
|
|
}
|
2020-06-30 16:02:29 +00:00
|
|
|
|
|
|
|
AuthType
|
|
|
|
ParseAuthType(std::string data)
|
|
|
|
{
|
|
|
|
static std::unordered_map<std::string, AuthType> values = {
|
|
|
|
{"lmq", AuthType::eAuthTypeLMQ},
|
|
|
|
{"whitelist", AuthType::eAuthTypeWhitelist},
|
|
|
|
{"none", AuthType::eAuthTypeNone}};
|
|
|
|
const auto itr = values.find(data);
|
|
|
|
if (itr == values.end())
|
|
|
|
throw std::invalid_argument("no such auth type: " + data);
|
|
|
|
return itr->second;
|
|
|
|
}
|
2020-05-28 11:07:32 +00:00
|
|
|
} // namespace llarp::service
|