Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
storage_config.h
1 #ifndef STORAGE_CONFIG_H
2 #define STORAGE_CONFIG_H
3 
4 #include <memory>
5 #include <string>
6 
7 #include <boost/filesystem.hpp>
8 #include <boost/property_tree/ptree_fwd.hpp>
9 
10 #include "utilities/config_utils.h"
11 
12 enum class StorageType { kFileSystem = 0, kSqlite };
13 std::ostream& operator<<(std::ostream& os, StorageType stype);
14 
15 struct StorageConfig {
16  StorageType type{StorageType::kSqlite};
17  boost::filesystem::path path{"/var/sota"};
18 
19  // FS storage
20  BasedPath uptane_metadata_path{"metadata"};
21  BasedPath uptane_private_key_path{"ecukey.der"};
22  BasedPath uptane_public_key_path{"ecukey.pub"};
23  BasedPath tls_cacert_path{"root.crt"};
24  BasedPath tls_pkey_path{"pkey.pem"};
25  BasedPath tls_clientcert_path{"client.pem"};
26 
27  // SQLite storage
28  BasedPath sqldb_path{"sql.db"}; // based on `/var/sota`
29 
30  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
31  void writeToStream(std::ostream& out_stream) const;
32 };
33 
34 struct ImportConfig {
35  boost::filesystem::path base_path{"/var/sota/import"};
36  BasedPath uptane_private_key_path{""};
37  BasedPath uptane_public_key_path{""};
38  BasedPath tls_cacert_path{""};
39  BasedPath tls_pkey_path{""};
40  BasedPath tls_clientcert_path{""};
41 
42  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
43  void writeToStream(std::ostream& out_stream) const;
44 };
45 
46 template <>
47 inline void CopyFromConfig(StorageType& dest, const std::string& option_name, const boost::property_tree::ptree& pt) {
48  boost::optional<std::string> value = pt.get_optional<std::string>(option_name);
49  if (value.is_initialized()) {
50  std::string storage_type{StripQuotesFromStrings(value.get())};
51  if (storage_type == "sqlite") {
52  dest = StorageType::kSqlite;
53  } else {
54  dest = StorageType::kFileSystem;
55  }
56  }
57 }
58 
59 #endif // STORAGE_CONFIG_H
BasedPath
Definition: utils.h:101
StorageConfig
Definition: storage_config.h:15
ImportConfig
Definition: storage_config.h:34