void ConfigShadow::resetClientConfigWithJSON()

in source/shadow/ConfigShadow.cpp [255:355]


void ConfigShadow::resetClientConfigWithJSON(
    PlainConfig &config,
    Crt::JsonView &deltaJsonView,
    Crt::JsonView &desiredJsonView)
{
    if (desiredJsonView.ValueExists(PlainConfig::JSON_KEY_JOBS) &&
        deltaJsonView.ValueExists(PlainConfig::JSON_KEY_JOBS))
    {
        PlainConfig::Jobs jobs;
        jobs.LoadFromJson(desiredJsonView.GetJsonObject(PlainConfig::JSON_KEY_JOBS));
        if (jobs.Validate())
        {
            config.jobs = jobs;
        }
        else
        {
            LOGM_WARN(
                TAG,
                "Config shadow contains invalid configurations in %s feature, aborting this feature's configuration "
                "update now. Please check the error logs for more information",
                PlainConfig::JSON_KEY_JOBS);
        }
    }

    if (desiredJsonView.ValueExists(PlainConfig::JSON_KEY_TUNNELING) &&
        deltaJsonView.ValueExists(PlainConfig::JSON_KEY_TUNNELING))
    {
        PlainConfig::Tunneling tunneling;
        tunneling.LoadFromJson(desiredJsonView.GetJsonObject(PlainConfig::JSON_KEY_TUNNELING));
        if (tunneling.Validate())
        {
            config.tunneling = tunneling;
        }
        else
        {
            LOGM_WARN(
                TAG,
                "Config shadow contains invalid configurations in %s feature, aborting this feature's configuration "
                "update now. Please check the error logs for more information",
                PlainConfig::JSON_KEY_TUNNELING);
        }
    }

    if (desiredJsonView.ValueExists(PlainConfig::JSON_KEY_DEVICE_DEFENDER) &&
        deltaJsonView.ValueExists(PlainConfig::JSON_KEY_DEVICE_DEFENDER))
    {
        PlainConfig::DeviceDefender deviceDefender;
        deviceDefender.LoadFromJson(desiredJsonView.GetJsonObject(PlainConfig::JSON_KEY_DEVICE_DEFENDER));
        if (deviceDefender.Validate())
        {
            config.deviceDefender = deviceDefender;
        }
        else
        {
            LOGM_WARN(
                TAG,
                "Config shadow contains invalid configurations in %s feature, aborting this feature's configuration "
                "update now. Please check the error logs for more information",
                PlainConfig::JSON_KEY_DEVICE_DEFENDER);
        }
    }

    if (desiredJsonView.ValueExists(PlainConfig::JSON_KEY_SAMPLES) &&
        deltaJsonView.ValueExists(PlainConfig::JSON_KEY_SAMPLES))
    {
        PlainConfig::PubSub pubSub;
        pubSub.LoadFromJson(
            desiredJsonView.GetJsonObject(PlainConfig::JSON_KEY_SAMPLES).GetJsonObject(PlainConfig::JSON_KEY_PUB_SUB));
        if (pubSub.Validate())
        {
            config.pubSub = pubSub;
        }
        else
        {
            LOGM_WARN(
                TAG,
                "Config shadow contains invalid configurations in %s feature, aborting this feature's configuration "
                "update now. Please check the error logs for more information",
                PlainConfig::JSON_KEY_PUB_SUB);
        }
    }

    if (desiredJsonView.ValueExists(PlainConfig::JSON_KEY_SAMPLE_SHADOW) &&
        deltaJsonView.ValueExists(PlainConfig::JSON_KEY_SAMPLE_SHADOW))
    {
        PlainConfig::SampleShadow sampleShadow;
        sampleShadow.LoadFromJson(desiredJsonView.GetJsonObject(PlainConfig::JSON_KEY_SAMPLE_SHADOW));
        if (sampleShadow.Validate())
        {
            config.sampleShadow = sampleShadow;
        }
        else
        {
            LOGM_WARN(
                TAG,
                "Config shadow contains invalid configurations in %s feature, aborting this feature's configuration "
                "update now. Please check the error logs for more information",
                PlainConfig::JSON_KEY_SAMPLE_SHADOW);
        }
    }
}