1 #include "secondary_provider.h" 3 bool SecondaryProvider::getMetadata(Uptane::MetaBundle* meta_bundle,
const Uptane::Target& target)
const {
9 if (!getDirectorMetadata(&root, &targets)) {
12 meta_bundle->emplace(std::make_pair(Uptane::RepositoryType::Director(), Uptane::Role::Root()), root);
13 meta_bundle->emplace(std::make_pair(Uptane::RepositoryType::Director(), Uptane::Role::Targets()), targets);
15 if (!getImageRepoMetadata(&root, ×tamp, &snapshot, &targets)) {
18 meta_bundle->emplace(std::make_pair(Uptane::RepositoryType::Image(), Uptane::Role::Root()), root);
19 meta_bundle->emplace(std::make_pair(Uptane::RepositoryType::Image(), Uptane::Role::Timestamp()), timestamp);
20 meta_bundle->emplace(std::make_pair(Uptane::RepositoryType::Image(), Uptane::Role::Snapshot()), snapshot);
21 meta_bundle->emplace(std::make_pair(Uptane::RepositoryType::Image(), Uptane::Role::Targets()), targets);
30 bool SecondaryProvider::getDirectorMetadata(std::string* root, std::string* targets)
const {
31 if (!storage_->loadLatestRoot(root, Uptane::RepositoryType::Director())) {
32 LOG_ERROR <<
"No Director Root metadata to send";
35 if (!storage_->loadNonRoot(targets, Uptane::RepositoryType::Director(), Uptane::Role::Targets())) {
36 LOG_ERROR <<
"No Director Targets metadata to send";
42 bool SecondaryProvider::getImageRepoMetadata(std::string* root, std::string* timestamp, std::string* snapshot,
43 std::string* targets)
const {
44 if (!storage_->loadLatestRoot(root, Uptane::RepositoryType::Image())) {
45 LOG_ERROR <<
"No Image repo Root metadata to send";
48 if (!storage_->loadNonRoot(timestamp, Uptane::RepositoryType::Image(), Uptane::Role::Timestamp())) {
49 LOG_ERROR <<
"No Image repo Timestamp metadata to send";
52 if (!storage_->loadNonRoot(snapshot, Uptane::RepositoryType::Image(), Uptane::Role::Snapshot())) {
53 LOG_ERROR <<
"No Image repo Snapshot metadata to send";
56 if (!storage_->loadNonRoot(targets, Uptane::RepositoryType::Image(), Uptane::Role::Targets())) {
57 LOG_ERROR <<
"No Image repo Targets metadata to send";
63 std::string SecondaryProvider::getTreehubCredentials()
const {
64 if (config_.tls.pkey_source != CryptoSource::kFile || config_.tls.cert_source != CryptoSource::kFile ||
65 config_.tls.ca_source != CryptoSource::kFile) {
66 LOG_ERROR <<
"Cannot send OSTree update to a Secondary when not using file as credential sources";
72 if (!storage_->loadTlsCreds(&ca, &cert, &pkey)) {
73 LOG_ERROR <<
"Could not load TLS credentials from storage";
77 const std::string treehub_url = config_.pacman.ostree_server;
78 std::map<std::string, std::string> archive_map = {
79 {
"ca.pem", ca}, {
"client.pem", cert}, {
"pkey.pem", pkey}, {
"server.url", treehub_url}};
83 Utils::writeArchive(archive_map, as);
86 }
catch (std::runtime_error& exc) {
87 LOG_ERROR <<
"Could not create credentials archive: " << exc.what();
92 std::ifstream SecondaryProvider::getTargetFileHandle(
const Uptane::Target& target)
const {
93 return package_manager_->openTargetFile(target);