1 #include "opcuasecondary.h" 3 #include "opcuabridge/opcuabridgeclient.h" 4 #include "secondaryconfig.h" 6 #include "logging/logging.h" 7 #include "package_manager/ostreereposync.h" 8 #include "utilities/utils.h" 13 #include <boost/filesystem.hpp> 14 #include <boost/iostreams/device/mapped_file.hpp> 20 OpcuaSecondary::OpcuaSecondary(
const SecondaryConfig& sconfig_in) : SecondaryInterface(sconfig_in) {}
22 OpcuaSecondary::~OpcuaSecondary() =
default;
26 return client.recvConfiguration().getSerial();
32 PublicKey OpcuaSecondary::getPublicKey() {
34 return PublicKey(client.recvConfiguration().getPublicKey(), client.recvConfiguration().getPublicKeyType());
37 Json::Value OpcuaSecondary::getManifest() {
39 auto original_manifest = client.recvOriginalManifest().getBlock();
40 return Utils::parseJSON(std::string(original_manifest.begin(), original_manifest.end()));
43 bool OpcuaSecondary::putMetadata(
const RawMetaPack& meta_pack) {
44 std::vector<opcuabridge::MetadataFile> metadatafiles;
47 mf.setMetadata(meta_pack.director_root);
48 metadatafiles.push_back(mf);
52 mf.setMetadata(meta_pack.director_targets);
53 metadatafiles.push_back(mf);
56 return client.sendMetadataFiles(metadatafiles);
59 bool OpcuaSecondary::sendFirmwareAsync(
const std::shared_ptr<std::string>&
data) {
60 sendEvent(std::make_shared<event::InstallStarted>(getSerial()));
62 Json::Value data_json = Utils::parseJSON(*
data);
64 const fs::path source_repo_dir_path(ostree_repo_sync::GetOstreeRepoPath(data_json[
"sysroot_path"].asString()));
68 sendEvent(std::make_shared<event::InstallComplete>(getSerial()));
73 if (ostree_repo_sync::ArchiveModeRepo(source_repo_dir_path)) {
74 retval = client.syncDirectoryFiles(source_repo_dir_path);
77 const fs::path working_repo_dir_path = temp_dir.Path();
79 if (!ostree_repo_sync::LocalPullRepo(source_repo_dir_path, working_repo_dir_path,
80 data_json[
"ref_hash"].asString())) {
81 LOG_ERROR <<
"OSTree repo sync failed: unable to local pull from " << source_repo_dir_path.native();
82 sendEvent(std::make_shared<event::InstallComplete>(getSerial()));
85 retval = client.syncDirectoryFiles(working_repo_dir_path);
87 sendEvent(std::make_shared<event::InstallComplete>(getSerial()));
91 int OpcuaSecondary::getRootVersion(
bool ) {
92 LOG_ERROR <<
"OpcuaSecondary::getRootVersion is not implemented yet";
96 bool OpcuaSecondary::putRoot(
const std::string& ,
bool ) {
97 LOG_ERROR <<
"OpcuaSecondary::putRoot is not implemented yet";
Base data types that are used in The Update Framework (TUF), part of UPTANE.