in source/config/Config.cpp [74:204]
bool PlainConfig::LoadFromJson(const Crt::JsonView &json)
{
const char *jsonKey = JSON_KEY_ENDPOINT;
if (json.ValueExists(jsonKey))
{
endpoint = json.GetString(jsonKey).c_str();
}
jsonKey = JSON_KEY_CERT;
if (json.ValueExists(jsonKey))
{
if (!json.GetString(jsonKey).empty())
{
cert = FileUtils::ExtractExpandedPath(json.GetString(jsonKey).c_str());
}
else
{
LOGM_WARN(Config::TAG, "Key {%s} was provided in the JSON configuration file with an empty value", jsonKey);
}
}
jsonKey = JSON_KEY_KEY;
if (json.ValueExists(jsonKey))
{
if (!json.GetString(jsonKey).empty())
{
key = FileUtils::ExtractExpandedPath(json.GetString(jsonKey).c_str());
}
else
{
LOGM_WARN(Config::TAG, "Key {%s} was provided in the JSON configuration file with an empty value", jsonKey);
}
}
jsonKey = JSON_KEY_ROOT_CA;
if (json.ValueExists(jsonKey))
{
if (!json.GetString(jsonKey).empty())
{
rootCa = FileUtils::ExtractExpandedPath(json.GetString(jsonKey).c_str());
}
else
{
LOGM_WARN(Config::TAG, "Key {%s} was provided in the JSON configuration file with an empty value", jsonKey);
}
}
jsonKey = JSON_KEY_THING_NAME;
if (json.ValueExists(jsonKey))
{
thingName = json.GetString(jsonKey).c_str();
}
jsonKey = JSON_KEY_JOBS;
if (json.ValueExists(jsonKey))
{
Jobs temp;
temp.LoadFromJson(json.GetJsonObject(jsonKey));
jobs = temp;
}
jsonKey = JSON_KEY_TUNNELING;
if (json.ValueExists(jsonKey))
{
Tunneling temp;
temp.LoadFromJson(json.GetJsonObject(jsonKey));
tunneling = temp;
}
jsonKey = JSON_KEY_DEVICE_DEFENDER;
if (json.ValueExists(jsonKey))
{
DeviceDefender temp;
temp.LoadFromJson(json.GetJsonObject(jsonKey));
deviceDefender = temp;
}
jsonKey = JSON_KEY_FLEET_PROVISIONING;
if (json.ValueExists(jsonKey))
{
FleetProvisioning temp;
temp.LoadFromJson(json.GetJsonObject(jsonKey));
fleetProvisioning = temp;
}
jsonKey = JSON_KEY_RUNTIME_CONFIG;
if (json.ValueExists(jsonKey))
{
FleetProvisioningRuntimeConfig temp;
temp.LoadFromJson(json.GetJsonObject(jsonKey));
fleetProvisioningRuntimeConfig = temp;
}
jsonKey = JSON_KEY_LOGGING;
if (json.ValueExists(jsonKey))
{
LogConfig temp;
temp.LoadFromJson(json.GetJsonObject(jsonKey));
logConfig = temp;
}
jsonKey = JSON_KEY_SAMPLES;
if (json.ValueExists(jsonKey))
{
const char *jsonKeyTwo = JSON_KEY_PUB_SUB;
if (json.ValueExists(jsonKey))
{
PubSub temp;
temp.LoadFromJson(json.GetJsonObject(jsonKey).GetJsonObject(jsonKeyTwo));
pubSub = temp;
}
}
jsonKey = JSON_KEY_SAMPLE_SHADOW;
if (json.ValueExists(jsonKey))
{
SampleShadow temp;
temp.LoadFromJson(json.GetJsonObject(jsonKey));
sampleShadow = temp;
}
jsonKey = JSON_KEY_CONFIG_SHADOW;
if (json.ValueExists(jsonKey))
{
ConfigShadow temp;
temp.LoadFromJson(json.GetJsonObject(jsonKey));
configShadow = temp;
}
return true;
}