Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
config.h
1 #ifndef CONFIG_H_
2 #define CONFIG_H_
3 
4 #include <algorithm>
5 #include <iostream>
6 #include <string>
7 #include <vector>
8 
9 #include <boost/filesystem.hpp>
10 #include <boost/program_options.hpp>
11 #include <boost/property_tree/ini_parser.hpp>
12 #include "bootloader/bootloader.h"
13 #include "crypto/keymanager_config.h"
14 #include "crypto/p11_config.h"
15 #include "logging/logging_config.h"
16 #include "package_manager/packagemanagerconfig.h"
17 #include "storage/storage_config.h"
18 #include "telemetry/telemetryconfig.h"
19 #include "utilities/config_utils.h"
20 #include "utilities/types.h"
21 
22 enum class ProvisionMode { kSharedCred = 0, kDeviceCred };
23 
24 // Try to keep the order of config options the same as in Config::writeToStream()
25 // and Config::updateFromPropertyTree() in config.cc.
26 
27 struct TlsConfig {
28  std::string server;
29  boost::filesystem::path server_url_path;
30  CryptoSource ca_source{CryptoSource::kFile};
31  CryptoSource pkey_source{CryptoSource::kFile};
32  CryptoSource cert_source{CryptoSource::kFile};
33 
34  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
35  void writeToStream(std::ostream& out_stream) const;
36 };
37 
39  std::string server;
40  std::string p12_password;
41  std::string expiry_days{"36000"};
42  boost::filesystem::path provision_path;
43  ProvisionMode mode{ProvisionMode::kSharedCred};
44  std::string device_id;
45  std::string primary_ecu_serial;
46  std::string primary_ecu_hardware_id;
47  std::string ecu_registration_endpoint;
48 
49  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
50  void writeToStream(std::ostream& out_stream) const;
51 };
52 
53 struct UptaneConfig {
54  uint64_t polling_sec{10U};
55  std::string director_server;
56  std::string repo_server;
57  CryptoSource key_source{CryptoSource::kFile};
58  KeyType key_type{KeyType::kRSA2048};
59  bool force_install_completion{false};
60  boost::filesystem::path secondary_config_file;
61  uint64_t secondary_preinstall_wait_sec{600U};
62 
63  void updateFromPropertyTree(const boost::property_tree::ptree& pt);
64  void writeToStream(std::ostream& out_stream) const;
65 };
66 
67 /**
68  * Configuration object for an aktualizr instance running on a Primary ECU.
69  *
70  * This class is a parent to a series of smaller configuration objects for
71  * specific subsystems. Note that most other aktualizr-related tools have their
72  * own parent configuration objects with a reduced set of members.
73  */
74 class Config : public BaseConfig {
75  public:
76  Config();
77  explicit Config(const boost::program_options::variables_map& cmd);
78  explicit Config(const boost::filesystem::path& filename);
79  explicit Config(const std::vector<boost::filesystem::path>& config_dirs);
80 
81  KeyManagerConfig keymanagerConfig() const;
82 
83  void updateFromTomlString(const std::string& contents);
84  void postUpdateValues();
85  void writeToStream(std::ostream& sink) const;
86 
87  // Config data structures. Keep logger first so that it is taken into account
88  // while processing the others.
89  LoggerConfig logger;
90  P11Config p11;
91  TlsConfig tls;
92  ProvisionConfig provision;
93  UptaneConfig uptane;
94  PackageConfig pacman;
95  StorageConfig storage;
96  ImportConfig import;
97  TelemetryConfig telemetry;
98  BootloaderConfig bootloader;
99 
100  private:
101  void updateFromPropertyTree(const boost::property_tree::ptree& pt) override;
102  void updateFromCommandLine(const boost::program_options::variables_map& cmd);
103 
104  std::vector<boost::filesystem::path> config_dirs_ = {"/usr/lib/sota/conf.d", "/etc/sota/conf.d/"};
105  bool loglevel_from_cmdline{false};
106 };
107 
108 std::ostream& operator<<(std::ostream& os, const Config& cfg);
109 
110 #endif // CONFIG_H_
Configuration object for an aktualizr instance running on a Primary ECU.
Definition: config.h:74