bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
TheBESKeys.h
1// TheBESKeys.h
2
3// This file is part of bes, A C++ back-end server implementation framework
4// for the OPeNDAP Data Access Protocol.
5
6// Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact University Corporation for Atmospheric Research at
24// 3080 Center Green Drive, Boulder, CO 80301
25
26// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27// Please read the full copyright statement in the file COPYRIGHT_UCAR.
28//
29// Authors:
30// pwest Patrick West <pwest@ucar.edu>
31// jgarcia Jose Garcia <jgarcia@ucar.edu>
32
33#ifndef TheBESKeys_h_
34#define TheBESKeys_h_ 1
35
36#include <fstream>
37#include <unordered_map>
38#include <set>
39#include <vector>
40#include <string>
41#include <memory>
42
43#include "BESObj.h"
44
45constexpr auto DYNAMIC_CONFIG_KEY = "DynamicConfig";
46constexpr auto DC_REGEX_KEY = "regex";
47constexpr auto DC_CONFIG_KEY = "config";
48
49#define DYNAMIC_CONFIG_ENABLED 0
50
51namespace http {
52class HttpCacheTest;
53}
54
91class TheBESKeys: public BESObj {
92
93 friend class keysT;
94 friend class http::HttpCacheTest;
95
96 std::string d_keys_file_name;
97
98 std::unordered_map< std::string, std::vector<std::string> > d_the_keys;
99
100#if DYNAMIC_CONFIG_ENABLED
101 std::unique_ptr<keys_kvp> d_the_original_keys{new keys_kvp()};
102#endif
103
104 bool d_dynamic_config_in_use = false;
105 bool d_own_keys = false;
106
107 std::set<std::string> d_ingested_key_files;
108
109 // Only called by the static TheBESKeys::TheKeys() method.
110 explicit TheBESKeys(std::string keys_file_name);
111
112public:
117 static std::string ConfigFile;
118
119 TheBESKeys() = delete;
120 TheBESKeys(const TheBESKeys &) = delete;
121 TheBESKeys(TheBESKeys &&) = delete;
122 TheBESKeys &operator=(const TheBESKeys &) = delete;
123 TheBESKeys &operator=(TheBESKeys &&) = delete;
124 ~TheBESKeys() override = default;
125
127 static TheBESKeys *TheKeys();
128
129 std::string keys_file_name() const {
130 return d_keys_file_name;
131 }
132
133 void reload_keys();
134 void reload_keys(const std::string &keys_file_name);
135
141 void delete_key(const std::string &key) {
142 d_the_keys.erase(key);
143 }
144
145 void set_key(const std::string &key, const std::string &val, bool addto = false);
146
147 void set_key(const std::string &pair);
148
149 void set_keys(const std::string &key, const std::vector<std::string> &values, bool addto);
150
151 void set_keys(const std::string &key, const std::unordered_map<std::string, std::string> &values,
152 bool case_insensitive_map_keys, bool addto);
153
154 void get_value(const std::string &s, std::string &val, bool &found);
155
156 // get values for a vector-valued key
157 void get_values(const std::string &s, std::vector<std::string> &vals, bool &found);
158
159 // get value for a map-valued key
160 void get_values(const std::string &, std::unordered_map<std::string, std::string> &map_values,
161 bool case_insensitive_map_keys, bool &found);
162
163 void get_values(const std::string &, std::unordered_map<std::string,
164 std::unordered_map<std::string, std::vector<std::string> > > &map,
165 bool case_insensitive_map_keys, bool &found);
166
167 static bool read_bool_key(const std::string &key, bool default_value);
168
169 static std::string read_string_key(const std::string &key, const std::string &default_value);
170
171 static int read_int_key(const std::string &key, int default_value);
172
173 static unsigned long read_ulong_key(const std::string &key, unsigned long default_value);
174
175 static uint64_t read_uint64_key(const std::string &key, uint64_t default_value);
176
177 std::unordered_map<std::string, std::vector<std::string> >::const_iterator keys_begin() {
178 return d_the_keys.begin();
179 }
180
181 std::unordered_map<std::string, std::vector<std::string> >::const_iterator keys_end() {
182 return d_the_keys.end();
183 }
184
185 std::string get_as_config() const;
186
187 void load_dynamic_config(const std::string &name);
188
189 bool using_dynamic_config() const {
190 return d_dynamic_config_in_use;
191 }
192
193 void dump(std::ostream &strm) const override;
194 virtual std::string dump() const;
195};
196
197#endif // TheBESKeys_h_
198
top level BES object to house generic methods
Definition BESObj.h:54
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
std::string get_as_config() const
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85
void set_key(const std::string &key, const std::string &val, bool addto=false)
allows the user to set key/value pairs from within the application.
static int read_int_key(const std::string &key, int default_value)
Read an integer-valued key from the bes.conf file.
void get_values(const std::string &s, std::vector< std::string > &vals, bool &found)
Retrieve the values of a given key, if set.
virtual std::string dump() const
dumps information about this object
static std::string ConfigFile
Definition TheBESKeys.h:117
void delete_key(const std::string &key)
Delete the key Added primarily for testing purposes.
Definition TheBESKeys.h:141
static bool read_bool_key(const std::string &key, bool default_value)
Read a boolean-valued key from the bes.conf file.
static std::string read_string_key(const std::string &key, const std::string &default_value)
Read a string-valued key from the bes.conf file.
static unsigned long read_ulong_key(const std::string &key, unsigned long default_value)
Read an integer-valued key from the bes.conf file.
void reload_keys()
Reload the keys. Erase the existing keys and reload them from the file. This uses the name of the key...
void set_keys(const std::string &key, const std::vector< std::string > &values, bool addto)
allows the user to set key/value pairs from within the application.
static uint64_t read_uint64_key(const std::string &key, uint64_t default_value)
Read an integer-valued key from the bes.conf file.
void load_dynamic_config(const std::string &name)
Loads the the applicable dynamic configuration or nothing if no configuration is applicable.
STL class.
STL class.
utility class for the HTTP catalog module
Definition TheBESKeys.h:51