Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

aktualizr-get: Allow passing HTTP headers #1762

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/aktualizr_get/get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include "http/httpclient.h"
#include "storage/invstorage.h"

std::string aktualizrGet(Config &config, const std::string &url) {
std::string aktualizrGet(Config &config, const std::string &url, const std::vector<std::string> &headers) {
auto storage = INvStorage::newStorage(config.storage);
storage->importData(config.import);

auto client = std_::make_unique<HttpClient>();
auto client = std_::make_unique<HttpClient>(&headers);
KeyManager keys(storage, config.keymanagerConfig());
keys.copyCertsToCurl(*client);
auto resp = client->get(url, HttpInterface::kNoLimit);
Expand Down
2 changes: 1 addition & 1 deletion src/aktualizr_get/get.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include "libaktualizr/config.h"

std::string aktualizrGet(Config &config, const std::string &url);
std::string aktualizrGet(Config &config, const std::string &url, const std::vector<std::string> &headers);

#endif // AKTUALIZR_GET_HELPERS
3 changes: 2 additions & 1 deletion src/aktualizr_get/get_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ TEST(aktualizr_get, good) {
TemporaryDirectory dir;
config.storage.path = dir.Path();

std::string body = aktualizrGet(config, server + "/path/1/2/3");
std::vector<std::string> headers;
std::string body = aktualizrGet(config, server + "/path/1/2/3", headers);
EXPECT_EQ("{\"path\": \"/path/1/2/3\"}", body);
}

Expand Down
7 changes: 6 additions & 1 deletion src/aktualizr_get/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bpo::variables_map parse_options(int argc, char **argv) {
("help,h", "print usage")
("version,v", "Current aktualizr-get version")
("config,c", bpo::value<std::vector<boost::filesystem::path> >()->composing(), "configuration file or directory, by default /var/sota")
("header,H", bpo::value<std::vector<std::string> >()->composing(), "Additional headers to pass")
("loglevel", bpo::value<int>(), "set log level 0-5 (trace, debug, info, warning, error, fatal)")
("url,u", bpo::value<std::string>(), "url to get, mandatory");
// clang-format on
Expand Down Expand Up @@ -65,7 +66,11 @@ int main(int argc, char *argv[]) {
int r = EXIT_FAILURE;
try {
Config config(commandline_map);
std::string body = aktualizrGet(config, commandline_map["url"].as<std::string>());
std::vector<std::string> headers;
if (commandline_map.count("header") == 1) {
headers = commandline_map["header"].as<std::vector<std::string>>();
}
std::string body = aktualizrGet(config, commandline_map["url"].as<std::string>(), headers);
std::cout << body;

r = EXIT_SUCCESS;
Expand Down