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 boost::filesystem::path tree_dir;
33 po::options_description desc(
"garage-check command line options");
36 (
"help",
"print usage")
37 (
"version",
"Current garage-check version")
38 (
"verbose,v", accumulator<int>(&verbosity),
"Verbose logging (use twice for more information)")
39 (
"quiet,q",
"Quiet mode")
40 (
"ref,r", po::value<std::string>(&ref)->required(),
"refhash to check")
41 (
"credentials,j", po::value<boost::filesystem::path>(&credentials_path)->required(),
"credentials (json or zip containing json)")
42 (
"cacert", po::value<std::string>(&cacerts),
"override path to CA root certificates, in the same format as curl --cacert")
43 (
"jobs", po::value<int>(&max_curl_requests)->default_value(30),
"maximum number of parallel requests (only relevant with --walk-tree)")
44 (
"walk-tree,w",
"walk entire tree and check presence of all objects")
45 (
"tree-dir,t", po::value<boost::filesystem::path>(&tree_dir),
"directory to which to write the tree (only used with --walk-tree)");
51 po::store(po::parse_command_line(argc, reinterpret_cast<const char *const *>(argv), desc), vm);
53 if (vm.count(
"help") != 0u) {
57 if (vm.count(
"version") != 0) {
58 LOG_INFO <<
"Current garage-check version is: " << garage_tools_version();
62 }
catch (
const po::error &o) {
63 LOG_ERROR << o.what();
72 if (static_cast<int>(vm.count(
"quiet")) != 0) {
73 logger_set_threshold(boost::log::trivial::warning);
75 logger_set_threshold(boost::log::trivial::info);
77 }
else if (verbosity == 1) {
78 logger_set_threshold(boost::log::trivial::debug);
79 LOG_DEBUG <<
"Debug level debugging enabled";
80 }
else if (verbosity > 1) {
81 logger_set_threshold(boost::log::trivial::trace);
82 LOG_TRACE <<
"Trace level debugging enabled";
87 Utils::setUserAgent(std::string(
"garage-check/") + garage_tools_version());
89 if (vm.count(
"walk-tree") != 0u) {
93 if (max_curl_requests < 1) {
94 LOG_FATAL <<
"--jobs must be greater than 0";
99 if (authenticate(cacerts,
ServerCredentials(credentials_path), treehub) != EXIT_SUCCESS) {
100 LOG_FATAL <<
"Authentication failed";
104 if (CheckRefValid(treehub, ref, mode, max_curl_requests, tree_dir) != EXIT_SUCCESS) {
105 LOG_FATAL <<
"Check if the ref is present on the server or in targets.json failed";
108 }
catch (std::exception &ex) {
109 LOG_ERROR <<
"Exception: " << ex.what();
112 LOG_ERROR <<
"Unknown exception";