Skip to content

Breaking Change - Removed ApiVersion parameter from Az.Resources deployments cmdlets and changed the output type of Get-AzResourceGroupDeploymentOperations #13112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a009dcd
Remove ApiVersion Parameter from deployments
Xynoclafe Jun 10, 2020
38585ee
update changelog
Xynoclafe Jun 10, 2020
fcb6129
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Jun 10, 2020
8568c38
Delete ApiVersion param
Xynoclafe Jun 10, 2020
603df06
Switch to SDK use in ResourceGroup Deployments cmdlets
Xynoclafe Jun 12, 2020
f8f9c77
Include review fixes
Xynoclafe Jun 15, 2020
d00f0c4
Merge branch 'master' into xynoclafe/deploymentsSDKfix
Xynoclafe Jun 15, 2020
77798dc
Changed help file to reflect new output type
Xynoclafe Jun 17, 2020
4428f27
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Jun 24, 2020
e8556bd
Rollback breaking changes from PR #12141
Xynoclafe Jun 24, 2020
a2ff0c1
Merge branch 'xynoclafe/deploymentsSDKfix' into xynoclafe/apiversion
Xynoclafe Aug 10, 2020
07f418d
Merge branch 'Az.Resources-preview' of https://github.com/Azure/azure…
Xynoclafe Aug 10, 2020
eefb5dc
Change Get-AzResourceGroupDeploymentOperation implementation to use SDK
Xynoclafe Aug 11, 2020
4a530a2
Update help
Xynoclafe Aug 17, 2020
4f7421b
Rollback changes to help files of untouched cmdlets
Xynoclafe Aug 19, 2020
c65f0b8
Suppress breaking change issues
Xynoclafe Aug 20, 2020
4fd788d
remove subscriptionId param
Xynoclafe Aug 20, 2020
2e1f949
Update breakingchanges csv
Xynoclafe Aug 24, 2020
88be509
Suppress breaking changes
Xynoclafe Sep 1, 2020
6c9887e
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Sep 29, 2020
92221e6
Review fixes + breaking change suppression
Xynoclafe Sep 30, 2020
70fe182
Add missed breaking change issue to fix static analysis failure
Xynoclafe Sep 30, 2020
8e6d2c3
Update ChangeLog.md
isra-fel Oct 9, 2020
41665b0
Merge branch 'master' into xynoclafe/apiversion
isra-fel Oct 9, 2020
981fb5d
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Oct 13, 2020
1e5b69c
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Oct 15, 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 @@ -25,15 +25,13 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.RestClients;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
using Microsoft.Rest.Azure;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;

/// <summary>
/// The base class for resource manager cmdlets.
Expand Down Expand Up @@ -66,14 +64,6 @@ protected CancellationToken? CancellationToken
/// </summary>
private SubscriptionSdkClient subscriptionSdkClient;

/// <summary>
/// Gets or sets the API version.
/// </summary>
[CmdletParameterBreakingChange("ApiVersion", ChangeDescription = "Parameter is being deprecated without being replaced")]
[Parameter(Mandatory = false, HelpMessage = "When set, indicates the version of the resource provider API to use. If not specified, the API version is automatically determined as the latest available.")]
[ValidateNotNullOrEmpty]
public virtual string ApiVersion { get; set; }

/// <summary>
/// Gets or sets the switch that indicates if pre-release API version should be considered.
/// </summary>
Expand Down Expand Up @@ -223,42 +213,6 @@ protected virtual void OnStopProcessing()
// no-op
}

/// <summary>
/// Determines the API version.
/// </summary>
/// <param name="resourceId">The resource Id.</param>
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
protected Task<string> DetermineApiVersion(string resourceId, bool? pre = null)
{
return string.IsNullOrWhiteSpace(this.ApiVersion)
? ApiVersionHelper.DetermineApiVersion(
context: DefaultContext,
resourceId: resourceId,
cancellationToken: this.CancellationToken.Value,
pre: pre ?? this.Pre,
cmdletHeaderValues: this.GetCmdletHeaders())
: Task.FromResult(this.ApiVersion);
}

/// <summary>
/// Determines the API version.
/// </summary>
/// <param name="providerNamespace">The provider namespace.</param>
/// <param name="resourceType">The resource type.</param>
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
protected Task<string> DetermineApiVersion(string providerNamespace, string resourceType, bool? pre = null)
{
return string.IsNullOrWhiteSpace(this.ApiVersion)
? ApiVersionHelper.DetermineApiVersion(
DefaultContext,
providerNamespace: providerNamespace,
resourceType: resourceType,
cancellationToken: this.CancellationToken.Value,
pre: pre ?? this.Pre,
cmdletHeaderValues: this.GetCmdletHeaders())
: Task.FromResult(this.ApiVersion);
}

/// <summary>
/// Gets a new instance of the <see cref="ResourceManagerRestRestClient"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,63 @@
// ----------------------------------------------------------------------------------

using System.Management.Automation;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
public abstract class ResourceManagerCmdletBaseWithAPiVersion : ResourceManagerCmdletBase
public abstract class ResourceManagerCmdletBaseWithApiVersion : ResourceManagerCmdletBase
{
/// <summary>
/// Gets or sets the API version.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "When set, indicates the version of the resource provider API to use. If not specified, the API version is automatically determined as the latest available.")]
[ValidateNotNullOrEmpty]
public override string ApiVersion { get; set; }
public string ApiVersion { get; set; }

private Dictionary<string, string> GetCmdletHeaders()
{
return new Dictionary<string, string>
{
{"ParameterSetName", this.ParameterSetName },
{"CommandName", this.CommandRuntime.ToString() }
};
}

/// <summary>
/// Determines the API version.
/// </summary>
/// <param name="resourceId">The resource Id.</param>
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
protected Task<string> DetermineApiVersion(string resourceId, bool? pre = null)
{
return string.IsNullOrWhiteSpace(this.ApiVersion)
? Components.ApiVersionHelper.DetermineApiVersion(
context: DefaultContext,
resourceId: resourceId,
cancellationToken: this.CancellationToken.Value,
pre: pre ?? this.Pre,
cmdletHeaderValues: this.GetCmdletHeaders())
: Task.FromResult(this.ApiVersion);
}

/// <summary>
/// Determines the API version.
/// </summary>
/// <param name="providerNamespace">The provider namespace.</param>
/// <param name="resourceType">The resource type.</param>
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
protected Task<string> DetermineApiVersion(string providerNamespace, string resourceType, bool? pre = null)
{
return string.IsNullOrWhiteSpace(this.ApiVersion)
? Components.ApiVersionHelper.DetermineApiVersion(
DefaultContext,
providerNamespace: providerNamespace,
resourceType: resourceType,
cancellationToken: this.CancellationToken.Value,
pre: pre ?? this.Pre,
cmdletHeaderValues: this.GetCmdletHeaders())
: Task.FromResult(this.ApiVersion);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// <summary>
/// The base class for manipulating resources.
/// </summary>
public abstract class ResourceManipulationCmdletBase : ResourceManagerCmdletBaseWithAPiVersion
public abstract class ResourceManipulationCmdletBase : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// The subscription level parameter set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Get all locations with the supported providers.
/// </summary>
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Location"), OutputType(typeof(PSResourceProviderLocation))]
public class GetAzureLocationCmdlet : ResourceManagerCmdletBaseWithAPiVersion
public class GetAzureLocationCmdlet : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// Executes the cmdlet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// <summary>
/// Base class for resource lock management cmdlets.
/// </summary>
public abstract class ResourceLockManagementCmdletBase : ResourceManagerCmdletBaseWithAPiVersion
public abstract class ResourceLockManagementCmdletBase : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// The Id parameter set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// <summary>
/// Base class for policy assignment cmdlets.
/// </summary>
public abstract class ManagedApplicationCmdletBase : ResourceManagerCmdletBaseWithAPiVersion
public abstract class ManagedApplicationCmdletBase : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// Gets the next set of resources using the <paramref name="nextLink"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Get an existing resource.
/// </summary>
[Cmdlet(VerbsCommon.Get, AzureRMConstants.AzureRMPrefix + "PolicyAlias"), OutputType(typeof(PsResourceProviderAlias))]
public class GetAzurePolicyAlias : ResourceManagerCmdletBaseWithAPiVersion
public class GetAzurePolicyAlias : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// Gets or sets the provider namespace match string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// <summary>
/// Base class for policy cmdlets.
/// </summary>
public abstract class PolicyCmdletBase : ResourceManagerCmdletBaseWithAPiVersion
public abstract class PolicyCmdletBase : ResourceManagerCmdletBaseWithApiVersion
{
public enum ListFilter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Get an existing resource.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceProvider", DefaultParameterSetName = GetAzureProviderCmdlet.ListAvailableParameterSet), OutputType(typeof(PSResourceProvider))]
public class GetAzureProviderCmdlet : ResourceManagerCmdletBaseWithAPiVersion
public class GetAzureProviderCmdlet : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// The individual provider parameter set name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Register the previewed features of a certain azure resource provider.
/// </summary>
[Cmdlet("Register", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceProvider", SupportsShouldProcess = true), OutputType(typeof(PSResourceProvider))]
public class RegisterAzureProviderCmdlet : ResourceManagerCmdletBaseWithAPiVersion
public class RegisterAzureProviderCmdlet : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// Gets or sets the provider namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Un-registers the resource provider from the current subscription.
/// </summary>
[Cmdlet("Unregister", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceProvider", SupportsShouldProcess = true), OutputType(typeof(PSResourceProvider))]
public class UnregisterAzureProviderCmdlet : ResourceManagerCmdletBaseWithAPiVersion
public class UnregisterAzureProviderCmdlet : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// Gets or sets the provider namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Cmdlet to get existing resources.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Resource", DefaultParameterSetName = ByTagNameValueParameterSet), OutputType(typeof(PSResource))]
public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBaseWithAPiVersion
public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBaseWithApiVersion
{
public const string ByResourceIdParameterSet = "ByResourceId";
public const string ByTagObjectParameterSet = "ByTagObjectParameterSet";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Moves existing resources to a new resource group or subscription.
/// </summary>
[Cmdlet("Move", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Resource", SupportsShouldProcess = true), OutputType(typeof(bool))]
public class MoveAzureResourceCommand : ResourceManagerCmdletBaseWithAPiVersion
public class MoveAzureResourceCommand : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// Caches the current resource ids to get all resource ids in the pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
using Commands.Common.Authentication.Abstractions;
using Common.ArgumentCompleters;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Newtonsoft.Json.Linq;
using System;
using System.Management.Automation;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;

/// <summary>
/// Gets the deployment operation.
/// </summary>
[CmdletOutputBreakingChange(typeof(PSObject), ReplacementCmdletOutputTypeName = "PSDeploymentOperation")]
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentOperation"), OutputType(typeof(PSObject))]
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentOperation"), OutputType(typeof(PSDeploymentOperation))]
public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmdletBase
{
/// <summary>
Expand All @@ -40,14 +32,6 @@ public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmd
[ValidateNotNullOrEmpty]
public string DeploymentName { get; set; }

/// <summary>
/// Gets or sets the subscription id parameter.
/// </summary>
[CmdletParameterBreakingChange("SubscriptionId", ChangeDescription = "Parameter is being deprecated without being replaced")]
[Parameter(Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The subscription to use.")]
[ValidateNotNullOrEmpty]
public Guid? SubscriptionId { get; set; }

/// <summary>
/// Gets or sets the resource group name parameter.
/// </summary>
Expand All @@ -61,68 +45,12 @@ public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmd
/// </summary>
protected override void OnProcessRecord()
{
var deploymentOperations = ResourceManagerSdkClient.ListDeploymentOperationsAtResourceGroup(
ResourceGroupName, DeploymentName);
base.OnProcessRecord();

if (this.SubscriptionId == null)
{
this.SubscriptionId = DefaultContext.Subscription.GetId();
}

this.RunCmdlet();
}

/// <summary>
/// Contains the cmdlet's execution logic.
/// </summary>
private void RunCmdlet()
{
PaginatedResponseHelper.ForEach(
getFirstPage: () => this.GetResources(),
getNextPage: nextLink => this.GetNextLink<JObject>(nextLink),
cancellationToken: this.CancellationToken,
action: resources => this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(resource =>
resource.ToPsObject("System.Management.Automation.PSCustomObject#DeploymentOperation")), enumerateCollection: true));
}

/// <summary>
/// Queries the ARM cache and returns the cached resource that match the query specified.
/// </summary>
private async Task<ResponseWithContinuation<JObject[]>> GetResources()
{
var resourceId = this.GetResourceId();

var apiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.DeploymentOperationApiVersion : this.ApiVersion;

return await this
.GetResourcesClient()
.ListObjectColleciton<JObject>(
resourceCollectionId: resourceId,
apiVersion: apiVersion,
cancellationToken: this.CancellationToken.Value)
.ConfigureAwait(continueOnCapturedContext: false);
WriteObject(deploymentOperations, true);
}

/// <summary>
/// Gets the next set of resources using the <paramref name="nextLink"/>
/// </summary>
/// <param name="nextLink">The next link.</param>
private Task<ResponseWithContinuation<TType[]>> GetNextLink<TType>(string nextLink)
{
return this
.GetResourcesClient()
.ListNextBatch<TType>(nextLink: nextLink, cancellationToken: this.CancellationToken.Value);
}

/// <summary>
/// Gets the resource Id from the supplied PowerShell parameters.
/// </summary>
protected string GetResourceId()
{
return ResourceIdUtility.GetResourceId(
subscriptionId: this.SubscriptionId,
resourceGroupName: this.ResourceGroupName,
resourceType: Constants.MicrosoftResourcesDeploymentOperationsType,
resourceName: this.DeploymentName);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Captures the specifies resource group as a template and saves it to a file on disk.
/// </summary>
[Cmdlet("Export", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroup", SupportsShouldProcess = true), OutputType(typeof(PSObject))]
public class ExportAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithAPiVersion
public class ExportAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// Adding a hard-coded API version to be used when there is no value provided for 'ApiVersion' parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Filters resource groups.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroup", DefaultParameterSetName = ResourceGroupNameParameterSet), OutputType(typeof(PSResourceGroup))]
public class GetAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithAPiVersion
public class GetAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// List resources group by name parameter set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Filters resource groups.
/// </summary>
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroup", SupportsShouldProcess = true), OutputType(typeof(PSResourceGroup))]
public class NewAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithAPiVersion
public class NewAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithApiVersion
{
[Alias("ResourceGroupName")]
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.Resources
/// Removes a resource group.
/// </summary>
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroup", SupportsShouldProcess = true, DefaultParameterSetName = ResourceGroupNameParameterSet), OutputType(typeof(bool))]
public class RemoveAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithAPiVersion
public class RemoveAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithApiVersion
{
/// <summary>
/// List resources group by name parameter set.
Expand Down
Loading