in source/config/Config.cpp [1733:1844]
bool Config::ExportDefaultSetting(const string &file)
{
string jsonTemplate = R"({
"%s": "<replace_with_endpoint_value>",
"%s": "<replace_with_certificate_file_path>",
"%s": "<replace_with_private_key_file_path>",
"%s": "<replace_with_root_ca_file_path>",
"%s": "<replace_with_thing_name>",
"%s": {
"%s": "DEBUG",
"%s": "FILE",
"%s": "%s",
"%s": false,
"%s": "TRACE",
"%s": "%s"
},
"%s": {
"%s": true,
"%s": "<replace_with_job_handler_directory_path>"
},
"%s": {
"%s": true
},
"%s": {
"%s": true,
"%s": <replace_with_interval>
},
"%s": {
"%s": false,
"%s": "<replace_with_template_name>",
"%s": "<replace_with_csr_file_path>",
"%s": "<replace_with_device_private_key_file_path>"
},
"%s": {
"%s": {
"%s": false,
"%s": "<replace_with_publish_topic>",
"%s": "<replace_with_publish_file_path>",
"%s": "<replace_with_subscribe_topic>",
"%s": "<replace_with_subscribe_file_path>"
}
},
"%s": {
"%s": false,
"%s": "<replace_with_shadow_name>",
"%s": "<replace_with_shaodw_input_file_path>",
"%s": "<replace_with_shaodw_output_file_path>"
},
"%s": {
"%s": false
}
}
)";
ofstream clientConfig(file);
if (!clientConfig.is_open())
{
LOGM_ERROR(TAG, "Unable to open file: '%s'", Sanitize(file).c_str());
return false;
}
clientConfig << FormatMessage(
jsonTemplate.c_str(),
PlainConfig::JSON_KEY_ENDPOINT,
PlainConfig::JSON_KEY_CERT,
PlainConfig::JSON_KEY_KEY,
PlainConfig::JSON_KEY_ROOT_CA,
PlainConfig::JSON_KEY_THING_NAME,
PlainConfig::JSON_KEY_LOGGING,
PlainConfig::LogConfig::JSON_KEY_LOG_LEVEL,
PlainConfig::LogConfig::JSON_KEY_LOG_TYPE,
PlainConfig::LogConfig::JSON_KEY_LOG_FILE,
FileLogger::DEFAULT_LOG_FILE,
PlainConfig::LogConfig::JSON_KEY_ENABLE_SDK_LOGGING,
PlainConfig::LogConfig::JSON_KEY_SDK_LOG_LEVEL,
PlainConfig::LogConfig::JSON_KEY_SDK_LOG_FILE,
SharedCrtResourceManager::DEFAULT_SDK_LOG_FILE,
PlainConfig::JSON_KEY_JOBS,
PlainConfig::Jobs::JSON_KEY_ENABLED,
PlainConfig::Jobs::JSON_KEY_HANDLER_DIR,
PlainConfig::JSON_KEY_TUNNELING,
PlainConfig::Tunneling::JSON_KEY_ENABLED,
PlainConfig::JSON_KEY_DEVICE_DEFENDER,
PlainConfig::DeviceDefender::JSON_KEY_ENABLED,
PlainConfig::DeviceDefender::JSON_KEY_INTERVAL,
PlainConfig::JSON_KEY_FLEET_PROVISIONING,
PlainConfig::FleetProvisioning::JSON_KEY_ENABLED,
PlainConfig::FleetProvisioning::JSON_KEY_TEMPLATE_NAME,
PlainConfig::FleetProvisioning::JSON_KEY_TEMPLATE_PARAMETERS,
PlainConfig::FleetProvisioning::JSON_KEY_CSR_FILE,
PlainConfig::FleetProvisioning::JSON_KEY_DEVICE_KEY,
PlainConfig::JSON_KEY_SAMPLES,
PlainConfig::JSON_KEY_PUB_SUB,
PlainConfig::PubSub::JSON_ENABLE_PUB_SUB,
PlainConfig::PubSub::JSON_PUB_SUB_PUBLISH_TOPIC,
PlainConfig::PubSub::JSON_PUB_SUB_PUBLISH_FILE,
PlainConfig::PubSub::JSON_PUB_SUB_SUBSCRIBE_TOPIC,
PlainConfig::PubSub::JSON_PUB_SUB_SUBSCRIBE_FILE,
PlainConfig::JSON_KEY_SAMPLE_SHADOW,
PlainConfig::SampleShadow::JSON_ENABLE_SAMPLE_SHADOW,
PlainConfig::SampleShadow::JSON_SAMPLE_SHADOW_NAME,
PlainConfig::SampleShadow::JSON_SAMPLE_SHADOW_INPUT_FILE,
PlainConfig::SampleShadow::JSON_SAMPLE_SHADOW_OUTPUT_FILE,
PlainConfig::JSON_KEY_CONFIG_SHADOW,
PlainConfig::ConfigShadow::JSON_ENABLE_CONFIG_SHADOW);
clientConfig.close();
LOGM_INFO(TAG, "Exported settings to: %s", Sanitize(file).c_str());
chmod(file.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
FileUtils::ValidateFilePermissions(file.c_str(), Permissions::CONFIG_FILE, false);
return true;
}