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);
10 bool OstreeUpdateAgent::isTargetSupported(
const Uptane::Target& target)
const {
return target.
IsOstree(); }
15 installed_image_info.len = 0;
16 installed_image_info.hash = _ostreePackMan->getCurrentHash();
21 auto currently_installed_target = _ostreePackMan->getCurrent();
22 if (!currently_installed_target.IsValid()) {
26 installed_image_info.name = _targetname_prefix +
"-" + installed_image_info.hash;
28 installed_image_info.name = currently_installed_target.filename();
32 }
catch (
const std::exception& exc) {
33 LOG_ERROR <<
"Failed to get the currently installed revision: " << exc.what();
38 bool OstreeUpdateAgent::download(
const Uptane::Target& target,
const std::string&
data) {
39 std::string treehub_server;
40 bool download_result =
false;
43 std::string ca, cert, pkey, server_url;
44 extractCredentialsArchive(
data, &ca, &cert, &pkey, &server_url);
46 _keyMngr->loadKeys(&pkey, &cert, &ca);
47 boost::trim(server_url);
48 treehub_server = server_url;
49 }
catch (std::runtime_error& exc) {
50 LOG_ERROR << exc.what();
54 auto install_res = OstreeManager::pull(_sysrootPath, treehub_server, *_keyMngr, target);
56 switch (install_res.result_code.num_code) {
57 case data::ResultCode::Numeric::kOk: {
58 LOG_INFO <<
"The target revision has been successfully downloaded: " << target.sha256Hash();
59 download_result =
true;
63 LOG_INFO <<
"The target revision is already present on the local ostree repo: " << target.sha256Hash();
64 download_result =
true;
68 LOG_ERROR <<
"Failed to download the target revision: " << target.sha256Hash() <<
" ( "
69 << install_res.result_code.toString() <<
" ): " << install_res.description;
73 return download_result;
77 return (_ostreePackMan->install(target)).result_code.num_code;
81 return _ostreePackMan->finalizeInstall(target);
84 void extractCredentialsArchive(
const std::string& archive, std::string* ca, std::string* cert, std::string* pkey,
85 std::string* treehub_server) {
87 std::stringstream as(archive);
88 *ca = Utils::readFileFromArchive(as,
"ca.pem");
91 std::stringstream as(archive);
92 *cert = Utils::readFileFromArchive(as,
"client.pem");
95 std::stringstream as(archive);
96 *pkey = Utils::readFileFromArchive(as,
"pkey.pem");
99 std::stringstream as(archive);
100 *treehub_server = Utils::readFileFromArchive(as,
"server.url",
true);