MCPcopy Create free account
hub / github.com/ReversecLabs/C3 / ReadGatewayConfigurationFile

Function ReadGatewayConfigurationFile

Src/Core/BackendCommons.cpp:69–89  ·  view source on GitHub ↗

Obtains Gateway's configuration. @param configurationFilePath path to the configuration file. @return std::tuple with read configuration.

Source from the content-addressed store, hash-verified

67 /// @param configurationFilePath path to the configuration file.
68 /// @return std::tuple with read configuration.
69 auto ReadGatewayConfigurationFile(std::filesystem::path const& configurationFilePath)
70 {
71 // Parse json configuration file.
72 if (!std::filesystem::exists(configurationFilePath))
73 throw std::invalid_argument{ OBF("Gateway configuration file not found.") };
74 auto configuration = json::parse(std::ifstream{ configurationFilePath, std::ios::in });
75
76 // Unfortunetly json::value throws for most value_types. This helper will return default in such case.
77 auto jsonValueClosure = [&configuration](auto const& key, auto const& defaultValue)
78 {
79 return configuration.is_object() ? configuration.value(key, defaultValue) : defaultValue; };
80
81 return std::make_tuple
82 (
83 jsonValueClosure(OBF("API Bridge IP"), OBF("127.0.0.1")),
84 jsonValueClosure(OBF("API Bridge port"), std::uint16_t{ 2323 }),
85 FSecure::C3::BuildId{ jsonValueClosure(OBF("BuildId"), FSecure::C3::BuildId::GenerateRandom().ToString()) },
86 FSecure::C3::AgentId{ jsonValueClosure(OBF("AgentId"), FSecure::C3::AgentId::GenerateRandom().ToString()) },
87 jsonValueClosure("Name", "")
88 );
89 }
90}
91
92////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Calls 3

parseFunction · 0.85
valueMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected