4 #include <boost/filesystem.hpp>
5 #include <boost/program_options.hpp>
7 #include "authenticate.h"
10 #include "garage_tools_version.h"
12 #include "logging/logging.h"
13 #include "ostree_http_repo.h"
14 #include "ostree_object.h"
15 #include "request_pool.h"
16 #include "treehub_server.h"
17 #include "utilities/utils.h"
19 namespace po = boost::program_options;
21 int main(
int argc,
char **argv) {
25 boost::filesystem::path credentials_path;
27 int max_curl_requests;
29 boost::filesystem::path tree_dir;
30 po::options_description desc(
"garage-check command line options");
33 (
"help",
"print usage")
34 (
"version",
"Current garage-check version")
35 (
"verbose,v",
"Verbose logging (loglevel 1)")
36 (
"quiet,q",
"Quiet mode (loglevel 3)")
37 (
"loglevel", po::value<int>(),
"set log level 0-5 (trace, debug, info, warning, error, fatal)")
38 (
"ref,r", po::value<std::string>(&ref)->required(),
"refhash to check")
39 (
"credentials,j", po::value<boost::filesystem::path>(&credentials_path)->required(),
"credentials (json or zip containing json)")
40 (
"cacert", po::value<std::string>(&cacerts),
"override path to CA root certificates, in the same format as curl --cacert")
41 (
"jobs", po::value<int>(&max_curl_requests)->default_value(30),
"maximum number of parallel requests (only relevant with --walk-tree)")
42 (
"walk-tree,w",
"walk entire tree and check presence of all objects")
43 (
"tree-dir,t", po::value<boost::filesystem::path>(&tree_dir),
"directory to which to write the tree (only used with --walk-tree)");
49 po::store(po::parse_command_line(argc,
reinterpret_cast<const char *
const *
>(argv), desc), vm);
51 if (vm.count(
"help") != 0U) {
55 if (vm.count(
"version") != 0) {
56 LOG_INFO <<
"Current garage-check version is: " << garage_tools_version();
60 }
catch (
const po::error &o) {
61 LOG_ERROR << o.what();
68 if (vm.count(
"loglevel") != 0) {
69 const int loglevel = vm[
"loglevel"].as<
int>();
70 logger_set_threshold(
static_cast<boost::log::trivial::severity_level
>(loglevel));
71 LOG_INFO <<
"Loglevel set to " << loglevel;
72 }
else if (
static_cast<int>(vm.count(
"verbose")) != 0) {
73 logger_set_threshold(boost::log::trivial::debug);
74 LOG_DEBUG <<
"Debug level debugging enabled";
75 }
else if (
static_cast<int>(vm.count(
"quiet")) != 0) {
76 logger_set_threshold(boost::log::trivial::warning);
78 logger_set_threshold(boost::log::trivial::info);
81 Utils::setUserAgent(std::string(
"garage-check/") + garage_tools_version());
83 if (vm.count(
"walk-tree") != 0U) {
87 if (max_curl_requests < 1) {
88 LOG_FATAL <<
"--jobs must be greater than 0";
93 if (authenticate(cacerts,
ServerCredentials(credentials_path), treehub) != EXIT_SUCCESS) {
94 LOG_FATAL <<
"Authentication failed";
98 if (CheckRefValid(treehub, ref, mode, max_curl_requests, tree_dir) != EXIT_SUCCESS) {
99 LOG_FATAL <<
"Check if the ref is present on the server or in targets.json failed";
102 }
catch (std::exception &ex) {
103 LOG_ERROR <<
"Exception: " << ex.what();
106 LOG_ERROR <<
"Unknown exception";