55#include < unordered_map>
66#include < vector>
77
8+ // current only support basic auth
9+ enum class ProxyAuthMethod {
10+ Basic,
11+ Digest,
12+ DigestIe,
13+ Bearer,
14+ Negotiate,
15+ Ntlm,
16+ NtlmWb,
17+ Any,
18+ AnySafe,
19+ AuthOnly,
20+ AwsSigV4
21+ };
22+
23+ struct ApiConfigurationMetadata {
24+ std::string name;
25+ std::string desc;
26+ std::string group;
27+ std::string accept_value;
28+ std::string default_value;
29+
30+ bool allow_empty = false ;
31+ };
32+
33+ static const std::unordered_map<std::string, ApiConfigurationMetadata>
34+ CONFIGURATIONS = {
35+ {" cors" ,
36+ ApiConfigurationMetadata{
37+ .name = " cors" ,
38+ .desc = " Cross-Origin Resource Sharing configuration." ,
39+ .group = " CORS" ,
40+ .accept_value = " [on|off]" ,
41+ .default_value = " on" }},
42+ {" allowed_origins" ,
43+ ApiConfigurationMetadata{
44+ .name = " allowed_origins" ,
45+ .desc = " Allowed origins for CORS. Comma separated. E.g. "
46+ " http://localhost,https://cortex.so" ,
47+ .group = " CORS" ,
48+ .accept_value = " comma separated" ,
49+ .default_value = " *" ,
50+ .allow_empty = true }},
51+ {" proxy_url" , ApiConfigurationMetadata{.name = " proxy_url" ,
52+ .desc = " Proxy URL" ,
53+ .group = " Proxy" ,
54+ .accept_value = " string" ,
55+ .default_value = " " }},
56+ {" proxy_username" , ApiConfigurationMetadata{.name = " proxy_username" ,
57+ .desc = " Proxy Username" ,
58+ .group = " Proxy" ,
59+ .accept_value = " string" ,
60+ .default_value = " " }},
61+ {" proxy_password" , ApiConfigurationMetadata{.name = " proxy_password" ,
62+ .desc = " Proxy Password" ,
63+ .group = " Proxy" ,
64+ .accept_value = " string" ,
65+ .default_value = " " }},
66+ {" verify_proxy_ssl" ,
67+ ApiConfigurationMetadata{.name = " verify_proxy_ssl" ,
68+ .desc = " Verify SSL for proxy" ,
69+ .group = " Proxy" ,
70+ .accept_value = " [on|off]" ,
71+ .default_value = " on" }},
72+ {" verify_proxy_host_ssl" ,
73+ ApiConfigurationMetadata{.name = " verify_proxy_host_ssl" ,
74+ .desc = " Verify SSL for proxy" ,
75+ .group = " Proxy" ,
76+ .accept_value = " [on|off]" ,
77+ .default_value = " on" }},
78+ {" no_proxy" , ApiConfigurationMetadata{.name = " no_proxy" ,
79+ .desc = " No proxy for hosts" ,
80+ .group = " Proxy" ,
81+ .accept_value = " string" ,
82+ .default_value = " " }},
83+ {" verify_peer_ssl" , ApiConfigurationMetadata{.name = " verify_peer_ssl" ,
84+ .desc = " Verify peer SSL" ,
85+ .group = " Proxy" ,
86+ .accept_value = " [on|off]" ,
87+ .default_value = " on" }},
88+ {" verify_host_ssl" , ApiConfigurationMetadata{.name = " verify_host_ssl" ,
89+ .desc = " Verify host SSL" ,
90+ .group = " Proxy" ,
91+ .accept_value = " [on|off]" ,
92+ .default_value = " on" }},
93+ };
94+
895class ApiServerConfiguration {
996 public:
10- ApiServerConfiguration (bool cors = true ,
11- std::vector<std::string> allowed_origins = {})
12- : cors{cors}, allowed_origins{allowed_origins} {}
97+ ApiServerConfiguration (
98+ bool cors = true , std::vector<std::string> allowed_origins = {},
99+ bool verify_proxy_ssl = true , bool verify_proxy_host_ssl = true ,
100+ const std::string& proxy_url = " " , const std::string& proxy_username = " " ,
101+ const std::string& proxy_password = " " , const std::string& no_proxy = " " ,
102+ bool verify_peer_ssl = true , bool verify_host_ssl = true )
103+ : cors{cors},
104+ allowed_origins{allowed_origins},
105+ verify_proxy_ssl{verify_proxy_ssl},
106+ verify_proxy_host_ssl{verify_proxy_host_ssl},
107+ proxy_url{proxy_url},
108+ proxy_username{proxy_username},
109+ proxy_password{proxy_password},
110+ no_proxy{no_proxy},
111+ verify_peer_ssl{verify_peer_ssl},
112+ verify_host_ssl{verify_host_ssl} {}
13113
114+ // cors
14115 bool cors{true };
15116 std::vector<std::string> allowed_origins;
16117
118+ // proxy
119+ bool verify_proxy_ssl{true };
120+ bool verify_proxy_host_ssl{true };
121+ ProxyAuthMethod proxy_auth_method{ProxyAuthMethod::Basic};
122+ std::string proxy_url{" " };
123+ std::string proxy_username{" " };
124+ std::string proxy_password{" " };
125+ std::string no_proxy{" " };
126+
127+ bool verify_peer_ssl{true };
128+ bool verify_host_ssl{true };
129+
17130 Json::Value ToJson () const {
18131 Json::Value root;
19132 root[" cors" ] = cors;
20133 root[" allowed_origins" ] = Json::Value (Json::arrayValue);
21134 for (const auto & origin : allowed_origins) {
22135 root[" allowed_origins" ].append (origin);
23136 }
137+ root[" verify_proxy_ssl" ] = verify_proxy_ssl;
138+ root[" verify_proxy_host_ssl" ] = verify_proxy_host_ssl;
139+ root[" proxy_url" ] = proxy_url;
140+ root[" proxy_username" ] = proxy_username;
141+ root[" proxy_password" ] = proxy_password;
142+ root[" no_proxy" ] = no_proxy;
143+ root[" verify_peer_ssl" ] = verify_peer_ssl;
144+ root[" verify_host_ssl" ] = verify_host_ssl;
145+
24146 return root;
25147 }
26148
@@ -31,6 +153,78 @@ class ApiServerConfiguration {
31153 const std::unordered_map<std::string,
32154 std::function<bool (const Json::Value&)>>
33155 field_updater{
156+ {" verify_peer_ssl" ,
157+ [this ](const Json::Value& value) -> bool {
158+ if (!value.isBool ()) {
159+ return false ;
160+ }
161+ verify_peer_ssl = value.asBool ();
162+ return true ;
163+ }},
164+
165+ {" verify_host_ssl" ,
166+ [this ](const Json::Value& value) -> bool {
167+ if (!value.isBool ()) {
168+ return false ;
169+ }
170+ verify_host_ssl = value.asBool ();
171+ return true ;
172+ }},
173+
174+ {" verify_proxy_host_ssl" ,
175+ [this ](const Json::Value& value) -> bool {
176+ if (!value.isBool ()) {
177+ return false ;
178+ }
179+ verify_proxy_host_ssl = value.asBool ();
180+ return true ;
181+ }},
182+
183+ {" verify_proxy_ssl" ,
184+ [this ](const Json::Value& value) -> bool {
185+ if (!value.isBool ()) {
186+ return false ;
187+ }
188+ verify_proxy_ssl = value.asBool ();
189+ return true ;
190+ }},
191+
192+ {" no_proxy" ,
193+ [this ](const Json::Value& value) -> bool {
194+ if (!value.isString ()) {
195+ return false ;
196+ }
197+ no_proxy = value.asString ();
198+ return true ;
199+ }},
200+
201+ {" proxy_url" ,
202+ [this ](const Json::Value& value) -> bool {
203+ if (!value.isString ()) {
204+ return false ;
205+ }
206+ proxy_url = value.asString ();
207+ return true ;
208+ }},
209+
210+ {" proxy_username" ,
211+ [this ](const Json::Value& value) -> bool {
212+ if (!value.isString ()) {
213+ return false ;
214+ }
215+ proxy_username = value.asString ();
216+ return true ;
217+ }},
218+
219+ {" proxy_password" ,
220+ [this ](const Json::Value& value) -> bool {
221+ if (!value.isString ()) {
222+ return false ;
223+ }
224+ proxy_password = value.asString ();
225+ return true ;
226+ }},
227+
34228 {" cors" ,
35229 [this ](const Json::Value& value) -> bool {
36230 if (!value.isBool ()) {
0 commit comments