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();
40 bool OstreeUpdateAgent::download(
const Uptane::Target& target,
const std::string&
data) {
41 std::string treehub_server;
42 bool download_result =
false;
48 std::string server_url;
49 extractCredentialsArchive(data, &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();
58 auto install_res = OstreeManager::pull(sysrootPath_, treehub_server, *keyMngr_, target);
60 switch (install_res.result_code.num_code) {
61 case data::ResultCode::Numeric::kOk: {
62 LOG_INFO <<
"The target revision has been successfully downloaded: " << target.sha256Hash();
63 download_result =
true;
67 LOG_INFO <<
"The target revision is already present on the local OSTree repo: " << target.sha256Hash();
68 download_result =
true;
72 LOG_ERROR <<
"Failed to download the target revision: " << target.sha256Hash() <<
" ( " 73 << install_res.result_code.toString() <<
" ): " << install_res.description;
77 return download_result;
81 return (ostreePackMan_->install(target)).result_code.num_code;
84 void OstreeUpdateAgent::completeInstall() { ostreePackMan_->completeInstall(); }
87 return ostreePackMan_->finalizeInstall(target);
90 void extractCredentialsArchive(
const std::string& archive, std::string* ca, std::string* cert, std::string* pkey,
91 std::string* treehub_server) {
93 std::stringstream as(archive);
94 *ca = Utils::readFileFromArchive(as,
"ca.pem");
97 std::stringstream as(archive);
98 *cert = Utils::readFileFromArchive(as,
"client.pem");
101 std::stringstream as(archive);
102 *pkey = Utils::readFileFromArchive(as,
"pkey.pem");
105 std::stringstream as(archive);
106 *treehub_server = Utils::readFileFromArchive(as,
"server.url",
true);
bool IsOstree() const
Is this an OSTree target? OSTree targets need special treatment because the hash doesn't represent th...
Operation has already been processed.
Results of libaktualizr API calls.