CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
settings.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_PUBLISH_SETTINGS_H_
6 #define CVMFS_PUBLISH_SETTINGS_H_
7 
8 #include <stdint.h>
9 #include <unistd.h>
10 
11 #include <map>
12 #include <string>
13 
14 #include "compression.h"
15 #include "hash.h"
16 #include "sync_union.h"
18 
19 class OptionsManager;
20 
21 namespace publish {
22 
28 template <class T>
29 class Setting {
30  public:
31  Setting() : value_(), is_default_(true) { }
32  explicit Setting(const T &v) : value_(v), is_default_(true) { }
33 
34  Setting& operator=(const T &v) {
35  value_ = v;
36  is_default_ = false;
37  return *this;
38  }
39 
40  operator const T& () const {
41  return value_;
42  }
43 
44  const T& operator()() const {
45  return value_;
46  }
47 
48  bool SetIfDefault(const T &v) {
49  if (!is_default_) return false;
50  value_ = v;
51  is_default_ = false;
52  return true;
53  }
54 
55  bool is_default() const { return is_default_; }
56 
57  T* GetPtr() { return &value_; }
58 
59  private:
60  T value_;
62 }; // Setting
63 
64 
72 };
73 
74 
75 // Settings from the point of construction always represent a valid
76 // configuration. The constructor sets default values, which can be overwritten
77 // by setters. The setters throw errors when invalid options are detected.
78 
80  public:
81  explicit SettingsSpoolArea(const std::string &fqrn)
82  : workspace_(std::string("/var/spool/cvmfs/") + fqrn)
83  , tmp_dir_(workspace_() + "/tmp")
84  , union_mnt_(std::string("/cvmfs/") + fqrn)
86  { }
87 
88  void UseSystemTempDir();
89  void SetSpoolArea(const std::string &path);
90  void SetUnionMount(const std::string &path);
91  void SetRepairMode(const EUnionMountRepairMode val);
92 
93  // Creates, if necessary, all the directories in the spool area and the temp
94  // directory. Does not take care of the union mount point.
95  void EnsureDirectories();
96 
97  std::string workspace() const { return workspace_; }
98  std::string tmp_dir() const { return tmp_dir_; }
99  std::string readonly_mnt() const { return workspace_() + "/rdonly"; }
100  std::string readonly_talk_socket() const {
101  return workspace_() + "/cvmfs_io";
102  }
103  std::string union_mnt() const { return union_mnt_; }
104  std::string scratch_base() const { return workspace_() + "/scratch"; }
105  std::string scratch_dir() const { return scratch_base() + "/current"; }
106  std::string scratch_wastebin() const { return scratch_base() + "/wastebin"; }
107  std::string log_dir() const { return workspace() + "/logs"; }
108  // TODO(jblomer): shouldn't this be in /etc/cvmfs/repositor.../client.conf
109  std::string client_config() const { return workspace_() + "/client.config"; }
110  std::string client_lconfig() const { return workspace_() + "/client.local"; }
111  std::string client_log() const { return log_dir() + "/cvmfs.log"; }
112  std::string cache_dir() const { return workspace_() + "/cache"; }
113  std::string ovl_work_dir() const { return workspace_() + "/ovl_work"; }
114  std::string checkout_marker() const { return workspace_() + "/checkout"; }
115  std::string gw_session_token() const {
116  return workspace_() + "/session_token";
117  }
118  std::string transaction_lock() const {
119  return workspace_() + "/in_transaction.lock";
120  }
121  std::string publishing_lock() const {
122  return workspace_() + "/is_publishing.lock";
123  }
125 
126  private:
134 }; // SettingsSpoolArea
135 
136 
138  public:
139  explicit SettingsTransaction(const std::string &fqrn)
140  : layout_revision_(0)
141  , in_enter_session_(false)
142  , hash_algorithm_(shash::kShake128)
144  , ttl_second_(240)
146  , is_volatile_(false)
147  , enforce_limits_(false)
148  // SyncParameters::kDefaultNestedKcatalogLimit
150  // SyncParameters::kDefaultRootKcatalogLimit
152  // SyncParameters::kDefaultFileMbyteLimit
153  , limit_file_size_mb_(1024)
154  , use_catalog_autobalance_(false)
155  // SyncParameters::kDefaultMaxWeight
156  , autobalance_max_weight_(100000)
157  // SyncParameters::kDefaultMinWeight
159  , print_changeset_(false)
160  , dry_run_(false)
162  , timeout_s_(0)
163  , spool_area_(fqrn)
164  {}
165 
166  void SetLayoutRevision(const unsigned revision);
167  void SetInEnterSession(const bool value);
168  void SetBaseHash(const shash::Any &hash);
169  void SetUnionFsType(const std::string &union_fs);
170  void SetHashAlgorithm(const std::string &algorithm);
171  void SetCompressionAlgorithm(const std::string &algorithm);
172  void SetEnforceLimits(bool value);
173  void SetLimitNestedCatalogKentries(unsigned value);
174  void SetLimitRootCatalogKentries(unsigned value);
175  void SetLimitFileSizeMb(unsigned value);
176  void SetUseCatalogAutobalance(bool value);
177  void SetAutobalanceMaxWeight(unsigned value);
178  void SetAutobalanceMinWeight(unsigned value);
179  void SetPrintChangeset(bool value);
180  void SetDryRun(bool value);
181  void SetTimeout(unsigned seconds);
182  void SetLeasePath(const std::string &path);
183  void SetTemplate(const std::string &from, const std::string &to);
184  void DetectUnionFsType();
185 
190  int GetTimeoutS() const;
191 
192  unsigned layout_revision() const { return layout_revision_; }
193  bool in_enter_session() const { return in_enter_session_; }
194  shash::Any base_hash() const { return base_hash_; }
197  return compression_algorithm_;
198  }
199  uint32_t ttl_second() const { return ttl_second_; }
201  bool is_volatile() const { return is_volatile_; }
202  bool enforce_limits() const { return enforce_limits_; }
203  unsigned limit_nested_catalog_kentries() const {
205  }
206  unsigned limit_root_catalog_kentries() const {
208  }
209  unsigned limit_file_size_mb() const { return limit_file_size_mb_; }
211  unsigned autobalance_max_weight() const { return autobalance_max_weight_; }
212  unsigned autobalance_min_weight() const { return autobalance_min_weight_; }
213  bool print_changeset() const { return print_changeset_; }
214  bool dry_run() const { return dry_run_; }
215  std::string voms_authz() const { return voms_authz_; }
216  UnionFsType union_fs() const { return union_fs_; }
217  std::string lease_path() const { return lease_path_; }
218  std::string template_from() const { return template_from_; }
219  std::string template_to() const { return template_to_; }
220 
221  const SettingsSpoolArea &spool_area() const { return spool_area_; }
223 
224  bool HasTemplate() const { return !template_to().empty(); }
225 
226  private:
227  bool ValidateUnionFs();
228 
273 
275 }; // class SettingsTransaction
276 
277 
278 class SettingsGc {
279 }; // class SettingsGc
280 
281 
283  public:
284  explicit SettingsStorage(const std::string &fqrn)
285  : fqrn_(fqrn)
286  , type_(upload::SpoolerDefinition::Local)
287  , tmp_dir_(std::string("/srv/cvmfs/") + fqrn + "/data/txn")
288  , endpoint_(std::string("/srv/cvmfs/") + fqrn)
289  { }
290 
291  std::string GetLocator() const;
292  void SetLocator(const std::string &locator);
293  void MakeLocal(const std::string &path);
294  void MakeS3(const std::string &s3_config, const std::string &tmp_dir);
295  void MakeGateway(const std::string &host, unsigned port,
296  const std::string &tmp_dir);
297 
299  std::string endpoint() const { return endpoint_; }
300 
301  private:
306 }; // class SettingsStorage
307 
308 
310  public:
311  explicit SettingsKeychain(const std::string &fqrn)
312  : fqrn_(fqrn)
313  , keychain_dir_("/etc/cvmfs/keys")
314  , master_private_key_path_(keychain_dir_() + "/" + fqrn + ".masterkey")
315  , master_public_key_path_(keychain_dir_() + "/" + fqrn + ".pub")
316  , private_key_path_(keychain_dir_() + "/" + fqrn + ".key")
317  , certificate_path_(keychain_dir_() + "/" + fqrn + ".crt")
318  , gw_key_path_(keychain_dir_() + "/" + fqrn + ".gw")
319  {}
320 
321  void SetKeychainDir(const std::string &keychain_dir);
322 
323  bool HasDanglingMasterKeys() const;
324  bool HasMasterKeys() const;
325  bool HasDanglingRepositoryKeys() const;
326  bool HasRepositoryKeys() const;
327  bool HasGatewayKey() const;
328 
329  std::string keychain_dir() const { return keychain_dir_; }
330  std::string master_private_key_path() const {
332  }
333  std::string master_public_key_path() const { return master_public_key_path_; }
334  std::string private_key_path() const { return private_key_path_; }
335  std::string certificate_path() const { return certificate_path_; }
336  std::string gw_key_path() const { return gw_key_path_; }
337 
338  private:
346 }; // class SettingsKeychain
347 
348 
349 class SettingsPublisher;
350 
355  public:
356  explicit SettingsRepository(const std::string &fqrn)
357  : fqrn_(fqrn)
358  , url_(std::string("http://localhost/cvmfs/") + fqrn_())
359  , tmp_dir_("/tmp")
360  , keychain_(fqrn)
361  {}
362  explicit SettingsRepository(const SettingsPublisher &settings_publisher);
363 
364  void SetUrl(const std::string &url);
365  void SetTmpDir(const std::string &tmp_dir);
366 
367  std::string fqrn() const { return fqrn_; }
368  std::string url() const { return url_; }
369  std::string tmp_dir() const { return tmp_dir_; }
370 
371  const SettingsKeychain &keychain() const { return keychain_; }
373 
374  private:
378 
380 }; // class SettingsRepository
381 
382 
387  public:
388  static const unsigned kDefaultWhitelistValidity; // 30 days
389 
390  explicit SettingsPublisher(const std::string &fqrn)
391  : fqrn_(fqrn)
392  , url_(std::string("http://localhost/cvmfs/") + fqrn)
393  , owner_uid_(0)
394  , owner_gid_(0)
396  , is_silent_(false)
397  , is_managed_(false)
398  , storage_(fqrn_)
400  , keychain_(fqrn_)
401  { }
402  explicit SettingsPublisher(const SettingsRepository &settings_repository);
403 
404  void SetUrl(const std::string &url);
405  void SetOwner(const std::string &user_name);
406  void SetOwner(uid_t uid, gid_t gid);
407  void SetIsSilent(bool value);
408  void SetIsManaged(bool value);
409 
410  std::string GetReadOnlyXAttr(const std::string &attr);
411 
412  std::string fqrn() const { return fqrn_; }
413  std::string url() const { return url_; }
415  uid_t owner_uid() const { return owner_uid_; }
416  uid_t owner_gid() const { return owner_gid_; }
417  bool is_silent() const { return is_silent_; }
418  bool is_managed() const { return is_managed_; }
419 
420  const SettingsStorage &storage() const { return storage_; }
421  const SettingsTransaction &transaction() const { return transaction_; }
422  const SettingsKeychain &keychain() const { return keychain_; }
426 
427  private:
435 
439 }; // SettingsPublisher
440 
441 
446  public:
447  explicit SettingsReplica(const std::string &fqrn)
448  : fqrn_(fqrn)
449  , alias_(fqrn)
450  , url_(std::string("http://localhost/cvmfs/") + alias_())
451  {}
452 
453  private:
457 }; // class SettingsReplica
458 
459 
465  public:
467  : config_path_("/etc/cvmfs/repositories.d")
468  , options_mgr_(NULL)
469  {}
474  explicit SettingsBuilder(const std::string c) : config_path_(c) {}
475 
483  SettingsRepository CreateSettingsRepository(const std::string &ident);
484 
497  const std::string &ident, bool needs_managed = false);
498 
500  bool IsManagedRepository() const { return options_mgr_ != NULL; }
501 
502  private:
503  std::string config_path_;
509 
517  std::string GetSingleAlias();
518 
523  std::map<std::string, std::string> GetSessionEnvironment();
524 
529 }; // class SettingsBuilder
530 
531 } // namespace publish
532 
533 #endif // CVMFS_PUBLISH_SETTINGS_H_
unsigned autobalance_min_weight() const
Definition: settings.h:212
void SetUnionFsType(const std::string &union_fs)
Definition: settings.cc:122
SettingsKeychain * GetKeychain()
Definition: settings.h:372
SettingsSpoolArea spool_area_
Definition: settings.h:274
Setting< std::string > keychain_dir_
Definition: settings.h:340
Setting< unsigned > whitelist_validity_days_
Definition: settings.h:432
bool use_catalog_autobalance() const
Definition: settings.h:210
std::string endpoint() const
Definition: settings.h:299
std::string config_path_
Definition: settings.h:503
std::string readonly_mnt() const
Definition: settings.h:99
std::string checkout_marker() const
Definition: settings.h:114
bool HasGatewayKey() const
Definition: settings.cc:272
Setting< unsigned > timeout_s_
Definition: settings.h:265
const T & operator()() const
Definition: settings.h:44
shash::Algorithms hash_algorithm() const
Definition: settings.h:195
std::string voms_authz() const
Definition: settings.h:215
SettingsPublisher * CreateSettingsPublisher(const std::string &ident, bool needs_managed=false)
Definition: settings.cc:500
SettingsTransaction * GetTransaction()
Definition: settings.h:424
void SetUrl(const std::string &url)
Definition: settings.cc:290
void SetUnionMount(const std::string &path)
Definition: settings.cc:37
void MakeGateway(const std::string &host, unsigned port, const std::string &tmp_dir)
Definition: settings.cc:203
Setting< bool > is_managed_
Definition: settings.h:434
void SetTimeout(unsigned seconds)
Definition: settings.cc:154
SettingsKeychain * GetKeychain()
Definition: settings.h:425
unsigned limit_root_catalog_kentries() const
Definition: settings.h:206
uid_t owner_gid() const
Definition: settings.h:416
void SetKeychainDir(const std::string &keychain_dir)
Definition: settings.cc:235
Setting< gid_t > owner_gid_
Definition: settings.h:431
std::string keychain_dir() const
Definition: settings.h:329
void SetLimitNestedCatalogKentries(unsigned value)
Definition: settings.cc:90
EUnionMountRepairMode
Definition: settings.h:68
void SetAutobalanceMaxWeight(unsigned value)
Definition: settings.cc:106
std::string gw_key_path() const
Definition: settings.h:336
void SetIsSilent(bool value)
Definition: settings.cc:342
bool HasTemplate() const
Definition: settings.h:224
SettingsKeychain(const std::string &fqrn)
Definition: settings.h:311
Setting< UnionFsType > union_fs_
Definition: settings.h:261
unsigned layout_revision() const
Definition: settings.h:192
Setting< upload::SpoolerDefinition::DriverType > type_
Definition: settings.h:303
Setting< uint32_t > ttl_second_
Definition: settings.h:248
std::string private_key_path() const
Definition: settings.h:334
void SetTemplate(const std::string &from, const std::string &to)
Definition: settings.cc:168
Setting< bool > enforce_limits_
Definition: settings.h:251
unsigned autobalance_max_weight() const
Definition: settings.h:211
std::string GetSingleAlias()
Definition: settings.cc:385
Setting< std::string > union_mnt_
Definition: settings.h:129
std::string client_config() const
Definition: settings.h:109
std::string template_to() const
Definition: settings.h:219
SettingsRepository(const std::string &fqrn)
Definition: settings.h:356
void SetLayoutRevision(const unsigned revision)
Definition: settings.cc:65
EUnionMountRepairMode repair_mode() const
Definition: settings.h:124
std::string log_dir() const
Definition: settings.h:107
SettingsTransaction transaction_
Definition: settings.h:437
Setting< std::string > voms_authz_
Definition: settings.h:260
bool is_default_
Definition: settings.h:61
void SetLeasePath(const std::string &path)
Definition: settings.cc:164
Setting< std::string > tmp_dir_
Definition: settings.h:377
unsigned limit_nested_catalog_kentries() const
Definition: settings.h:203
Setting< unsigned > layout_revision_
Definition: settings.h:232
bool is_volatile() const
Definition: settings.h:201
void SetAutobalanceMinWeight(unsigned value)
Definition: settings.cc:110
char algorithm
SettingsPublisher(const std::string &fqrn)
Definition: settings.h:390
OptionsManager * options_mgr_
Definition: settings.h:508
Setting< bool > is_silent_
Definition: settings.h:433
bool HasMasterKeys() const
Definition: settings.cc:253
Setting< shash::Any > base_hash_
Definition: settings.h:245
Algorithms
Definition: hash.h:39
bool is_silent() const
Definition: settings.h:417
std::string master_public_key_path() const
Definition: settings.h:333
Setting< unsigned > limit_root_catalog_kentries_
Definition: settings.h:253
std::string transaction_lock() const
Definition: settings.h:118
Algorithms
Definition: compression.h:44
std::string cache_dir() const
Definition: settings.h:112
bool HasRepositoryKeys() const
Definition: settings.cc:267
UnionFsType union_fs() const
Definition: settings.h:216
const SettingsKeychain & keychain() const
Definition: settings.h:422
void SetTmpDir(const std::string &tmp_dir)
Definition: settings.cc:296
bool IsManagedRepository() const
Definition: settings.h:500
Setting< bool > in_enter_session_
Definition: settings.h:237
void SetDryRun(bool value)
Definition: settings.cc:118
std::string scratch_wastebin() const
Definition: settings.h:106
Setting< std::string > template_from_
Definition: settings.h:271
Setting< uid_t > owner_uid_
Definition: settings.h:430
std::string union_mnt() const
Definition: settings.h:103
Setting< bool > use_catalog_autobalance_
Definition: settings.h:255
bool print_changeset() const
Definition: settings.h:213
SettingsBuilder(const std::string c)
Definition: settings.h:474
std::string GetReadOnlyXAttr(const std::string &attr)
Definition: settings.cc:455
std::string publishing_lock() const
Definition: settings.h:121
std::string lease_path() const
Definition: settings.h:217
void SetUrl(const std::string &url)
Definition: settings.cc:324
std::string master_private_key_path() const
Definition: settings.h:330
std::string ovl_work_dir() const
Definition: settings.h:113
SettingsRepository CreateSettingsRepository(const std::string &ident)
Definition: settings.cc:408
Setting< unsigned > autobalance_max_weight_
Definition: settings.h:256
const SettingsSpoolArea & spool_area() const
Definition: settings.h:221
void SetLimitRootCatalogKentries(unsigned value)
Definition: settings.cc:94
Setting< std::string > url_
Definition: settings.h:456
void SetIsManaged(bool value)
Definition: settings.cc:346
Setting & operator=(const T &v)
Definition: settings.h:34
Setting< std::string > workspace_
Definition: settings.h:127
const SettingsTransaction & transaction() const
Definition: settings.h:421
Setting< std::string > fqrn_
Definition: settings.h:428
SettingsPublisher * CreateSettingsPublisherFromSession()
Definition: settings.cc:465
uint32_t ttl_second() const
Definition: settings.h:199
Setting< std::string > alias_
Definition: settings.h:455
SettingsKeychain keychain_
Definition: settings.h:438
bool is_default() const
Definition: settings.h:55
void SetHashAlgorithm(const std::string &algorithm)
Definition: settings.cc:77
std::string workspace() const
Definition: settings.h:97
void SetLocator(const std::string &locator)
Definition: settings.cc:213
SettingsTransaction(const std::string &fqrn)
Definition: settings.h:139
Setting< std::string > fqrn_
Definition: settings.h:302
zlib::Algorithms compression_algorithm() const
Definition: settings.h:196
std::string certificate_path() const
Definition: settings.h:335
Setting< bool > print_changeset_
Definition: settings.h:258
bool is_managed() const
Definition: settings.h:418
SettingsStorage * GetStorage()
Definition: settings.h:423
const SettingsStorage & storage() const
Definition: settings.h:420
Setting< zlib::Algorithms > compression_algorithm_
Definition: settings.h:247
Setting< std::string > fqrn_
Definition: settings.h:339
OptionsManager * options_mgr() const
Definition: settings.h:499
void SetLimitFileSizeMb(unsigned value)
Definition: settings.cc:98
Setting< std::string > url_
Definition: settings.h:429
Setting< std::string > template_to_
Definition: settings.h:272
void SetUseCatalogAutobalance(bool value)
Definition: settings.cc:102
Setting< EUnionMountRepairMode > repair_mode_
Definition: settings.h:133
Setting< unsigned > autobalance_min_weight_
Definition: settings.h:257
void SetCompressionAlgorithm(const std::string &algorithm)
Definition: settings.cc:81
bool enforce_limits() const
Definition: settings.h:202
Setting< std::string > private_key_path_
Definition: settings.h:343
void SetSpoolArea(const std::string &path)
Definition: settings.cc:32
Setting< shash::Algorithms > hash_algorithm_
Definition: settings.h:246
unsigned limit_file_size_mb() const
Definition: settings.h:209
void SetEnforceLimits(bool value)
Definition: settings.cc:86
Setting< std::string > tmp_dir_
Definition: settings.h:304
Setting< std::string > master_private_key_path_
Definition: settings.h:341
shash::Any base_hash() const
Definition: settings.h:194
const SettingsKeychain & keychain() const
Definition: settings.h:371
static const unsigned kDefaultWhitelistValidity
Definition: settings.h:388
std::string tmp_dir() const
Definition: settings.h:98
void SetBaseHash(const shash::Any &hash)
Definition: settings.cc:73
Setting< std::string > endpoint_
Definition: settings.h:305
void SetPrintChangeset(bool value)
Definition: settings.cc:114
std::string readonly_talk_socket() const
Definition: settings.h:100
SettingsStorage(const std::string &fqrn)
Definition: settings.h:284
std::string scratch_dir() const
Definition: settings.h:105
std::string gw_session_token() const
Definition: settings.h:115
unsigned whitelist_validity_days() const
Definition: settings.h:414
std::map< std::string, std::string > GetSessionEnvironment()
Definition: settings.cc:359
SettingsSpoolArea * GetSpoolArea()
Definition: settings.h:222
bool HasDanglingRepositoryKeys() const
Definition: settings.cc:259
std::string fqrn() const
Definition: settings.h:412
std::string fqrn() const
Definition: settings.h:367
SettingsStorage storage_
Definition: settings.h:436
Setting< unsigned > limit_file_size_mb_
Definition: settings.h:254
void MakeLocal(const std::string &path)
Definition: settings.cc:197
Setting< std::string > master_public_key_path_
Definition: settings.h:342
upload::SpoolerDefinition::DriverType type() const
Definition: settings.h:298
std::string scratch_base() const
Definition: settings.h:104
void SetOwner(const std::string &user_name)
Definition: settings.cc:330
void SetRepairMode(const EUnionMountRepairMode val)
Definition: settings.cc:41
std::string template_from() const
Definition: settings.h:218
uid_t owner_uid() const
Definition: settings.h:415
bool in_enter_session() const
Definition: settings.h:193
Setting< unsigned > limit_nested_catalog_kentries_
Definition: settings.h:252
Setting< std::string > fqrn_
Definition: settings.h:454
Setting< bool > is_volatile_
Definition: settings.h:250
SettingsKeychain keychain_
Definition: settings.h:379
Setting< bool > dry_run_
Definition: settings.h:259
Setting< std::string > certificate_path_
Definition: settings.h:344
std::string url() const
Definition: settings.h:368
bool SetIfDefault(const T &v)
Definition: settings.h:48
std::string client_lconfig() const
Definition: settings.h:110
void MakeS3(const std::string &s3_config, const std::string &tmp_dir)
Definition: settings.cc:188
std::string url() const
Definition: settings.h:413
Setting< std::string > tmp_dir_
Definition: settings.h:128
std::string GetLocator() const
Definition: settings.cc:182
Setting< std::string > url_
Definition: settings.h:376
void SetInEnterSession(const bool value)
Definition: settings.cc:69
SettingsReplica(const std::string &fqrn)
Definition: settings.h:447
Setting< std::string > gw_key_path_
Definition: settings.h:345
Setting(const T &v)
Definition: settings.h:32
Setting< std::string > lease_path_
Definition: settings.h:266
std::string tmp_dir() const
Definition: settings.h:369
SettingsSpoolArea(const std::string &fqrn)
Definition: settings.h:81
Setting< bool > is_garbage_collectable_
Definition: settings.h:249
Setting< std::string > fqrn_
Definition: settings.h:375
bool HasDanglingMasterKeys() const
Definition: settings.cc:245
std::string client_log() const
Definition: settings.h:111
bool is_garbage_collectable() const
Definition: settings.h:200