@@ -374,16 +374,37 @@ void ConfigShadow::resetClientConfigWithJSON(
374
374
}
375
375
}
376
376
377
- // Save the updated configuration to a local file for persistence
378
- JsonObject jsonObj;
379
- config.SerializeToObject (jsonObj);
380
-
381
- const char * jsonStr = jsonObj.View ().WriteReadable ().c_str ();
382
- LOGM_INFO (TAG, " Updating device configuration files with the following: %s" , jsonStr);
377
+ if (desiredJsonView.ValueExists (PlainConfig::JSON_KEY_CONFIG_SHADOW) &&
378
+ deltaJsonView.ValueExists (PlainConfig::JSON_KEY_CONFIG_SHADOW))
379
+ {
380
+ PlainConfig::ConfigShadow configShadow;
381
+ configShadow.LoadFromJson (desiredJsonView.GetJsonObject (PlainConfig::JSON_KEY_CONFIG_SHADOW));
382
+ if (configShadow.Validate ())
383
+ {
384
+ config.configShadow = configShadow;
385
+ }
386
+ else
387
+ {
388
+ LOGM_WARN (
389
+ TAG,
390
+ " Config shadow contains invalid configurations in %s feature, aborting this feature's configuration "
391
+ " update now. Please check the error logs for more information" ,
392
+ PlainConfig::JSON_KEY_CONFIG_SHADOW);
393
+ }
394
+ }
383
395
384
- string userConfig = FileUtils::ExtractExpandedPath (Config::DEFAULT_CONFIG_FILE);
385
- updateLocalConfigFile (config, userConfig.c_str ());
386
- updateLocalConfigFile (config, Config::DEFAULT_ROOT_CONFIG_FILE);
396
+ // Save the updated configuration to a local file for persistence if required
397
+ if (config.configShadow .persistentUpdate )
398
+ {
399
+ JsonObject jsonObj;
400
+ config.SerializeToObject (jsonObj);
401
+ const char * jsonStr = jsonObj.View ().WriteReadable ().c_str ();
402
+ LOGM_INFO (TAG, " Updating device configuration files with the following config shadow update: %s" , jsonStr);
403
+
404
+ string userConfig = FileUtils::ExtractExpandedPath (Config::DEFAULT_CONFIG_FILE);
405
+ updateLocalConfigFile (config, userConfig.c_str ());
406
+ updateLocalConfigFile (config, Config::DEFAULT_ROOT_CONFIG_FILE);
407
+ }
387
408
}
388
409
389
410
void ConfigShadow::updateShadowWithLocalConfig (Iotshadow::IotShadowClient iotShadowClient, PlainConfig &config)
0 commit comments