1 #include "update_agent_ostree.h"
3 #include "package_manager/ostreemanager.h"
7 static void extractCredentialsArchive(
const std::string& archive, std::string* ca, std::string* cert, std::string* pkey,
8 std::string* treehub_server);
12 bool OstreeUpdateAgent::isTargetSupported(
const Uptane::Target& target)
const {
return target.
IsOstree(); }
17 installed_image_info.len = 0;
18 installed_image_info.hash = ostreePackMan_->getCurrentHash();
23 auto currently_installed_target = ostreePackMan_->getCurrent();
24 if (!currently_installed_target.IsValid()) {
28 installed_image_info.name = targetname_prefix_ +
"-" + installed_image_info.hash;
30 installed_image_info.name = currently_installed_target.filename();
34 }
catch (
const std::exception& exc) {
35 LOG_ERROR <<
"Failed to get the currently installed revision: " << exc.what();
41 const std::string& treehub_tls_creds) {
42 std::string treehub_server;
48 std::string server_url;
49 extractCredentialsArchive(treehub_tls_creds, &ca, &cert, &pkey, &server_url);
50 keyMngr_->loadKeys(&pkey, &cert, &ca);
51 boost::trim(server_url);
52 treehub_server = server_url;
53 }
catch (std::runtime_error& exc) {
54 LOG_ERROR << exc.what();
56 std::string(
"Error loading Treehub credentials: ") + exc.what());
59 auto result = OstreeManager::pull(sysrootPath_, treehub_server, *keyMngr_, target);
61 switch (
result.result_code.num_code) {
62 case data::ResultCode::Numeric::kOk: {
63 LOG_INFO <<
"The target commit has been successfully downloaded: " << target.sha256Hash();
67 LOG_INFO <<
"The target commit is already present on the local OSTree repo: " << target.sha256Hash();
71 LOG_ERROR <<
"Failed to download the target commit: " << target.sha256Hash() <<
" ( "
72 <<
result.result_code.toString() <<
" ): " <<
result.description;
80 return ostreePackMan_->install(target);
83 void OstreeUpdateAgent::completeInstall() { ostreePackMan_->completeInstall(); }
86 return ostreePackMan_->finalizeInstall(target);
89 void extractCredentialsArchive(
const std::string& archive, std::string* ca, std::string* cert, std::string* pkey,
90 std::string* treehub_server) {
92 std::stringstream as(archive);
93 *ca = Utils::readFileFromArchive(as,
"ca.pem");
96 std::stringstream as(archive);
97 *cert = Utils::readFileFromArchive(as,
"client.pem");
100 std::stringstream as(archive);
101 *pkey = Utils::readFileFromArchive(as,
"pkey.pem");
104 std::stringstream as(archive);
105 *treehub_server = Utils::readFileFromArchive(as,
"server.url",
true);