bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
ServerAdministrator.cc
1
2// ServerAdministrator.cc
3// -*- mode: c++; c-basic-offset:4 -*-
4//
5//
6// This file is part of BES httpd_catalog_module
7//
8// Copyright (c) 2018 OPeNDAP, Inc.
9// Author: Nathan Potter <ndp@opendap.org>
10//
11// This library is free software; you can redistribute it and/or
12// modify it under the terms of the GNU Lesser General Public
13// License as published by the Free Software Foundation; either
14// version 2.1 of the License, or (at your option) any later version.
15//
16// This library is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19// Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public
22// License along with this library; if not, write to the Free Software
23// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24//
25// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26// Please read the full copyright statement in the file COPYRIGHT_URI.
27//
28#include "config.h"
29
30#include <vector>
31#include <map>
32#include <sstream>
33
34#include "TheBESKeys.h"
35#include "BESDebug.h"
36#include "BESUtil.h"
37#include "BESLog.h"
38#include "BESInternalFatalError.h"
39
40#include "ServerAdministrator.h"
41
42using std::vector;
43using std::endl;
44using std::string;
45using std::ostream;
46
47#define MODULE "bes"
48
49#define prolog std::string("ServerAdministrator::").append(__func__).append("() - ")
50
51
63
64#define EMAIL_KEY "email"
65#define EMAIL_DEFAULT "support@opendap.org"
66
67#define ORGANIZATION_KEY "organization"
68#define ORGANIZATION_DEFAULT "OPeNDAP Inc."
69
70#define STREET_KEY "street"
71#define STREET_DEFAULT "165 NW Dean Knauss Dr."
72
73#define CITY_KEY "city"
74#define CITY_DEFAULT "Narragansett"
75
76#define REGION_KEY "region"
77#define STATE_KEY "state"
78#define REGION_DEFAULT "RI"
79
80#define POSTAL_CODE_KEY "postalCode"
81#define POSTAL_CODE_DEFAULT "02882"
82
83#define COUNTRY_KEY "country"
84#define COUNTRY_DEFAULT "US"
85
86#define TELEPHONE_KEY "telephone"
87#define TELEPHONE_DEFAULT "+1.401.575.4835"
88
89#define WEBSITE_KEY "website"
90#define WEBSITE_DEFAULT "http://www.opendap.org"
91
92
93namespace bes {
94
100 bool found = false;
101
102
103 TheBESKeys::TheKeys()->get_values(SERVER_ADMINISTRATOR_KEY,d_admin_info, true, found);
104
105
106 bool bad_flag = false;
107
108 d_organization = get(ORGANIZATION_KEY);
109 if(d_organization.empty()){
110 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
111 SERVER_ADMINISTRATOR_KEY << "[" << ORGANIZATION_KEY << "] was missing." << endl);
112 bad_flag = true;
113 }
114
115 d_street = get(STREET_KEY);
116 if(d_street.empty()){
117 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
118 SERVER_ADMINISTRATOR_KEY << "[" << STREET_KEY << "] was missing." << endl);
119 bad_flag = true;
120 }
121
122 d_city = get(CITY_KEY);
123 if(d_city.empty()){
124 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
125 SERVER_ADMINISTRATOR_KEY << "[" << CITY_KEY << "] was missing." << endl);
126 bad_flag = true;
127 }
128
129 d_region = get(REGION_KEY);
130 if(d_region.empty()){
131 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
132 SERVER_ADMINISTRATOR_KEY << "[" << REGION_KEY << "] was missing." << endl);
133 d_region = get(STATE_KEY);
134
135 if(d_region.empty()){
136 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
137 SERVER_ADMINISTRATOR_KEY << "[" << STATE_KEY << "] was missing." << endl);
138 bad_flag = true;
139 }
140 }
141
142 d_postal_code = get(POSTAL_CODE_KEY);
143 if(d_postal_code.empty()){
144 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
145 SERVER_ADMINISTRATOR_KEY << "[" << POSTAL_CODE_KEY << "] was missing." << endl);
146 bad_flag = true;
147 }
148
149 d_country = get(COUNTRY_KEY);
150 if(d_country.empty()){
151 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
152 SERVER_ADMINISTRATOR_KEY << "[" << COUNTRY_KEY << "] was missing." << endl);
153 bad_flag = true;
154 }
155
156 d_telephone = get(TELEPHONE_KEY);
157 if(d_telephone.empty()){
158 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
159 SERVER_ADMINISTRATOR_KEY << "[" << TELEPHONE_KEY << "] was missing." << endl);
160 bad_flag = true;
161 }
162
163 d_email = get(EMAIL_KEY);
164 if(d_email.empty()){
165 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
166 SERVER_ADMINISTRATOR_KEY << "[" << EMAIL_KEY << "] was missing." << endl);
167 bad_flag = true;
168 }
169
170 d_website = get(WEBSITE_KEY);
171 if(d_website.empty()){
172 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " <<
173 SERVER_ADMINISTRATOR_KEY << "[" << WEBSITE_KEY << "] was missing." << endl);
174 bad_flag = true;
175 }
176
177 // %TODO This is a pretty simple (and brutal) qc in that any missing value prompts all of it to be rejected. Review. Fix?
178 if(bad_flag ){
179 mk_default();
180 BESDEBUG(MODULE,__func__ << "() - The configuration entry for the " << SERVER_ADMINISTRATOR_KEY << " was missing crucial information. jdump(): " << jdump(true) << endl);
181 }
182}
183
184
185
186std::string ServerAdministrator::get(const string &key){
187 string lkey = BESUtil::lowercase(key);
188 auto result = d_admin_info.find(lkey);
189 if(result == d_admin_info.end()){
190 return "";
191 }
192 return result->second;
193}
194
195
196
197
198
199std::string ServerAdministrator::xdump() const {
200 std::stringstream ss;
201 ss << R"(<ServerAdministrator )";
202 ss << R"(organization=")" << d_organization << R"(" )";
203 ss << R"(street=")" << d_street << R"(" )";
204 ss << R"(city=")" << d_city << R"(" )";
205 ss << R"(region=")" << d_region << R"(" )";
206 ss << R"(country=")" << d_country << R"(" )";
207 ss << R"(postalcode=")" << d_postal_code << R"(" )";
208 ss << R"(telephone=")" << d_telephone << R"(" )";
209 ss << R"(email=")" << d_email << R"(" )";
210 ss << R"(website=")" << d_website << R"(" )";
211 ss << "/>";
212 return ss.str();
213}
214
215std::string ServerAdministrator::jdump(bool compact) const {
216 std::stringstream ss;
217 ss << "{";
218 if(!compact)
219 ss<< endl << " ";
220 ss << R"("ServerAdministrator":)";
221 if(!compact)
222 ss << " ";
223 ss << "{";
224 if(!compact) ss << " ";
225 if(!compact) ss << " ";
226
227 if(!compact){ ss << endl << " "; }
228 ss << R"("organization": ")" << d_organization << R"(", )";
229 if(!compact){ ss << endl << " "; }
230 ss << R"("street": ")" << d_street << R"(", )";
231 if(!compact){ ss << endl << " "; }
232 ss << R"("city": ")" << d_city << R"(", )";
233 if(!compact){ ss << endl << " "; }
234 ss << R"("region": ")" << d_region << R"(", )";
235 if(!compact){ ss << endl << " "; }
236 ss << R"("country": ")" << d_country << R"(", )";
237 if(!compact){ ss << endl << " "; }
238 ss << R"("postalcode": ")" << d_postal_code << R"(", )";
239 if(!compact){ ss << endl << " "; }
240 ss << R"("telephone": ")" << d_telephone << R"(", )";
241 if(!compact){ ss << endl << " "; }
242 ss << R"("email": ")" << d_email << R"(", )";
243 if(!compact){ ss << endl << " "; }
244 ss << R"("website": ")" << d_website << R"(" )";
245 if(!compact){ ss << endl << " "; }
246 ss << "}";
247 if(!compact)
248 ss << endl;
249 ss << "}";
250 if(!compact)
251 ss << endl;
252 return ss.str();
253}
254
255
256void ServerAdministrator::mk_default() {
257 this->d_admin_info.clear();
258 d_admin_info.insert( std::pair<string,string>(EMAIL_KEY,EMAIL_DEFAULT));
259 d_admin_info.insert( std::pair<string,string>(ORGANIZATION_KEY,ORGANIZATION_DEFAULT));
260 d_admin_info.insert( std::pair<string,string>(STREET_KEY,STREET_DEFAULT));
261 d_admin_info.insert( std::pair<string,string>(CITY_KEY,CITY_DEFAULT));
262 d_admin_info.insert( std::pair<string,string>(REGION_KEY,REGION_DEFAULT));
263 d_admin_info.insert( std::pair<string,string>(POSTAL_CODE_KEY,POSTAL_CODE_DEFAULT));
264 d_admin_info.insert( std::pair<string,string>(COUNTRY_KEY,COUNTRY_DEFAULT));
265 d_admin_info.insert( std::pair<string,string>(TELEPHONE_KEY,TELEPHONE_DEFAULT));
266 d_admin_info.insert( std::pair<string,string>(WEBSITE_KEY,WEBSITE_DEFAULT));
267 BESDEBUG(MODULE,__func__ << "() - ServerAdministrator values have been set to the defaults: " << jdump(true) << endl);
268}
269
270
271
272
273
274} // namespace bes
static std::string lowercase(const std::string &s)
Definition BESUtil.cc:257
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85
void get_values(const std::string &s, std::vector< std::string > &vals, bool &found)
Retrieve the values of a given key, if set.