55#include < radio/sdr_device_reader.h>
66#include < utils/utils.h>
77
8+ #include < regex>
9+
810constexpr auto LABEL = " config" ;
911
1012spdlog::level::level_enum parseLogLevel (const std::string& level) {
@@ -68,7 +70,11 @@ Config::Config(const nlohmann::json& json, const ArgConfig& argConfig)
6870 m_recordingMinTime(std::chrono::milliseconds(readKey<int >(json, {" recording" , " min_time_ms" }))),
6971 m_recordingTimeout(std::chrono::milliseconds(readKey<int >(json, {" recording" , " max_noise_time_ms" }))),
7072 m_recordingTuningStep(readKey<Frequency>(json, {" recording" , " step" })),
71- m_workers(readKey<int >(json, {" workers" })) {}
73+ m_workers(readKey<int >(json, {" workers" })),
74+ m_apiKey(readKey<std::string>(json, {" api_key" })),
75+ m_latitude(readKey<std::string>(json, {" position" , " latitude" })),
76+ m_longitude(readKey<std::string>(json, {" position" , " longitude" })),
77+ m_altitude(readKey<int >(json, {" position" , " altitude" })) {}
7278
7379Config Config::loadFromFile (const std::string& path, const ArgConfig& argConfig) {
7480 constexpr auto BUFFER_SIZE = 1024 * 1024 ;
@@ -107,6 +113,21 @@ void Config::saveToFile(const std::string& path, const nlohmann::json& json) {
107113 }
108114}
109115
116+ nlohmann::json Config::hideSensitiveData (const nlohmann::json& json) {
117+ nlohmann::json config (json);
118+ try {
119+ if (!config[" api_key" ].empty ()) {
120+ config[" api_key" ] = " ******" ;
121+ }
122+ std::regex regex (R"( ^(\d+)\.\d+)" );
123+ config[" position" ][" latitude" ] = std::regex_replace (config[" position" ][" latitude" ].get <std::string>(), regex, " $1.********" );
124+ config[" position" ][" longitude" ] = std::regex_replace (config[" position" ][" longitude" ].get <std::string>(), regex, " $1.********" );
125+ } catch (const std::exception& exception) {
126+ Logger::warn (LABEL, " hide sensitive data exception: {}" , colored (RED, " {}" , exception.what ()));
127+ }
128+ return config;
129+ }
130+
110131nlohmann::json Config::json () const { return m_json; }
111132std::string Config::mqtt () const { return fmt::format (" {}@{}" , m_argConfig.mqttUser , m_argConfig.mqttUrl ); };
112133
@@ -131,3 +152,8 @@ Frequency Config::recordingTuningStep() const { return m_recordingTuningStep; }
131152std::string Config::mqttUrl () const { return m_argConfig.mqttUrl ; }
132153std::string Config::mqttUsername () const { return m_argConfig.mqttUser ; }
133154std::string Config::mqttPassword () const { return m_argConfig.mqttPassword ; }
155+
156+ std::string Config::apiKey () const { return m_apiKey; }
157+ std::string Config::latitude () const { return m_latitude; }
158+ std::string Config::longitude () const { return m_longitude; }
159+ int Config::altitude () const { return m_altitude; }
0 commit comments