userver: userver/server/auth/user_env.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
user_env.hpp
1#pragma once
2
3#include <stdexcept>
4#include <string>
5
6#include <userver/formats/parse/to.hpp>
7#include <userver/utils/assert.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace server::handlers::auth {
12class AuthCheckerBase;
13}
14
15namespace server::auth {
16
17/// @brief Authorization environments for users
18enum class UserEnv : int {
19 kProd,
20 kTest,
21 kProdYateam,
22 kTestYateam,
23 kStress,
24};
25
26template <class Value>
27UserEnv Parse(const Value& v, formats::parse::To<UserEnv>) {
28 const std::string env_name = v.template As<std::string>();
29 if (env_name == "Prod" || env_name == "Mimino") {
30 return UserEnv::kProd;
31 } else if (env_name == "Test") {
32 return UserEnv::kTest;
33 } else if (env_name == "ProdYateam") {
34 return UserEnv::kProdYateam;
35 } else if (env_name == "TestYateam") {
36 return UserEnv::kTestYateam;
37 } else if (env_name == "Stress") {
38 return UserEnv::kStress;
39 }
40
41 UASSERT_MSG(false, "Unknown user env");
42 throw std::runtime_error("Unknown user env " + env_name);
43}
44
45std::string ToString(UserEnv env);
46
47} // namespace server::auth
48
49USERVER_NAMESPACE_END