#include #include #include "client/grpc/GrpcClient.hh" #include #include "common/StringConversion.hh" int usage(const char* prog) { fprintf(stderr, "usage: %s [--key " "--cert " "--ca ] " "[--endpoint ] [--token ] [--export ] [--depth ] [--select ] [-f | -d] \n", prog); fprintf(stderr, " is setup as \"key1:val1,key2:val2,key3:val3 ... where keyN:valN is one of \n"); fprintf(stderr, "" " owner-root:1|0\n" " group-root:1|0\n" " owner:\n" " group:\n" " regex-filename:\n" " regex-dirname:\n" " zero-size:1|0\n" " min-size:\n" " max-size:\n" " min-children:\n" " max-children:\n" " zero-children:1|0\n" " min-locations:\n" " max-locations:\n" " zero-locations:1|0\n" " min-unlinked_locations:\n" " max-unlinked_locations:\n" " max-treesize:\n" " zero-treesize:1|0\n" " min-ctime:\n" " max-ctime:\n" " zero-ctime:1|0\n" " min-mtime:\n" " max-mtime:\n" " zero-mtime:1|0\n" " min-stime:\n" " max-stime:\n" " zero-stime:1|0\n" " layoutid:\n" " flags:\n" " symlink:1|0\n" " checksum-type:\n" " checksum-value:\n" " xattr:=\n"); return -1; } int main(int argc, const char* argv[]) { std::string endpoint = "localhost:50051"; std::string token = ""; std::string key; std::string cert; std::string ca; std::string keyfile; std::string certfile; std::string cafile; std::string path = ""; std::string select; bool files = false; bool dirs = false; uint64_t depth = 1024; std::string exportfs = ""; for (auto i = 1; i < argc; ++i) { std::string option = argv[i]; if (option == "--key") { if (argc > i + 1) { keyfile = argv[i + 1]; ++i; continue; } else { return usage(argv[0]); } } if (option == "--cert") { if (argc > i + 1) { certfile = argv[i + 1]; ++i; continue; } else { return usage(argv[0]); } } if (option == "--ca") { if (argc > i + 1) { cafile = argv[i + 1]; ++i; continue; } else { return usage(argv[0]); } } if (option == "--endpoint") { if (argc > i + 1) { endpoint = argv[i + 1]; ++i; continue; } else { return usage(argv[0]); } } if (option == "--token") { if (argc > i + 1) { token = argv[i + 1]; ++i; continue; } else { return usage(argv[0]); } } if (option == "--export") { if (argc > i + 1) { exportfs = argv[i + 1]; ++i; continue; } else { return usage(argv[0]); } } if (option == "--depth") { if (argc > i + 1) { depth = strtoull(argv[i + 1],0,10); ++i; continue; } else { return usage(argv[0]); } } if (option == "--select") { if (argc > i + 1) { select = argv[i+1]; ++i; continue; } else { return usage(argv[0]); } } if (option == "-f") { files = true; continue; } if (option == "-d") { dirs = true; continue; } path = option; if (argc > (i + 1)) { return usage(argv[0]); } } if (!files && ! dirs) { files = true; dirs = true; } if (keyfile.length() || certfile.length() || cafile.length()) { if (!keyfile.length() || !certfile.length() || !cafile.length()) { return usage(argv[0]); } } if (path.empty()) { return usage(argv[0]); } if (path.front() != '/') { return usage(argv[0]); } std::unique_ptr eosgrpc = eos::client::GrpcClient::Create( endpoint, token, keyfile, certfile, cafile); if (!eosgrpc) { return usage(argv[0]); } std::chrono::steady_clock::time_point watch_global = std::chrono::steady_clock::now(); std::string reply = eosgrpc->Find(path, select, 0, 0, files, dirs, depth, true, exportfs); std::chrono::microseconds elapsed_global = std::chrono::duration_cast (std::chrono::steady_clock::now() - watch_global); std::cout << "request took " << elapsed_global.count() << " micro seconds" << std::endl; return 0; }