in src/AWS.Deploy.Orchestration/LocalUserSettings/LocalUserSettingsEngine.cs [42:113]
public async Task UpdateLastDeployedStack(string stackName, string projectName, string? awsAccountId, string? awsRegion)
{
try
{
if (string.IsNullOrEmpty(projectName))
throw new FailedToUpdateLocalUserSettingsFileException(DeployToolErrorCode.FailedToUpdateLocalUserSettingsFile, "The Project Name is not defined.");
if (string.IsNullOrEmpty(awsAccountId) || string.IsNullOrEmpty(awsRegion))
throw new FailedToUpdateLocalUserSettingsFileException(DeployToolErrorCode.FailedToUpdateLocalUserSettingsFile, "The AWS Account Id or Region is not defined.");
var localUserSettings = await GetLocalUserSettings();
var lastDeployedStack = localUserSettings?.LastDeployedStacks?
.FirstOrDefault(x => x.Exists(awsAccountId, awsRegion, projectName));
if (localUserSettings != null)
{
if (lastDeployedStack != null)
{
if (lastDeployedStack.Stacks == null)
{
lastDeployedStack.Stacks = new List<string> { stackName };
}
else
{
if (!lastDeployedStack.Stacks.Contains(stackName))
lastDeployedStack.Stacks.Add(stackName);
lastDeployedStack.Stacks.Sort();
}
}
else
{
var currentStack = new LastDeployedStack(
awsAccountId,
awsRegion,
projectName,
new List<string>()
{
stackName
});
if (localUserSettings.LastDeployedStacks == null)
{
localUserSettings.LastDeployedStacks = new List<LastDeployedStack>() { currentStack };
}
else
{
localUserSettings.LastDeployedStacks.Add(currentStack);
}
}
}
else
{
var lastDeployedStacks = new List<LastDeployedStack> {
new LastDeployedStack(
awsAccountId,
awsRegion,
projectName,
new List<string>() { stackName }) };
localUserSettings = new LocalUserSettings
{
LastDeployedStacks = lastDeployedStacks
};
}
await WriteLocalUserSettingsFile(localUserSettings);
}
catch (Exception ex)
{
throw new FailedToUpdateLocalUserSettingsFileException(DeployToolErrorCode.FailedToUpdateLocalUserSettingsFile, $"Failed to update the local user settings file " +
$"to include the last deployed to stack '{stackName}'.", ex);
}
}