diff --git a/src/libaktualizr/campaign/campaign.cc b/src/libaktualizr/campaign/campaign.cc index 1341e6b96b..7e0b8443ec 100644 --- a/src/libaktualizr/campaign/campaign.cc +++ b/src/libaktualizr/campaign/campaign.cc @@ -68,7 +68,7 @@ void Campaign::getJson(Json::Value &out) const { out["metadata"][2]["value"] = std::to_string(estPreparationDuration); } -std::vector campaignsFromJson(const Json::Value &json) { +std::vector Campaign::campaignsFromJson(const Json::Value &json) { std::vector campaigns; Json::Value campaigns_array; @@ -95,7 +95,7 @@ std::vector campaignsFromJson(const Json::Value &json) { return campaigns; } -void JsonFromCampaigns(const std::vector &in, Json::Value &out) { +void Campaign::JsonFromCampaigns(const std::vector &in, Json::Value &out) { out.clear(); auto i = 0; Json::Value json; @@ -106,7 +106,7 @@ void JsonFromCampaigns(const std::vector &in, Json::Value &out) { } } -std::vector fetchAvailableCampaigns(HttpInterface &http_client, const std::string &tls_server) { +std::vector Campaign::fetchAvailableCampaigns(HttpInterface &http_client, const std::string &tls_server) { HttpResponse response = http_client.get(tls_server + "/campaigner/campaigns", kMaxCampaignsMetaSize); if (!response.isOk()) { LOG_ERROR << "Failed to fetch list of available campaigns"; diff --git a/src/libaktualizr/campaign/campaign.h b/src/libaktualizr/campaign/campaign.h index cb91f1d9a6..85cccc633f 100644 --- a/src/libaktualizr/campaign/campaign.h +++ b/src/libaktualizr/campaign/campaign.h @@ -29,6 +29,11 @@ static inline Cmd cmdFromName(const std::string &name) { // Out of uptane concept: update campaign for a device class Campaign { + public: + static std::vector campaignsFromJson(const Json::Value &json); + static void JsonFromCampaigns(const std::vector &in, Json::Value &out); + static std::vector fetchAvailableCampaigns(HttpInterface &http_client, const std::string &tls_server); + public: Campaign() = default; Campaign(const Json::Value &json); @@ -43,9 +48,6 @@ class Campaign { int estPreparationDuration{0}; }; -std::vector campaignsFromJson(const Json::Value &json); -void JsonFromCampaigns(const std::vector &in, Json::Value &out); -std::vector fetchAvailableCampaigns(HttpInterface &http_client, const std::string &tls_server); } // namespace campaign #endif diff --git a/src/libaktualizr/campaign/campaign_test.cc b/src/libaktualizr/campaign/campaign_test.cc index e1a3dfd5a7..21be1c7153 100644 --- a/src/libaktualizr/campaign/campaign_test.cc +++ b/src/libaktualizr/campaign/campaign_test.cc @@ -10,7 +10,7 @@ boost::filesystem::path test_data_dir; TEST(campaign, Campaigns_from_json) { auto json = Utils::parseJSONFile(test_data_dir / "campaigns_sample.json"); - auto campaigns = campaign::campaignsFromJson(json); + auto campaigns = campaign::Campaign::campaignsFromJson(json); EXPECT_EQ(campaigns.size(), 1); EXPECT_EQ(campaigns.at(0).name, "campaign1"); @@ -27,7 +27,7 @@ TEST(campaign, Campaigns_from_json) { bad4["campaigns"][0] = Json::Value(); bad4["campaigns"][0]["name"] = "a"; bad4["campaigns"][0]["id"] = "a"; - auto campaignsNoAutoAccept = campaign::campaignsFromJson(bad4); + auto campaignsNoAutoAccept = campaign::Campaign::campaignsFromJson(bad4); EXPECT_FALSE(campaignsNoAutoAccept.at(0).autoAccept); } @@ -35,9 +35,9 @@ TEST(campaign, Campaigns_from_json) { TEST(campaign, Campaigns_to_json) { auto json = Utils::parseJSONFile(test_data_dir / "campaigns_sample.json"); - auto campaigns = campaign::campaignsFromJson(json); + auto campaigns = campaign::Campaign::campaignsFromJson(json); Json::Value res; - JsonFromCampaigns(campaigns, res); + campaign::Campaign::JsonFromCampaigns(campaigns, res); EXPECT_EQ(res["campaigns"][0]["name"], "campaign1"); EXPECT_EQ(res["campaigns"][0]["id"], "c2eb7e8d-8aa0-429d-883f-5ed8fdb2a493"); @@ -53,27 +53,27 @@ TEST(campaign, Campaigns_to_json) { TEST(campaign, Campaigns_from_invalid_json) { // empty object - EXPECT_EQ(campaign::campaignsFromJson(Json::Value()).size(), 0); + EXPECT_EQ(campaign::Campaign::campaignsFromJson(Json::Value()).size(), 0); // naked array - EXPECT_EQ(campaign::campaignsFromJson(Json::Value(Json::arrayValue)).size(), 0); + EXPECT_EQ(campaign::Campaign::campaignsFromJson(Json::Value(Json::arrayValue)).size(), 0); // object in object Json::Value bad1; bad1["campaigns"] = Json::Value(); - EXPECT_EQ(campaign::campaignsFromJson(bad1).size(), 0); + EXPECT_EQ(campaign::Campaign::campaignsFromJson(bad1).size(), 0); // array in array in object Json::Value bad2; bad2["campaigns"] = Json::Value(Json::arrayValue); bad2["campaigns"][0] = Json::Value(Json::arrayValue); - EXPECT_EQ(campaign::campaignsFromJson(bad2).size(), 0); + EXPECT_EQ(campaign::Campaign::campaignsFromJson(bad2).size(), 0); // no name Json::Value bad3; bad3["campaigns"] = Json::Value(Json::arrayValue); bad3["campaigns"][0] = Json::Value(); - EXPECT_EQ(campaign::campaignsFromJson(bad3).size(), 0); + EXPECT_EQ(campaign::Campaign::campaignsFromJson(bad3).size(), 0); } #ifndef __NO_MAIN__ diff --git a/src/libaktualizr/primary/sotauptaneclient.cc b/src/libaktualizr/primary/sotauptaneclient.cc index 4a7f4e9494..add86c96b0 100644 --- a/src/libaktualizr/primary/sotauptaneclient.cc +++ b/src/libaktualizr/primary/sotauptaneclient.cc @@ -931,7 +931,7 @@ result::Install SotaUptaneClient::uptaneInstall(const std::vector