Aktualizr
C++ SOTA Client
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 
14 struct StorageConfig {
15  StorageType type{StorageType::kSqlite};
16  boost::filesystem::path path{"/var/sota"};
17 
18  // FS storage
19  BasedPath uptane_metadata_path{"metadata"};
20  BasedPath uptane_private_key_path{"ecukey.der"};
21  BasedPath uptane_public_key_path{"ecukey.pub"};
22  BasedPath tls_cacert_path{"root.crt"};
23  BasedPath tls_pkey_path{"pkey.pem"};
24  BasedPath tls_clientcert_path{"client.pem"};
25 
26  // SQLite storage
27  BasedPath sqldb_path{"sql.db"}; // based on `/var/sota`
28 
29  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
30  void writeToStream(std::ostream& out_stream) const;
31 };
32 
33 struct ImportConfig {
34  boost::filesystem::path base_path{"/var/sota/import"};
35  BasedPath uptane_private_key_path{""};
36  BasedPath uptane_public_key_path{""};
37  BasedPath tls_cacert_path{""};
38  BasedPath tls_pkey_path{""};
39  BasedPath tls_clientcert_path{""};
40 
41  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
42  void writeToStream(std::ostream& out_stream) const;
43 };
44 
45 template <>
46 inline void CopyFromConfig(StorageType& dest, const std::string& option_name, const boost::property_tree::ptree& pt) {
47  boost::optional<std::string> value = pt.get_optional<std::string>(option_name);
48  if (value.is_initialized()) {
49  std::string storage_type{StripQuotesFromStrings(value.get())};
50  if (storage_type == "sqlite") {
51  dest = StorageType::kSqlite;
52  } else {
53  dest = StorageType::kFileSystem;
54  }
55  }
56 }
57 
58 #endif // STORAGE_CONFIG_H