Clearing Data On Export
Your device(s) may contain sensitive information (database connection strings), or context-specific configuration data (a reference to a specific local resource). If you want to clear out specific fields when a device is exported, you can do so with the following code.
Sensitive data should be encrypted within your device configuration. Configuration remains encrypted during export (and within a channel file) and is not viewable upon import in Connexion. Clearing configuration is usually done to protect against accidentally starting a newly imported channel which has incorrect configuration information (referencing a different customer, accessing a specific folder, etc.)
The OnBeforeExport
method in the ConfigurationFactory
class is used to clear configuration data.
public override string OnBeforeExport(string configuration, StringBuilder warnings)
{
// deserialize the configuration string into a configuratino object
var config = SerializationEx.Deserialize<FtpDeviceConfiguration>(configuration);
var updated = false;
// the ShouldReplaceValue method checks for null/empty as well as
// global values. Globals are not cleared
// This method is available in >= v16.1
if (ShouldReplaceValue(config.SomeStringProperty))
{
config.SomeStringProperty = string.Empty;
warnings.AppendLine("SomeStringProperty has been cleared.");
updated = true;
}
// serialize the cleared configuration, if we cleared something
return updated ? SerializationEx.Serialize(config, false) : configuration;
}