Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
753 changes: 753 additions & 0 deletions src/Compute/Compute/Common/ComputeClientBaseCmdlet.cs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/Compute/Compute/Compute.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<PackageReference Include="System.Management" Version="4.5.0" />
<!-- Include the following DLLs for security issue -->
<PackageReference Include="System.Security.Cryptography.Xml" Version="4.7.1" />
<PackageReference Include="Azure.Identity" Version="1.11.4" />
</ItemGroup>

<!-- Include shared WhatIf library -->
<ItemGroup>
<Compile Include="..\..\shared\WhatIf\**\*.cs" LinkBase="Shared\WhatIf" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ public class NewAzureVMCommand : VirtualMachineBaseCmdlet

public override void ExecuteCmdlet()
{
// Handle DryRun early (before any real logic)
if (DryRun.IsPresent && TryHandleDryRun())
{
return;
}

switch (ParameterSetName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,29 @@ public class UpdateAzureVMCommand : VirtualMachineBaseCmdlet

public override void ExecuteCmdlet()
{
// If DryRun requested, build flattened PS script including VM object assignment
if (DryRun.IsPresent)
{
try
{
var vmJson = Newtonsoft.Json.JsonConvert.SerializeObject(this.VM, Newtonsoft.Json.Formatting.Indented);
string escapedJson = vmJson.Replace("`", "``");
string vmAssign = "$vm = ConvertFrom-Json @'\n" + escapedJson + "\n'@";
if (TryHandleDryRun(vmAssign))
{
return;
}
}
catch (Exception ex)
{
WriteVerbose($"DryRun VM flatten failed: {ex.Message}. Falling back to default invocation capture.");
if (TryHandleDryRun())
{
return;
}
}
}

if (this.IsParameterBound(c => c.UserData))
{
if (!ValidateBase64EncodedString.ValidateStringIsBase64Encoded(this.UserData))
Expand All @@ -223,7 +246,6 @@ public override void ExecuteCmdlet()
{
ExecuteClientAction(() =>
{

var parameters = new VirtualMachine
{
DiagnosticsProfile = this.VM.DiagnosticsProfile,
Expand Down Expand Up @@ -346,7 +368,7 @@ public override void ExecuteCmdlet()
parameters.SecurityProfile.EncryptionAtHost = this.EncryptionAtHost;
}

if (this.IsParameterBound( c => c.SecurityType))
if (this.IsParameterBound(c => c.SecurityType))
{
if (parameters.SecurityProfile == null)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Network/Network/Network.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<PackageReference Include="Microsoft.Azure.PowerShell.AutoMapper" Version="6.2.2" />
</ItemGroup>

<!-- Add shared WhatIf library source files -->
<ItemGroup>
<Compile Include="..\..\shared\WhatIf\**\*.cs" LinkBase="Shared\WhatIf" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public class NewAzureVirtualNetworkCommand : VirtualNetworkBaseCmdlet

public override void Execute()
{
// Handle DryRun early: perform DryRun payload post and formatting only, skip real create logic
if (DryRun.IsPresent && TryHandleDryRun())
{
return; // do not proceed to actual creation
}

base.Execute();
var present = IsVirtualNetworkPresent(ResourceGroupName, Name);
ConfirmAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ public class SetAzureVirtualNetworkCommand : VirtualNetworkBaseCmdlet

public override void Execute()
{
// DryRun support (modeled after UpdateAzureVMCommand): attempt to flatten PSVirtualNetwork into a PS assignment
if (DryRun.IsPresent)
{
try
{
var vnetJson = Newtonsoft.Json.JsonConvert.SerializeObject(this.VirtualNetwork, Newtonsoft.Json.Formatting.Indented);
string escapedJson = vnetJson.Replace("`", "``");
string vnetAssign = "$virtualNetwork = ConvertFrom-Json @'\n" + escapedJson + "\n'@";
if (TryHandleDryRun(vnetAssign))
{
return; // DryRun handled, do not execute real operation
}
}
catch (Exception ex)
{
WriteVerbose($"DryRun VirtualNetwork flatten failed: {ex.Message}. Falling back to default invocation capture.");
if (TryHandleDryRun())
{
return;
}
}
}

base.Execute();

if (!this.IsVirtualNetworkPresent(this.VirtualNetwork.ResourceGroupName, this.VirtualNetwork.Name))
Expand Down
Loading