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 60
ref: little step forward to separate lib aktualizr headers #1688
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7238405
ref: little step forward to separate lib aktualizr headers
kbushgit 6bdcc52
cmake: libaktualizr headers installation
kbushgit f5434e0
fix include path in tests
kbushgit 8bc23c7
ref: add/remove headers
kbushgit 17d9f72
ref: finishing definition of aktualizr + move some types into public API
kbushgit 79e8b6c
Add campaign definition to public api + fix doxygen
kbushgit f7ea14c
adding Target and Hash obj to pub def + del unnecessary includes
kbushgit 0cc5851
put all configs into single header + remove config utils from pub api
kbushgit 62c3051
using unique_ptr with incomplete types requires explicit dtor
kbushgit cc4742a
remove definitions of general utils from pub API
kbushgit b19559e
Remove Config::config_dirs_ member, defined in BaseConfig
kbushgit d73b21a
fix: LoggerConfig def + remove unnecessary comments
kbushgit 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
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 "libaktualizr/types.h" | ||
|
||
struct LoggerConfig { | ||
int loglevel{2}; | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
// Try to keep the order of config options the same as in Config::writeToStream() | ||
// and Config::updateFromPropertyTree() in config.cc. | ||
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::kSharedCred}; | ||
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; | ||
}; | ||
|
||
// 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; | ||
|
||
}; | ||
|
||
// 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; | ||
}; | ||
|
||
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; | ||
}; | ||
|
||
// 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 TelemetryConfig { | ||
/** | ||
* Report device network information: IP address, hostname, MAC address | ||
*/ | ||
bool report_network{true}; | ||
bool report_config{true}; | ||
|
||
void updateFromPropertyTree(const boost::property_tree::ptree& pt); | ||
void writeToStream(std::ostream& out_stream) const; | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, StorageType stype); | ||
|
||
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; | ||
}; | ||
|
||
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
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.
I forget, does
class api::CommandQueue
work? I thought it did and it's a little cleaner.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.
yes we use it, the disadvantage he is that we have to use smart ptr, the reason is that we cant simple uses forward declaration with member objects defined by the value
aktualizr/include/libaktualizr/aktualizr.h
Line 250 in 39f58c5
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.
Yeah, that's fine, I just meant if we could put this forward declaration on one line by using the scope resolution operator (
::
) instead of this three-line variant.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.
Why not a unique_ptr, though?
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 will cause a compilation error:
It can be fixed by adding an empty dtor for Aktualizr.
Here is an answer with a good explanation
https://stackoverflow.com/a/9954553