in src/AWS.Deploy.Orchestration/DeploymentSettingsHandler.cs [112:169]
public async Task SaveSettings(SaveSettingsConfiguration saveSettingsConfig, Recommendation recommendation, CloudApplication cloudApplication, OrchestratorSession orchestratorSession)
{
if (saveSettingsConfig.SettingsType == SaveSettingsType.None)
{
// We are not throwing an expected exception here as this issue is not caused by the user.
throw new InvalidOperationException($"Cannot persist settings with {SaveSettingsType.None}");
}
if (!_fileManager.IsFileValidPath(saveSettingsConfig.FilePath))
{
var message = $"Failed to save deployment settings because {saveSettingsConfig.FilePath} is invalid or its parent directory does not exist on disk.";
throw new FailedToSaveDeploymentSettingsException(DeployToolErrorCode.FailedToSaveDeploymentSettings, message);
}
var projectDirectory = Path.GetDirectoryName(orchestratorSession.ProjectDefinition.ProjectPath);
if (string.IsNullOrEmpty(projectDirectory))
{
var message = "Failed to save deployment settings because the current deployment session does not have a valid project path";
throw new FailedToSaveDeploymentSettingsException(DeployToolErrorCode.FailedToSaveDeploymentSettings, message);
}
var deploymentSettings = new DeploymentSettings
{
AWSProfile = orchestratorSession.AWSProfileName,
AWSRegion = orchestratorSession.AWSRegion,
ApplicationName = recommendation.Recipe.DeploymentType == DeploymentTypes.ElasticContainerRegistryImage ? null : cloudApplication.Name,
RecipeId = cloudApplication.RecipeId,
Settings = _optionSettingHandler.GetOptionSettingsMap(recommendation, orchestratorSession.ProjectDefinition, _directoryManager)
};
if (saveSettingsConfig.SettingsType == SaveSettingsType.Modified)
{
foreach (var optionSetting in recommendation.GetConfigurableOptionSettingItems())
{
if (!_optionSettingHandler.IsOptionSettingModified(recommendation, optionSetting))
{
deploymentSettings.Settings.Remove(optionSetting.FullyQualifiedId);
}
}
}
try
{
var content = JsonConvert.SerializeObject(deploymentSettings, new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new SerializeModelContractResolver()
});
await _fileManager.WriteAllTextAsync(saveSettingsConfig.FilePath, content);
}
catch (Exception ex)
{
var message = $"Failed to save the deployment settings at {saveSettingsConfig.FilePath} due to the following error: {Environment.NewLine}{ex.Message}";
throw new FailedToSaveDeploymentSettingsException(DeployToolErrorCode.FailedToSaveDeploymentSettings, message, ex);
}
}