CernVM-FS  2.9.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);
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);
141 
147  std::vector<std::string> GetAllKeys();
148 
153  std::vector<std::string> GetEnvironmentSubset(
154  const std::string &key_prefix,
155  bool strip_prefix);
156 
165  std::string Dump();
166 
167  bool HasConfigRepository(const std::string &fqrn, std::string *config_path);
168 
173  void ProtectParameter(const std::string &param);
174 
178  void SetValue(const std::string &key, const std::string &value);
179 
183  void UnsetValue(const std::string &key);
184 
185  void set_taint_environment(bool value) { taint_environment_ = value; }
186 
187  protected:
192  struct ConfigValue {
193  std::string value;
194  std::string source;
195  };
196 
197  std::string TrimParameter(const std::string &parameter);
198  std::string SanitizeParameterAssignment(std::string *line,
199  std::vector <std::string> *tokens);
200  void PopulateParameter(const std::string &param, const ConfigValue val);
201  void ParseValue(const std::string param, ConfigValue *val);
202  void UpdateEnvironment(
203  const std::string &param, ConfigValue val);
204  std::map<std::string, ConfigValue> config_;
205  std::map<std::string, std::string> protected_parameters_;
206  std::map<std::string, std::string> templatable_values_;
207 
214 
215  private:
216  // NOLINTNEXTLINE(bugprone-unhandled-self-assignment,cert-oop54-cpp)
217  OptionsManager & operator= (const OptionsManager & /* other */) {
218  assert(false);
219  }
220 }; // class OptionManager
221 
222 
239  public:
241  OptionsTemplateManager *opt_templ_mgr_param = NULL)
242  : OptionsManager(opt_templ_mgr_param) { }
243  virtual void ParsePath(
244  const std::string &config_file,
245  const bool external __attribute__((unused))) {
246  (void) TryParsePath(config_file);
247  }
248  // Libcvmfs returns success or failure, the fuse module fails silently
249  bool TryParsePath(const std::string &config_file);
250 }; // class SimpleOptionsManager
251 
252 
260  public:
262  OptionsTemplateManager *opt_templ_mgr_param = NULL)
263  : OptionsManager(opt_templ_mgr_param) { }
264  void ParsePath(const std::string &config_file, const bool external);
265 }; // class BashOptionsManager
266 
267 
268 
269 #ifdef CVMFS_NAMESPACE_GUARD
270 } // namespace CVMFS_NAMESPACE_GUARD
271 #endif
272 
273 #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:185
std::map< std::string, std::string > protected_parameters_
Definition: options.h:205
std::map< std::string, std::string > templatable_values_
Definition: options.h:206
OptionsTemplateManager * opt_templ_mgr_
Definition: options.h:208
BashOptionsManager(OptionsTemplateManager *opt_templ_mgr_param=NULL)
Definition: options.h:261
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:204
SimpleOptionsParser(OptionsTemplateManager *opt_templ_mgr_param=NULL)
Definition: options.h:240
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:243
OptionsManager(const OptionsManager &opt_mgr)
Definition: options.h:58
bool taint_environment_
Definition: options.h:213
virtual ~OptionsManager()
Definition: options.h:67