MCPcopy Create free account
hub / github.com/GDATASoftwareAG/vaas / main

Function main

cpp/main.cpp:6–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <string>
5
6int main(int argc, char* argv[]) {
7 if (argc < 2) {
8 std::cout << "Usage: " << argv[0] << " [PATH]..." << std::endl;
9 exit(1);
10 }
11
12 const auto vaasUrl = std::getenv("VAAS_URL")
13 ? std::getenv("VAAS_URL")
14 : "https://gateway.staging.vaas.gdatasecurity.de";
15 const auto tokenUrl = std::getenv("TOKEN_URL")
16 ? std::getenv("TOKEN_URL")
17 : "https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token";
18 const auto clientId = std::getenv("CLIENT_ID")
19 ? std::getenv("CLIENT_ID")
20 : throw std::runtime_error("CLIENT_ID must be set");
21 const auto clientSecret = std::getenv("CLIENT_SECRET")
22 ? std::getenv("CLIENT_SECRET")
23 : throw std::runtime_error("CLIENT_SECRET must be set");
24
25 try {
26 vaas::Vaas vaas(vaasUrl, tokenUrl, clientId, clientSecret);
27
28 for (int i = 1; i < argc; ++i) {
29 std::filesystem::path fileOrDirectory(argv[i]);
30
31 if (std::filesystem::is_directory(fileOrDirectory)) {
32 for (const auto& entry : std::filesystem::recursive_directory_iterator(fileOrDirectory)) {
33 if (entry.is_regular_file()) {
34 const auto report = vaas.forFile(entry);
35 std::cout << entry << " " << report << std::endl;
36 }
37 }
38 } else {
39 const auto report = vaas.forFile(fileOrDirectory);
40 std::cout << fileOrDirectory << " " << report << std::endl;
41 }
42 }
43 } catch (const vaas::VaasException& e) {
44 // Some issue talking to VaaS, retry later
45 std::cerr << "VaaS error: " << e.what() << std::endl;
46 } catch (const vaas::AuthenticationException& e) {
47 // We need to check our credentials before trying again
48 std::cerr << "Authentication error - check your credentials: " << e.what() << std::endl;
49 } catch (const std::runtime_error& e) {
50 // Other error (filesystem, critical init failure - retry with care)
51 std::cerr << "Problem: " << e.what() << std::endl;
52 }
53 return 0;
54}

Callers

nothing calls this directly

Calls 1

forFileMethod · 0.65

Tested by

no test coverage detected