4 #include <boost/filesystem.hpp>
5 #include <boost/program_options.hpp>
8 #include "accumulator.h"
9 #include "authenticate.h"
12 #include "garage_tools_version.h"
13 #include "logging/logging.h"
14 #include "ostree_http_repo.h"
15 #include "ostree_object.h"
16 #include "request_pool.h"
17 #include "treehub_server.h"
19 #include "utilities/utils.h"
21 namespace po = boost::program_options;
23 int main(
int argc,
char **argv) {
28 boost::filesystem::path credentials_path;
30 int max_curl_requests;
32 po::options_description desc(
"garage-check command line options");
35 (
"help",
"print usage")
36 (
"version",
"Current garage-check version")
37 (
"verbose,v", accumulator<int>(&verbosity),
"Verbose logging (use twice for more information)")
38 (
"quiet,q",
"Quiet mode")
39 (
"ref,r", po::value<std::string>(&ref)->required(),
"refhash to check")
40 (
"credentials,j", po::value<boost::filesystem::path>(&credentials_path)->required(),
"credentials (json or zip containing json)")
41 (
"cacert", po::value<std::string>(&cacerts),
"override path to CA root certificates, in the same format as curl --cacert")
42 (
"jobs", po::value<int>(&max_curl_requests)->default_value(30),
"maximum number of parallel requests (only relevant with --walk-tree)")
43 (
"walk-tree,w",
"walk entire tree and check presence of all objects");
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();
70 if (static_cast<int>(vm.count(
"quiet")) != 0) {
71 logger_set_threshold(boost::log::trivial::warning);
73 logger_set_threshold(boost::log::trivial::info);
75 }
else if (verbosity == 1) {
76 logger_set_threshold(boost::log::trivial::debug);
77 LOG_DEBUG <<
"Debug level debugging enabled";
78 }
else if (verbosity > 1) {
79 logger_set_threshold(boost::log::trivial::trace);
80 LOG_TRACE <<
"Trace level debugging enabled";
85 Utils::setUserAgent(std::string(
"garage-check/") + garage_tools_version());
87 if (vm.count(
"walk-tree") != 0u) {
91 if (max_curl_requests < 1) {
92 LOG_FATAL <<
"--jobs must be greater than 0";
97 if (authenticate(cacerts,
ServerCredentials(credentials_path), treehub) != EXIT_SUCCESS) {
98 LOG_FATAL <<
"Authentication failed";
102 if (CheckRefValid(treehub, ref, mode, max_curl_requests) != EXIT_SUCCESS) {
103 LOG_FATAL <<
"Check if the ref is present on the server or in targets.json failed";
106 }
catch (std::exception &ex) {
107 LOG_ERROR <<
"Exception: " << ex.what();
110 LOG_ERROR <<
"Unknown exception";