This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
ref: moving all configs definition into a single file #1707
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
#ifndef CONFIG_H_ | ||
#define CONFIG_H_ | ||
|
||
#include <algorithm> | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <boost/filesystem.hpp> | ||
#include <boost/program_options.hpp> | ||
#include <boost/property_tree/ini_parser.hpp> | ||
#include "utilities/types.h" | ||
#include "utilities/utils.h" | ||
|
||
// Try to keep the order of config options the same as in Config::writeToStream() | ||
// and Config::updateFromPropertyTree() in config.cc. | ||
|
||
struct LoggerConfig { | ||
int loglevel{2}; | ||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
// declare p11 types as incomplete so that the header can be used without libp11 | ||
struct PKCS11_ctx_st; | ||
struct PKCS11_slot_st; | ||
|
||
struct P11Config { | ||
boost::filesystem::path module; | ||
std::string pass; | ||
std::string uptane_key_id; | ||
std::string tls_cacert_id; | ||
std::string tls_pkey_id; | ||
std::string tls_clientcert_id; | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
struct TlsConfig { | ||
std::string server; | ||
boost::filesystem::path server_url_path; | ||
CryptoSource ca_source{CryptoSource::kFile}; | ||
CryptoSource pkey_source{CryptoSource::kFile}; | ||
CryptoSource cert_source{CryptoSource::kFile}; | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
struct ProvisionConfig { | ||
std::string server; | ||
std::string p12_password; | ||
std::string expiry_days{"36000"}; | ||
boost::filesystem::path provision_path; | ||
ProvisionMode mode{ProvisionMode::kDefault}; | ||
std::string device_id; | ||
std::string primary_ecu_serial; | ||
std::string primary_ecu_hardware_id; | ||
std::string ecu_registration_endpoint; | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
struct UptaneConfig { | ||
uint64_t polling_sec{10U}; | ||
std::string director_server; | ||
std::string repo_server; | ||
CryptoSource key_source{CryptoSource::kFile}; | ||
KeyType key_type{KeyType::kRSA2048}; | ||
bool force_install_completion{false}; | ||
boost::filesystem::path secondary_config_file; | ||
uint64_t secondary_preinstall_wait_sec{600U}; | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
// TODO: move these to their corresponding headers | ||
#define PACKAGE_MANAGER_NONE "none" | ||
#define PACKAGE_MANAGER_OSTREE "ostree" | ||
#define PACKAGE_MANAGER_DEBIAN "debian" | ||
#define PACKAGE_MANAGER_ANDROID "android" | ||
#define PACKAGE_MANAGER_OSTREEDOCKERAPP "ostree+docker-app" | ||
|
||
#ifdef BUILD_OSTREE | ||
#define PACKAGE_MANAGER_DEFAULT PACKAGE_MANAGER_OSTREE | ||
#else | ||
#define PACKAGE_MANAGER_DEFAULT PACKAGE_MANAGER_NONE | ||
#endif | ||
|
||
struct PackageConfig { | ||
std::string type{PACKAGE_MANAGER_DEFAULT}; | ||
|
||
// OSTree options | ||
std::string os; | ||
boost::filesystem::path sysroot; | ||
std::string ostree_server; | ||
boost::filesystem::path images_path{"/var/sota/images"}; | ||
boost::filesystem::path packages_file{"/usr/package.manifest"}; | ||
|
||
// Options for simulation (to be used with "none") | ||
bool fake_need_reboot{false}; | ||
|
||
// for specialized configuration | ||
std::map<std::string, std::string> extra; | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
struct StorageConfig { | ||
StorageType type{StorageType::kSqlite}; | ||
boost::filesystem::path path{"/var/sota"}; | ||
|
||
// FS storage | ||
BasedPath uptane_metadata_path{"metadata"}; | ||
BasedPath uptane_private_key_path{"ecukey.der"}; | ||
BasedPath uptane_public_key_path{"ecukey.pub"}; | ||
BasedPath tls_cacert_path{"root.crt"}; | ||
BasedPath tls_pkey_path{"pkey.pem"}; | ||
BasedPath tls_clientcert_path{"client.pem"}; | ||
|
||
// SQLite storage | ||
BasedPath sqldb_path{"sql.db"}; // based on `/var/sota` | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
struct ImportConfig { | ||
boost::filesystem::path base_path{"/var/sota/import"}; | ||
BasedPath uptane_private_key_path{""}; | ||
BasedPath uptane_public_key_path{""}; | ||
BasedPath tls_cacert_path{""}; | ||
BasedPath tls_pkey_path{""}; | ||
BasedPath tls_clientcert_path{""}; | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
/** | ||
* @brief The TelemetryConfig struct | ||
* Report device network information: IP address, hostname, MAC address. | ||
*/ | ||
struct TelemetryConfig { | ||
bool report_network{true}; | ||
bool report_config{true}; | ||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
enum class RollbackMode { kBootloaderNone = 0, kUbootGeneric, kUbootMasked }; | ||
std::ostream& operator<<(std::ostream& os, RollbackMode mode); | ||
|
||
struct BootloaderConfig { | ||
RollbackMode rollback_mode{RollbackMode::kBootloaderNone}; | ||
boost::filesystem::path reboot_sentinel_dir{"/var/run/aktualizr-session"}; | ||
boost::filesystem::path reboot_sentinel_name{"need_reboot"}; | ||
std::string reboot_command{"/sbin/reboot"}; | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
// bundle some parts of the main config together | ||
// Should be derived by calling Config::keymanagerConfig() | ||
struct KeyManagerConfig { | ||
KeyManagerConfig() = delete; // only allow construction by initializer list | ||
P11Config p11; | ||
CryptoSource tls_ca_source; | ||
CryptoSource tls_pkey_source; | ||
CryptoSource tls_cert_source; | ||
KeyType uptane_key_type; | ||
CryptoSource uptane_key_source; | ||
}; | ||
|
||
/** | ||
* @brief The BaseConfig class | ||
*/ | ||
class BaseConfig { | ||
public: | ||
virtual ~BaseConfig() = default; | ||
void updateFromToml(const boost::filesystem::path& filename); | ||
virtual void updateFromPropertyTree(const boost::property_tree::ptree& pt) = 0; | ||
|
||
protected: | ||
void updateFromDirs(const std::vector<boost::filesystem::path>& configs); | ||
|
||
static void checkDirs(const std::vector<boost::filesystem::path>& configs) { | ||
for (const auto& config : configs) { | ||
if (!boost::filesystem::exists(config)) { | ||
throw std::runtime_error("Config directory " + config.string() + " does not exist."); | ||
} | ||
} | ||
} | ||
|
||
std::vector<boost::filesystem::path> config_dirs_ = {"/usr/lib/sota/conf.d", "/etc/sota/conf.d/"}; | ||
}; | ||
|
||
/** | ||
* Configuration object for an aktualizr instance running on a Primary ECU. | ||
* | ||
* This class is a parent to a series of smaller configuration objects for | ||
* specific subsystems. Note that most other aktualizr-related tools have their | ||
* own parent configuration objects with a reduced set of members. | ||
*/ | ||
class Config : public BaseConfig { | ||
public: | ||
Config(); | ||
explicit Config(const boost::program_options::variables_map& cmd); | ||
explicit Config(const boost::filesystem::path& filename); | ||
explicit Config(const std::vector<boost::filesystem::path>& config_dirs); | ||
|
||
KeyManagerConfig keymanagerConfig() const; | ||
|
||
void updateFromTomlString(const std::string& contents); | ||
void postUpdateValues(); | ||
void writeToStream(std::ostream& sink) const; | ||
|
||
// Config data structures. Keep logger first so that it is taken into account | ||
// while processing the others. | ||
LoggerConfig logger; | ||
P11Config p11; | ||
TlsConfig tls; | ||
ProvisionConfig provision; | ||
UptaneConfig uptane; | ||
PackageConfig pacman; | ||
StorageConfig storage; | ||
ImportConfig import; | ||
TelemetryConfig telemetry; | ||
BootloaderConfig bootloader; | ||
|
||
private: | ||
void updateFromPropertyTree(const boost::property_tree::ptree& pt) override; | ||
void updateFromCommandLine(const boost::program_options::variables_map& cmd); | ||
bool loglevel_from_cmdline{false}; | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, const Config& cfg); | ||
|
||
#endif // CONFIG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is slightly unfortunate that we have to include a bunch more stuff in aktualizr-secondary that we won't actually use, but for now that seems like a small issue that we can address at another time.