Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a76aaf4
Add support for Tail and refactor code for new SDK version
Xynoclafe Apr 29, 2020
ebf173a
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe May 4, 2020
40a181e
Added test cases
Xynoclafe May 5, 2020
a35d02d
Edited test cases
Xynoclafe May 6, 2020
347a071
Re-record test cases
Xynoclafe May 6, 2020
c083a11
Modify help files
Xynoclafe May 6, 2020
5ac2761
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe May 7, 2020
28a60b8
Review fixes
Xynoclafe May 13, 2020
abf676b
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe May 13, 2020
d645140
Fix CLI test case
Xynoclafe May 13, 2020
ffe2e6c
Fix missing file name in the message shown when file already exists -…
Xynoclafe May 14, 2020
bf2a72f
Change parameter name from DeploymentScriptInputObject to DeploymentS…
Xynoclafe May 14, 2020
ae7bed4
Fix missing target name in what if result - Performing the operation …
Xynoclafe May 14, 2020
3e0222f
Format output property for cmdlet output
Xynoclafe May 15, 2020
4fcc53c
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe May 18, 2020
54ef5ee
Edit output formatting; newline character fix; Update changelog
Xynoclafe May 19, 2020
34cbb60
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe May 19, 2020
6ca5152
Add alias to avoid a breaking change
Xynoclafe May 19, 2020
4b5c264
Modify help files
Xynoclafe May 19, 2020
a1ee192
Update row format
Xynoclafe May 20, 2020
5fa5656
Use StringReader for newline formatting
Xynoclafe May 20, 2020
172fbf7
Update ChangeLog.md
VeryEarly May 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ public class GetAzDeploymentScriptLog : DeploymentScriptCmdletBase
[ResourceIdCompleter("Microsoft.Resources/deploymentScripts")]
public string DeploymentScriptResourceId { get; set; }

[Alias("DeploymentScriptInputObject")]
[Parameter(Position = 0, ParameterSetName = GetDeploymentScriptLogByInputObject, Mandatory = true, ValueFromPipeline = true,
HelpMessage = "The deployment script PowerShell object.")]
[ValidateNotNullOrEmpty]
public PsDeploymentScript DeploymentScriptInputObject { get; set; }
public PsDeploymentScript DeploymentScriptObject { get; set; }

[Parameter(Position = 2, ParameterSetName = GetDeploymentScriptLogByName, Mandatory = false, HelpMessage = "Limit output to last n lines")]
[Parameter(Position = 1, ParameterSetName = GetDeploymentScriptLogByResourceId, Mandatory = false, HelpMessage = "Limit output to last n lines")]
Expand Down Expand Up @@ -81,8 +82,8 @@ public override void ExecuteCmdlet()
break;
case GetDeploymentScriptLogByInputObject:
deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(
DeploymentScriptInputObject.Name,
ResourceIdUtility.GetResourceGroupName(DeploymentScriptInputObject.Id),
DeploymentScriptObject.Name,
ResourceIdUtility.GetResourceGroupName(DeploymentScriptObject.Id),
tailParam);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,31 @@ public override void ExecuteCmdlet()
{
try
{
string scriptName = "";

switch (ParameterSetName)
{
case RemoveDeploymentScriptByName:
if (ShouldProcess(Name, "Remove Deployment Script"))
scriptName = Name;
if (ShouldProcess(scriptName, "Remove Deployment Script"))
{
DeploymentScriptsSdkClient.DeleteDeploymentScript(Name, ResourceGroupName);
DeploymentScriptsSdkClient.DeleteDeploymentScript(scriptName, ResourceGroupName);
}
break;
case RemoveDeploymentScriptByResourceId:
if (ShouldProcess(Name, "Remove Deployment Script"))
scriptName = ResourceIdUtility.GetResourceName(this.Id);
if (ShouldProcess(scriptName, "Remove Deployment Script"))
{
DeploymentScriptsSdkClient.DeleteDeploymentScript( ResourceIdUtility.GetResourceName(this.Id),
DeploymentScriptsSdkClient.DeleteDeploymentScript(scriptName,
ResourceIdUtility.GetResourceGroupName(this.Id));
}
break;
case RemoveDeploymentScriptByInputObject:
if (ShouldProcess(Name, "Remove Deployment Script"))
scriptName = InputObject.Name;
if (ShouldProcess(scriptName, "Remove Deployment Script"))
{
DeploymentScriptsSdkClient.DeleteDeploymentScript(InputObject.Name, ResourceIdUtility.GetResourceGroupName(InputObject.Id));
DeploymentScriptsSdkClient.DeleteDeploymentScript(scriptName,
ResourceIdUtility.GetResourceGroupName(InputObject.Id));
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System;
using System.IO;
using System.Management.Automation;
using System.Text;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
Expand Down Expand Up @@ -53,11 +54,12 @@ public class SaveAzDeploymentScriptLog : DeploymentScriptCmdletBase
[ResourceIdCompleter("Microsoft.Resources/deploymentScripts")]
public string DeploymentScriptResourceId { get; set; }

[Alias("DeploymentScriptInputObject")]
[Parameter(Position = 0, ParameterSetName = SaveDeploymentScriptLogByInputObject, Mandatory = true,
ValueFromPipeline = true,
HelpMessage = "The deployment script PowerShell object.")]
[ValidateNotNullOrEmpty]
public PsDeploymentScript DeploymentScriptInputObject { get; set; }
public PsDeploymentScript DeploymentScriptObject { get; set; }

[Parameter(Position = 2, ParameterSetName = SaveDeploymentScriptLogByName, Mandatory = true, HelpMessage = "The directory path to save deployment script log.")]
[Parameter(Position = 1, ParameterSetName = SaveDeploymentScriptLogByResourceId, Mandatory = true, HelpMessage = "The directory path to save deployment script log.")]
Expand All @@ -84,25 +86,28 @@ public override void ExecuteCmdlet()

PsDeploymentScriptLog deploymentScriptLog;
int tailParam = this.IsParameterBound(c => c.Tail) ? Tail : 0;
string scriptName = "";

try
{
switch (ParameterSetName)
{
case SaveDeploymentScriptLogByName:
scriptName = Name;
deploymentScriptLog =
DeploymentScriptsSdkClient.GetDeploymentScriptLog(Name, ResourceGroupName, tailParam);
DeploymentScriptsSdkClient.GetDeploymentScriptLog(scriptName, ResourceGroupName, tailParam);
break;
case SaveDeploymentScriptLogByResourceId:
deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(
ResourceIdUtility.GetResourceName(this.DeploymentScriptResourceId),
scriptName = ResourceIdUtility.GetResourceName(this.DeploymentScriptResourceId);
deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(scriptName,
ResourceIdUtility.GetResourceGroupName(this.DeploymentScriptResourceId),
tailParam);
break;
case SaveDeploymentScriptLogByInputObject:
scriptName = DeploymentScriptObject.Name;
deploymentScriptLog = DeploymentScriptsSdkClient.GetDeploymentScriptLog(
DeploymentScriptInputObject.Name,
ResourceIdUtility.GetResourceGroupName(DeploymentScriptInputObject.Id),
scriptName,
ResourceIdUtility.GetResourceGroupName(DeploymentScriptObject.Id),
tailParam);
break;
default:
Expand All @@ -118,13 +123,26 @@ public override void ExecuteCmdlet()
this.ConfirmAction(
this.Force || !AzureSession.Instance.DataStore.FileExists(outputPathWithFileName),
string.Format(
Properties.Resources.DeploymentScriptLogFileExists, Name, OutputPath),
Properties.Resources.DeploymentScriptLogFileExists, scriptName, OutputPath),
Properties.Resources.DeploymentScriptShouldProcessString,
OutputPath,
() =>
{
//Standardize newline character to be written into file
StringBuilder logs = new StringBuilder();
StringReader stringReader = new StringReader(deploymentScriptLog.Log);

String line = stringReader.ReadLine();
while(line != null)
{
logs.Append(line);
line = stringReader.ReadLine();
if (line != null)
logs.Append(Environment.NewLine);
}

AzureSession.Instance.DataStore.WriteFile(outputPathWithFileName,
deploymentScriptLog.Log);
logs.ToString());

WriteObject(new PsDeploymentScriptLogPath() {Path = outputPathWithFileName});
});
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/ResourceManager/ResourceManager.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@
<Label>ContainerInstanceId</Label>
<ScriptBlock>$_.Status.ContainerInstanceId</ScriptBlock>
</ListItem>
<ListItem>
<Label>Outputs</Label>
<PropertyName>OutputsString</PropertyName>
</ListItem>
<ListItem>
<Label>RetentionInterval</Label>
<PropertyName>RetentionInterval</PropertyName>
Expand Down
29 changes: 29 additions & 0 deletions src/Resources/ResourceManager/SdkExtensions/ResourcesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,35 @@ private static string ConstructTemplateLinkView(TemplateLink templateLink)
return result.ToString();
}

public static string ConstructOutputTable(IDictionary<string, object> dictionary)
{
if (dictionary == null)
{
return null;
}

var maxNameLength = 18;
dictionary.Keys.ForEach(k => maxNameLength = Math.Max(maxNameLength, k.Length + 2));

StringBuilder output = new StringBuilder();

if (dictionary.Count > 0)
{
string rowFormat = "{0, -" + maxNameLength + "} {1}\r\n";
output.AppendLine();
output.AppendFormat(rowFormat, "Key", "Value");
output.AppendFormat(rowFormat, GeneralUtilities.GenerateSeparator(maxNameLength, "="), GeneralUtilities.GenerateSeparator(maxNameLength, "="));
Copy link
Contributor

@filizt filizt May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GeneralUtilities.GenerateSeparator(maxNameLength, "=") [](start = 106, length = 55)

A bit confused with the use of maxTypeLength. You don't seem to use it in the AppendFormat, do we need it then? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I think I can get rid of that variable. I was using it earlier to determine the length of the separating line at the top. It's redundant now.


foreach (KeyValuePair<string, object> pair in dictionary)
{
String val = pair.Value.ToString().Replace("\n", "\n" + GeneralUtilities.GenerateSeparator(maxNameLength, " ") + " ");
output.AppendFormat(rowFormat, pair.Key, val);
}
}

return output.ToString();
}

public static string ConstructDeploymentVariableTable(Dictionary<string, DeploymentVariable> dictionary)
{
if (dictionary == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkExtensions;
using Microsoft.Azure.Management.ResourceManager.Models;
using System.Collections.Generic;

Expand All @@ -25,6 +26,11 @@ public class PsDeploymentScript : PsAzureScriptBase

public IDictionary<string,string> Tags { get; set; }

public string ScriptKind { get; set; }
public string ScriptKind { get; set; }

public string OutputsString
{
get { return ResourcesExtensions.ConstructOutputTable(Outputs); }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function Test-GetDeploymentScriptLog-PowerShell

#Test - GetLogByInputObject
$deploymentScript = Get-AzDeploymentScript -ResourceGroupName $rgname -Name $deploymentScriptName
$getLogByInputObject = Get-AzDeploymentScriptLog -DeploymentScriptInputObject $deploymentScript
$getLogByInputObject = Get-AzDeploymentScriptLog -DeploymentScriptObject $deploymentScript

# Assert
Assert-NotNull $getLogByInputObject
Expand All @@ -277,7 +277,7 @@ function Test-GetDeploymentScriptLog-PowerShell

#Test - GetLogByInputObject - WithTailParameter
$deploymentScript = Get-AzDeploymentScript -ResourceGroupName $rgname -Name $deploymentScriptName
$getLogByInputObjectWithTail = Get-AzDeploymentScriptLog -DeploymentScriptInputObject $deploymentScript -Tail $tailInteger
$getLogByInputObjectWithTail = Get-AzDeploymentScriptLog -DeploymentScriptObject $deploymentScript -Tail $tailInteger
$tail = [math]::min( ($getLogByInputObject.Log -split '\n').count, $tailInteger)

# Assert
Expand Down Expand Up @@ -359,7 +359,7 @@ function Test-GetDeploymentScriptLog-Cli

#Test - GetLogByInputObject
$deploymentScript = Get-AzDeploymentScript -ResourceGroupName $rgname -Name $deploymentScriptName
$getLogByInputObject = Get-AzDeploymentScriptLog -DeploymentScriptInputObject $deploymentScript
$getLogByInputObject = Get-AzDeploymentScriptLog -DeploymentScriptObject $deploymentScript

# Assert
Assert-NotNull $getLogByInputObject
Expand All @@ -369,7 +369,7 @@ function Test-GetDeploymentScriptLog-Cli

#Test - GetLogByInputObject - WithTailParameter
$deploymentScript = Get-AzDeploymentScript -ResourceGroupName $rgname -Name $deploymentScriptName
$getLogByInputObjectWithTail = Get-AzDeploymentScriptLog -DeploymentScriptInputObject $deploymentScript -Tail $tailInteger
$getLogByInputObjectWithTail = Get-AzDeploymentScriptLog -DeploymentScriptObject $deploymentScript -Tail $tailInteger
$tail = [math]::min( ($getLogByResourceId.Log -split '\r').count, $tailInteger)

# Assert
Expand Down Expand Up @@ -463,8 +463,8 @@ function Test-TrySaveNonExistingFilePathForLogFile
$path = (Get-Item ".\").FullName
$fullPath = Join-Path $path $badPath
$exceptionMessage = "Cannot find path '$fullPath'"
Assert-Throws { Save-AzDeploymentScriptLog -DeploymentScriptInputObject $deploymentScript -OutputPath $badPath } $exceptionMessage
Assert-Throws { Save-AzDeploymentScriptLog -DeploymentScriptInputObject $deploymentScript -OutputPath $badPath -Tail $tailInteger} $exceptionMessage
Assert-Throws { Save-AzDeploymentScriptLog -DeploymentScriptObject $deploymentScript -OutputPath $badPath } $exceptionMessage
Assert-Throws { Save-AzDeploymentScriptLog -DeploymentScriptObject $deploymentScript -OutputPath $badPath -Tail $tailInteger} $exceptionMessage
}
finally
{
Expand Down
Loading