34#define TheBESKeys_h_ 1
37#include <unordered_map>
45constexpr auto DYNAMIC_CONFIG_KEY =
"DynamicConfig";
46constexpr auto DC_REGEX_KEY =
"regex";
47constexpr auto DC_CONFIG_KEY =
"config";
49#define DYNAMIC_CONFIG_ENABLED 0
94 friend class http::HttpCacheTest;
96 std::string d_keys_file_name;
98 std::unordered_map< std::string, std::vector<std::string> > d_the_keys;
100#if DYNAMIC_CONFIG_ENABLED
101 std::unique_ptr<keys_kvp> d_the_original_keys{
new keys_kvp()};
104 bool d_dynamic_config_in_use =
false;
105 bool d_own_keys =
false;
107 std::set<std::string> d_ingested_key_files;
110 explicit TheBESKeys(std::string keys_file_name);
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;
129 std::string keys_file_name()
const {
130 return d_keys_file_name;
134 void reload_keys(
const std::string &keys_file_name);
142 d_the_keys.erase(key);
145 void set_key(
const std::string &key,
const std::string &val,
bool addto =
false);
149 void set_keys(
const std::string &key,
const std::vector<std::string> &values,
bool addto);
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);
154 void get_value(
const std::string &s, std::string &val,
bool &found);
157 void get_values(
const std::string &s, std::vector<std::string> &vals,
bool &found);
160 void get_values(
const std::string &, std::unordered_map<std::string, std::string> &map_values,
161 bool case_insensitive_map_keys,
bool &found);
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);
167 static bool read_bool_key(
const std::string &key,
bool default_value);
169 static std::string
read_string_key(
const std::string &key,
const std::string &default_value);
171 static int read_int_key(
const std::string &key,
int default_value);
173 static unsigned long read_ulong_key(
const std::string &key,
unsigned long default_value);
175 static uint64_t
read_uint64_key(
const std::string &key, uint64_t default_value);
177 std::unordered_map<std::string, std::vector<std::string> >::const_iterator keys_begin() {
178 return d_the_keys.begin();
181 std::unordered_map<std::string, std::vector<std::string> >::const_iterator keys_end() {
182 return d_the_keys.end();
189 bool using_dynamic_config()
const {
190 return d_dynamic_config_in_use;
193 void dump(std::ostream &strm)
const override;
194 virtual std::string
dump()
const;
top level BES object to house generic methods
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.
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
void delete_key(const std::string &key)
Delete the key Added primarily for testing purposes.
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.
utility class for the HTTP catalog module