CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
options.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_OPTIONS_H_
6 #define CVMFS_OPTIONS_H_
7 
8 #include <stdint.h>
9 
10 #include <cassert>
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 #ifdef CVMFS_NAMESPACE_GUARD
16 namespace CVMFS_NAMESPACE_GUARD {
17 #endif
18 
23  public:
24  void SetTemplate(std::string name, std::string val);
25  std::string GetTemplate(std::string name);
26  bool HasTemplate(std::string name);
27  bool ParseString(std::string *input);
28  private:
29  std::map<std::string, std::string> templates_;
30 };
31 
33  public:
34  explicit DefaultOptionsTemplateManager(std::string fqrn);
35  private:
36  static const char *kTemplateIdentFqrn;
37  static const char *kTemplateIdentOrg;
38 };
39 
48  public:
49  explicit OptionsManager(OptionsTemplateManager *opt_templ_mgr_param)
50  : taint_environment_(true) {
51  if (opt_templ_mgr_param != NULL) {
52  opt_templ_mgr_ = opt_templ_mgr_param;
53  } else {
54  opt_templ_mgr_ = new OptionsTemplateManager();
55  }
56  }
57 
58  OptionsManager(const OptionsManager& opt_mgr) {
59  config_ = opt_mgr.config_;
60  protected_parameters_ = opt_mgr.protected_parameters_;
61  templatable_values_ = opt_mgr.templatable_values_;
62  taint_environment_ = opt_mgr.taint_environment_;
63 
64  opt_templ_mgr_ = new OptionsTemplateManager(*(opt_mgr.opt_templ_mgr_));
65  }
66 
67  virtual ~OptionsManager() {
68  delete opt_templ_mgr_;
69  }
70 
74  void SwitchTemplateManager(OptionsTemplateManager *opt_templ_mgr_param);
75 
85  virtual void ParsePath(const std::string &config_file,
86  const bool external) = 0;
87 
91  void ParseDefault(const std::string &fqrn);
92 
96  void ClearConfig();
97 
104  bool IsDefined(const std::string &key);
105 
113  bool GetValue(const std::string &key, std::string *value) const;
114 
122  std::string GetValueOrDie(const std::string &key);
123 
132  bool GetSource(const std::string &key, std::string *value);
133 
140  bool IsOn(const std::string &param_value) const;
141 
148  bool IsOff(const std::string &param_value) const;
149 
155  std::vector<std::string> GetAllKeys();
156 
161  std::vector<std::string> GetEnvironmentSubset(
162  const std::string &key_prefix,
163  bool strip_prefix);
164 
173  std::string Dump();
174 
175  bool HasConfigRepository(const std::string &fqrn, std::string *config_path);
176 
181  void ProtectParameter(const std::string &param);
182 
186  void SetValue(const std::string &key, const std::string &value);
187 
191  void UnsetValue(const std::string &key);
192 
193  void set_taint_environment(bool value) { taint_environment_ = value; }
194 
195  protected:
200  struct ConfigValue {
201  std::string value;
202  std::string source;
203  };
204 
205  std::string TrimParameter(const std::string &parameter);
206  std::string SanitizeParameterAssignment(std::string *line,
207  std::vector <std::string> *tokens);
208  void PopulateParameter(const std::string &param, const ConfigValue val);
209  void ParseValue(const std::string param, ConfigValue *val);
210  void UpdateEnvironment(
211  const std::string &param, ConfigValue val);
212  std::map<std::string, ConfigValue> config_;
213  std::map<std::string, std::string> protected_parameters_;
214  std::map<std::string, std::string> templatable_values_;
215 
222 
223  private:
224  // NOLINTNEXTLINE(bugprone-unhandled-self-assignment,cert-oop54-cpp)
225  OptionsManager & operator= (const OptionsManager & /* other */) {
226  assert(false);
227  }
228 }; // class OptionManager
229 
230 
247  public:
249  OptionsTemplateManager *opt_templ_mgr_param = NULL)
250  : OptionsManager(opt_templ_mgr_param) { }
251  virtual void ParsePath(
252  const std::string &config_file,
253  const bool external __attribute__((unused))) {
254  (void) TryParsePath(config_file);
255  }
256  // Libcvmfs returns success or failure, the fuse module fails silently
257  bool TryParsePath(const std::string &config_file);
258 }; // class SimpleOptionsManager
259 
260 
268  public:
270  OptionsTemplateManager *opt_templ_mgr_param = NULL)
271  : OptionsManager(opt_templ_mgr_param) { }
272  void ParsePath(const std::string &config_file, const bool external);
273 }; // class BashOptionsManager
274 
275 
276 
277 #ifdef CVMFS_NAMESPACE_GUARD
278 } // namespace CVMFS_NAMESPACE_GUARD
279 #endif
280 
281 #endif // CVMFS_OPTIONS_H_
static const char * kTemplateIdentOrg
Definition: options.h:37
static const char * kTemplateIdentFqrn
Definition: options.h:36
OptionsManager(OptionsTemplateManager *opt_templ_mgr_param)
Definition: options.h:49
void set_taint_environment(bool value)
Definition: options.h:193
std::map< std::string, std::string > protected_parameters_
Definition: options.h:213
std::map< std::string, std::string > templatable_values_
Definition: options.h:214
OptionsTemplateManager * opt_templ_mgr_
Definition: options.h:216
BashOptionsManager(OptionsTemplateManager *opt_templ_mgr_param=NULL)
Definition: options.h:269
assert((mem||(size==0))&&"Out Of Memory")
struct cvmcache_object_info __attribute__
Definition: atomic.h:24
std::map< std::string, ConfigValue > config_
Definition: options.h:212
SimpleOptionsParser(OptionsTemplateManager *opt_templ_mgr_param=NULL)
Definition: options.h:248
std::map< std::string, std::string > templates_
Definition: options.h:29
virtual void ParsePath(const std::string &config_file, const bool external __attribute__((unused)))
Definition: options.h:251
OptionsManager(const OptionsManager &opt_mgr)
Definition: options.h:58
bool taint_environment_
Definition: options.h:221
virtual ~OptionsManager()
Definition: options.h:67