bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
ProxyConfig.cc
1//
2// Created by ndp on 10/19/20.
3//
4#include "config.h"
5
6#include <string>
7#include <sstream>
8#include <vector>
9
10#include <curl/curl.h>
11
12#include "BESSyntaxUserError.h"
13#include "TheBESKeys.h"
14#include "BESUtil.h"
15#include "BESDebug.h"
16#include "HttpNames.h"
17#include "ProxyConfig.h"
18
19using std::string;
20using std::vector;
21using std::stringstream;
22using std::endl;
23
24#define prolog string("ProxyConfig::").append(__func__).append("() - ")
25namespace http {
26
27 ProxyConfig *ProxyConfig::d_instance = 0;
28
29 ProxyConfig *ProxyConfig::theOne() {
30 if (d_instance)
31 return d_instance;
32
33 d_instance = new ProxyConfig();
34 return d_instance;
35 }
36
37
41 void ProxyConfig::load_proxy_from_keys() {
42 bool found = false;
43 vector<string> vals;
44 string key;
45
46 found = false;
47 key = HTTP_PROXYHOST_KEY;
48 TheBESKeys::TheKeys()->get_value(key, d_host, found);
49 if (found && !d_host.empty()) {
50 // if the proxy host is set, then check to see if the port is
51 // set. Does not need to be.
52 found = false;
53 string port;
54 key = HTTP_PROXYPORT_KEY;
55 TheBESKeys::TheKeys()->get_value(key, port, found);
56 if (found && !port.empty()) {
57 d_port = atoi(port.c_str());
58 if (!d_port) {
59 stringstream err_msg;
60 err_msg << prolog << "The Httpd catalog proxy host is specified, but a specified port is absent";
61 throw BESSyntaxUserError(err_msg.str(), __FILE__, __LINE__);
62 }
63 }
64 // Everything else is optional, the minimum for a proxy is host and port, so:
65 d_configured = true;
66
67 // @TODO Either use this or remove it - right now this variable is never used downstream
68 // find the protocol to use for the proxy server. If none set, default to http
69 found = false;
70 TheBESKeys::TheKeys()->get_value(HTTP_PROXYPROTOCOL_KEY, d_protocol, found);
71 if (!found || d_protocol.empty()) {
72 d_protocol = "http";
73 }
74
75 // find the user to use for authenticating with the proxy server. If none set,
76 // default to ""
77 found = false;
78 key = HTTP_PROXYUSER_KEY;
79 TheBESKeys::TheKeys()->get_value(key, d_user_id, found);
80 if (!found) {
81 d_user_id = "";
82 }
83
84 // find the password to use for authenticating with the proxy server. If none set,
85 // default to ""
86 found = false;
87 key = HTTP_PROXYPASSWORD_KEY;
88 TheBESKeys::TheKeys()->get_value(key, d_proxy_password, found);
89 if (!found) {
90 d_proxy_password = "";
91 }
92
93 // find the user:password string to use for authenticating with the proxy server. If none set,
94 // default to ""
95 found = false;
96 key = HTTP_PROXYUSERPW_KEY;
97 TheBESKeys::TheKeys()->get_value(key, d_user_password, found);
98 if (!found) {
99 d_user_password = "";
100 }
101
102 // find the authentication mechanism to use with the proxy server. If none set,
103 // default to BASIC authentication.
104 found = false;
105 string authType;
106 key = HTTP_PROXYAUTHTYPE_KEY;
107 TheBESKeys::TheKeys()->get_value(key, authType, found);
108 if (found) {
109 authType = BESUtil::lowercase(authType);
110 if (authType == "basic") {
111 d_auth_type = CURLAUTH_BASIC;
112 BESDEBUG(HTTP_MODULE, prolog << "ProxyAuthType BASIC set." << endl);
113 } else if (authType == "digest") {
114 d_auth_type = CURLAUTH_DIGEST;
115 BESDEBUG(HTTP_MODULE, prolog << "ProxyAuthType DIGEST set." << endl);
116 } else if (authType == "ntlm") {
117 d_auth_type = CURLAUTH_NTLM;
118 BESDEBUG(HTTP_MODULE, prolog << "ProxyAuthType NTLM set." << endl);
119 } else {
120 d_auth_type = CURLAUTH_BASIC;
121 BESDEBUG(HTTP_MODULE,
122 prolog << "User supplied an invalid value '" << authType
123 << "' for Gateway.ProxyAuthType. Falling back to BASIC authentication scheme."
124 << endl);
125 }
126 } else {
127 d_auth_type = CURLAUTH_BASIC;
128 }
129 }
130
131 // Grab the value for the NoProxy regex; empty if there is none.
132 found = false; // Not used
133 key = HTTP_NO_PROXY_REGEX_KEY;
134 TheBESKeys::TheKeys()->get_value(key, d_no_proxy_regex, found);
135 if (!found) {
136 d_no_proxy_regex = "";
137 }
138
139 }
140
141} // namespace http
static std::string lowercase(const std::string &s)
Definition BESUtil.cc:257
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85
utility class for the HTTP catalog module
Definition TheBESKeys.h:51