diff --git a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/GetAzureResourceCmdlet.cs b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/GetAzureResourceCmdlet.cs index 6a8396fe7a2a..b636eaa36979 100644 --- a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/GetAzureResourceCmdlet.cs +++ b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/GetAzureResourceCmdlet.cs @@ -103,13 +103,6 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase [ValidateNotNullOrEmpty] public string ResourceType { get; set; } - /// - /// Gets or sets the deprecated parent resource parameter. - /// - [Parameter(ParameterSetName = GetAzureResourceCmdlet.GetResourceParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "The parent resource type. e.g. Servers/myServer.")] - [ValidateNotNullOrEmpty] - public string ParentResource { get; set; } - /// /// Gets or sets the extension resource name parameter. /// @@ -132,34 +125,12 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase [ValidateNotNullOrEmpty] public string ExtensionResourceType { get; set; } - /// - /// Gets or sets the tag name. - /// - [Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourcesParameterSet, Mandatory = false, HelpMessage = "The name of the tag to query by.")] - [Parameter(ParameterSetName = GetAzureResourceCmdlet.MultiSubscriptionListResourcesParameterSet, Mandatory = false, HelpMessage = "The name of the tag to query by.")] - [ValidateNotNullOrEmpty] - public string TagName { get; set; } - - /// - /// Gets or sets the tag value. - /// - [Parameter(ParameterSetName = GetAzureResourceCmdlet.ListResourcesParameterSet, Mandatory = false, HelpMessage = "The value of the tag to query by.")] - [Parameter(ParameterSetName = GetAzureResourceCmdlet.MultiSubscriptionListResourcesParameterSet, Mandatory = false, HelpMessage = "The value of the tag to query by.")] - [ValidateNotNullOrEmpty] - public string TagValue { get; set; } - /// /// Gets or sets the expand properties property. /// [Parameter(Mandatory = false, HelpMessage = "When specified, expands the properties of the resource.")] public SwitchParameter ExpandProperties { get; set; } - /// - /// Gets or sets the expand permissions property. - /// - [Parameter(Mandatory = false, HelpMessage = "When specified, expands the permissions on the resource.")] - public SwitchParameter ExpandPermissions { get; set; } - /// /// Gets or sets the is collection. /// @@ -186,15 +157,6 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase [ValidateNotNullOrEmpty] public string ODataQuery { get; set; } - /// - /// Gets or sets the subscription ids. - /// - [Parameter(Mandatory = false, ParameterSetName = GetAzureResourceCmdlet.GetResourceParameterSet, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The subscription to use.")] - [Parameter(Mandatory = false, ParameterSetName = GetAzureResourceCmdlet.ListResourcesParameterSet, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The subscription to use.")] - [Parameter(Mandatory = true, ParameterSetName = GetAzureResourceCmdlet.MultiSubscriptionListResourcesParameterSet, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The subscription to use.")] - [ValidateNotNullOrEmpty] - public Guid[] SubscriptionId { get; set; } - /// /// Gets or sets the resource group name. /// @@ -217,12 +179,21 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase [Parameter(Mandatory = false, HelpMessage = "The output format of the resource properties.")] public ResourceObjectFormat OutputObjectFormat { get; set; } + /// + /// Gets or sets the subscription id. + /// + public Guid SubscriptionId { get; set; } + /// /// Initializes a new instance of the class. /// public GetAzureResourceCmdlet() { this.OutputObjectFormat = ResourceObjectFormat.Legacy; + if(string.IsNullOrEmpty(this.ResourceId)) + { + this.SubscriptionId = DefaultContext.Subscription.Id; + } } /// @@ -231,19 +202,6 @@ public GetAzureResourceCmdlet() protected override void OnProcessRecord() { base.OnProcessRecord(); - if(!string.IsNullOrEmpty(this.TagName) || !string.IsNullOrEmpty(this.TagValue)) - { - this.WriteWarning("The TagName and TagValue parameters are obsolete and will be removed in future releases."); - } - if(!string.IsNullOrEmpty(this.ParentResource)) - { - this.WriteWarning("The ParentResource parameter is obsolete and will be removed in future releases. Please use the -ResourceType and -ResourceName parameters instead."); - } - if (this.ExpandPermissions.IsPresent) - { - this.WriteWarning("The ExpandPermissions parameter is obsolete and will be removed in future releases."); - } - this.subscriptionIds.AddRange(this.SubscriptionId.CoalesceEnumerable()); } /// @@ -253,12 +211,6 @@ protected override void OnEndProcessing() { base.OnEndProcessing(); - this.SubscriptionId = this.subscriptionIds.DistinctArray(); - if (string.IsNullOrWhiteSpace(this.ResourceId) && !this.SubscriptionId.CoalesceEnumerable().Any() && !this.TenantLevel) - { - this.SubscriptionId = DefaultContext.Subscription.Id.AsArray(); - } - this.RunCmdlet(); } @@ -292,10 +244,6 @@ private void RunCmdlet() } var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPsObject(this.OutputObjectFormat)); - if (this.ExpandPermissions) - { - this.PopulatePermissions(powerShellObjects).Wait(); - } this.WriteObject(sendToPipeline: powerShellObjects, enumerateCollection: true); } @@ -354,9 +302,7 @@ private async Task GetResource() { #pragma warning disable 618 - var resourceId = string.IsNullOrWhiteSpace(this.ParentResource) - ? this.GetResourceId() - : this.GetResourceIdWithParentResource(); + var resourceId = this.GetResourceId(); #pragma warning restore 618 @@ -387,7 +333,7 @@ private async Task GetResource() private async Task> ListResourcesTypeCollection() { var resourceCollectionId = ResourceIdUtility.GetResourceId( - subscriptionId: this.SubscriptionId.CoalesceEnumerable().Cast().FirstOrDefault(), + subscriptionId: this.SubscriptionId, resourceGroupName: this.ResourceGroupName, resourceType: this.ResourceType, resourceName: this.ResourceName, @@ -401,8 +347,8 @@ private async Task> ListResourcesTypeCollect var odataQuery = QueryFilterBuilder.CreateFilter( resourceType: null, resourceName: null, - tagName: this.TagName, - tagValue: this.TagValue, + tagName: null, + tagValue: null, filter: this.ODataQuery); return await this @@ -422,12 +368,12 @@ private async Task> ListResourcesInTenant() { var filterQuery = QueryFilterBuilder .CreateFilter( - subscriptionIds: this.SubscriptionId, + subscriptionIds: new Guid[] { this.SubscriptionId }, resourceGroup: this.ResourceGroupName, resourceType: this.ResourceType, resourceName: this.ResourceName, - tagName: this.TagName, - tagValue: this.TagValue, + tagName: null, + tagValue: null, filter: this.ODataQuery); var apiVersion = await this @@ -453,8 +399,8 @@ private async Task> ListResourcesInResourceG .CreateFilter( resourceType: this.ResourceType, resourceName: this.ResourceName, - tagName: this.TagName, - tagValue: this.TagValue, + tagName: null, + tagValue: null, filter: this.ODataQuery); var apiVersion = await this @@ -464,7 +410,7 @@ private async Task> ListResourcesInResourceG return await this .GetResourcesClient() .ListResources( - subscriptionId: this.SubscriptionId.Single(), + subscriptionId: this.SubscriptionId, resourceGroupName: this.ResourceGroupName, apiVersion: apiVersion, top: this.Top, @@ -482,8 +428,8 @@ private async Task> ListResourcesInSubscript .CreateFilter( resourceType: this.ResourceType, resourceName: this.ResourceName, - tagName: this.TagName, - tagValue: this.TagValue, + tagName: null, + tagValue: null, filter: this.ODataQuery); var apiVersion = await this @@ -493,7 +439,7 @@ private async Task> ListResourcesInSubscript return await this .GetResourcesClient() .ListResources( - subscriptionId: this.SubscriptionId.Single(), + subscriptionId: this.SubscriptionId, apiVersion: apiVersion, top: this.Top, filter: filterQuery, @@ -512,85 +458,6 @@ private Task> GetNextLink(string nextLi .ListNextBatch(nextLink: nextLink, cancellationToken: this.CancellationToken.Value); } - /// - /// Populates the permissions on an array of resources. - /// - /// The resources. - private async Task PopulatePermissions(PSObject[] resources) - { - foreach (var batch in resources.Batch()) - { - await batch - .Select(resource => this.PopulatePermissions(resource: resource)) - .WhenAllForAwait() - .ConfigureAwait(continueOnCapturedContext: false); - } - } - - /// - /// Populates the permissions on the resource. - /// - /// The resource. - private async Task PopulatePermissions(PSObject resource) - { - try - { - var resourceId = resource.Properties["ResourceId"].Value.ToString(); - - var resourceCollectionId = resourceId + ResourceIdUtility - .GetResourceCollectionId( - subscriptionId: null, - resourceGroupName: null, - resourceType: null, - extensionResourceType: "Microsoft.Authorization/permissions"); - - var apiVersion = await ApiVersionHelper - .DetermineApiVersion( - DefaultContext, - providerNamespace: "Microsoft.Authorization", - resourceType: "permissions", - cancellationToken: this.CancellationToken.Value, - pre: this.Pre) - .ConfigureAwait(continueOnCapturedContext: false); - - var permissions = PaginatedResponseHelper.Enumerate( - getFirstPage: () => this.GetPermissions(permissionCheckId: resourceCollectionId, apiVersion: apiVersion), - getNextPage: nextLink => this.GetNextLink(nextLink), - cancellationToken: this.CancellationToken); - - resource.Properties.Add(new PSNoteProperty("Permissions", permissions)); - } - catch (Exception ex) - { - if (ex.IsFatal()) - { - throw; - } - - ex = (ex is AggregateException) - ? (ex as AggregateException).Flatten() - : ex; - - this.errors.Add(new ErrorRecord(ex, "ErrorExpandingPermissions", ErrorCategory.CloseError, resource)); - } - } - - /// - /// Gets the permission. - /// - /// The permission check Id. - /// The api version. - /// - private Task> GetPermissions(string permissionCheckId, string apiVersion) - { - return this - .GetResourcesClient() - .ListObjectColleciton( - resourceCollectionId: permissionCheckId, - apiVersion: apiVersion, - cancellationToken: this.CancellationToken.Value); - } - /// /// Populates the properties on an array of resources. /// @@ -652,7 +519,7 @@ private string GetResourceId() return !string.IsNullOrWhiteSpace(this.ResourceId) ? this.ResourceId : ResourceIdUtility.GetResourceId( - subscriptionId: this.SubscriptionId.CoalesceEnumerable().Cast().FirstOrDefault(), + subscriptionId: this.SubscriptionId, resourceGroupName: this.ResourceGroupName, resourceType: this.ResourceType, resourceName: this.ResourceName, @@ -660,28 +527,6 @@ private string GetResourceId() extensionResourceName: this.ExtensionResourceName); } - /// - /// Gets the resource Id using the ParentResource. - /// - private string GetResourceIdWithParentResource() - { - if (this.SubscriptionId.Length != 1) - { - throw new ArgumentException(); - } - -#pragma warning disable 618 - - return ResourceIdUtility.GetResourceId( - subscriptionId: this.SubscriptionId.First(), - resourceGroupName: this.ResourceGroupName, - parentResource: this.ParentResource, - resourceType: this.ResourceType, - resourceName: this.ResourceName); - -#pragma warning restore 618 - } - /// /// Returns true if this is a resource get at any level. /// @@ -709,7 +554,7 @@ private bool IsResourceTypeCollectionGet() /// private bool IsSubscriptionLevelResourceTypeCollectionGet() { - return this.SubscriptionId.Length == 1 && + return this.SubscriptionId != Guid.Empty && this.ResourceGroupName == null && this.ResourceName == null && this.ExtensionResourceName == null && @@ -721,7 +566,7 @@ private bool IsSubscriptionLevelResourceTypeCollectionGet() /// private bool IsResourceGroupLevelResourceTypeCollectionGet() { - return this.SubscriptionId.Length == 1 && + return this.SubscriptionId != Guid.Empty && this.ResourceGroupName != null && this.ResourceName == null && this.ExtensionResourceName == null && @@ -734,7 +579,7 @@ private bool IsResourceGroupLevelResourceTypeCollectionGet() /// private bool IsTenantLevelResourceTypeCollectionGet() { - return this.SubscriptionId.Length == 0 && + return this.SubscriptionId == Guid.Empty && this.ResourceGroupName == null && this.ResourceName == null && this.ExtensionResourceName == null && @@ -747,10 +592,8 @@ private bool IsTenantLevelResourceTypeCollectionGet() /// private bool IsSubscriptionLevelResourceGet() { - return this.SubscriptionId.Length == 1 && + return this.SubscriptionId != Guid.Empty && this.ResourceGroupName == null && - this.TagName == null && - this.TagValue == null && (this.ResourceName != null || this.ExtensionResourceName != null) && (this.ResourceType != null || this.ExtensionResourceType != null); } @@ -761,10 +604,8 @@ private bool IsSubscriptionLevelResourceGet() /// private bool IsResourceGroupLevelResourceGet() { - return this.SubscriptionId.Length == 1 && + return this.SubscriptionId != Guid.Empty && this.ResourceGroupName != null && - this.TagName == null && - this.TagValue == null && (this.ResourceName != null || this.ExtensionResourceName != null) && (this.ResourceType != null || this.ExtensionResourceType != null); } @@ -774,10 +615,8 @@ private bool IsResourceGroupLevelResourceGet() /// private bool IsTenantLevelResourceGet() { - return this.SubscriptionId.Length == 0 && + return this.SubscriptionId == Guid.Empty && this.ResourceGroupName == null && - this.TagName == null && - this.TagValue == null && (this.ResourceName != null || this.ExtensionResourceName != null) && (this.ResourceType != null || this.ExtensionResourceType != null); } @@ -787,7 +626,7 @@ private bool IsTenantLevelResourceGet() /// private bool IsSubscriptionLevelQuery() { - return this.SubscriptionId.Length == 1 && + return this.SubscriptionId != Guid.Empty && this.ResourceGroupName == null; } @@ -796,11 +635,9 @@ private bool IsSubscriptionLevelQuery() /// private bool IsResourceGroupLevelQuery() { - return this.SubscriptionId.Length == 1 && + return this.SubscriptionId != Guid.Empty && this.ResourceGroupName != null && - (this.TagName != null || - this.TagValue != null || - this.ResourceName != null || + (this.ResourceName != null || this.ExtensionResourceName != null || this.ResourceType != null || this.ExtensionResourceType != null); diff --git a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/MoveAzureResourceCmdlet.cs b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/MoveAzureResourceCmdlet.cs index 445e9d4a5158..9871a58adf67 100644 --- a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/MoveAzureResourceCmdlet.cs +++ b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/MoveAzureResourceCmdlet.cs @@ -59,12 +59,6 @@ public class MoveAzureResourceCommand : ResourceManagerCmdletBase [Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")] public SwitchParameter Force { get; set; } - /// - /// Gets or sets a value that indicates if the operation should wait for completion before returning the result. If set, the cmdlet will return as soon as the request is accepted. - /// - [Parameter(Mandatory = false, HelpMessage = "Do not wait for operation to complete.")] - public SwitchParameter NoWait { get; set; } - /// /// Gets or sets the ids of the resources to move. /// @@ -101,10 +95,6 @@ protected override void OnEndProcessing() /// private void RunCmdlet() { - if(this.NoWait.IsPresent) - { - this.WriteWarning("The NoWait parameter is obsolete and will be removed in future releases."); - } var resourceIdsToUse = this.resourceIds .Concat(this.ResourceId) .DistinctArray(StringComparer.InvariantCultureIgnoreCase); @@ -161,28 +151,21 @@ private void RunCmdlet() cancellationToken: this.CancellationToken.Value) .Result; - if(!this.NoWait) - { - var managementUri = this.GetResourcesClient() - .GetResourceManagementRequestUri( - resourceId: destinationResourceGroup, - apiVersion: apiVersion, - action: Constants.MoveResources); + var managementUri = this.GetResourcesClient() + .GetResourceManagementRequestUri( + resourceId: destinationResourceGroup, + apiVersion: apiVersion, + action: Constants.MoveResources); - var activity = string.Format("POST {0}", managementUri.PathAndQuery); + var activity = string.Format("POST {0}", managementUri.PathAndQuery); - var result = this - .GetLongRunningOperationTracker( - activityName: activity, - isResourceCreateOrUpdate: false) - .WaitOnOperation(operationResult: operationResult); + var result = this + .GetLongRunningOperationTracker( + activityName: activity, + isResourceCreateOrUpdate: false) + .WaitOnOperation(operationResult: operationResult); - this.TryConvertAndWriteObject(result, ResourceObjectFormat.New); - } - else - { - this.WriteObject(operationResult); - } + this.TryConvertAndWriteObject(result, ResourceObjectFormat.New); }); } } diff --git a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceManipulationCmdletBase.cs b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceManipulationCmdletBase.cs index 97acf711f083..279b403c42af 100644 --- a/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceManipulationCmdletBase.cs +++ b/src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceManipulationCmdletBase.cs @@ -63,13 +63,6 @@ public abstract class ResourceManipulationCmdletBase : ResourceManagerCmdletBase [ValidateNotNullOrEmpty] public string ResourceType { get; set; } - /// - /// Gets or sets the deprecated parent resource parameter. - /// - [Parameter(ParameterSetName = ResourceManipulationCmdletBase.SubscriptionLevelResoruceParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "The parent resource type. e.g. Servers/myServer.")] - [ValidateNotNullOrEmpty] - public string ParentResource { get; set; } - /// /// Gets or sets the extension resource name parameter. /// @@ -93,13 +86,6 @@ public abstract class ResourceManipulationCmdletBase : ResourceManagerCmdletBase [ValidateNotNullOrEmpty] public string ODataQuery { get; set; } - /// - /// Gets or sets the subscription id parameter. - /// - [Parameter(ParameterSetName = ResourceManipulationCmdletBase.SubscriptionLevelResoruceParameterSet, Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The subscription to use.")] - [ValidateNotNullOrEmpty] - public Guid? SubscriptionId { get; set; } - /// /// Gets or sets the resource group name parameter. /// @@ -119,24 +105,24 @@ public abstract class ResourceManipulationCmdletBase : ResourceManagerCmdletBase [Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")] public SwitchParameter Force { get; set; } + /// + /// Gets or sets the subscription id. + /// + public Guid SubscriptionId { get; set; } + /// /// Initializes the default subscription id if needed. /// - protected override void OnProcessRecord() + public ResourceManipulationCmdletBase() { - if(this.SubscriptionId != null) - { - this.WriteWarning("The SubscriptionId parameter is obsolete and will be removed in future releases."); - } - if (!string.IsNullOrEmpty(this.ParentResource)) - { - this.WriteWarning("The ParentResource parameter is obsolete and will be removed in future releases. Please use the -ResourceType and -ResourceName parameters instead."); - } - if (string.IsNullOrWhiteSpace(this.ResourceId) && !this.TenantLevel && this.SubscriptionId == null) + if (string.IsNullOrEmpty(this.ResourceId)) { this.SubscriptionId = DefaultContext.Subscription.Id; } + } + protected override void OnProcessRecord() + { base.OnProcessRecord(); } @@ -149,9 +135,7 @@ protected string GetResourceId() return !string.IsNullOrWhiteSpace(this.ResourceId) ? this.ResourceId - : !this.TenantLevel || string.IsNullOrWhiteSpace(this.ParentResource) - ? this.GetResourceIdWithoutParentResource() - : this.GetResourceIdWithParentResource(); + : this.GetResourceIdWithoutParentResource(); #pragma warning restore 618 } @@ -169,22 +153,5 @@ private string GetResourceIdWithoutParentResource() extensionResourceType: this.ExtensionResourceType, extensionResourceName: this.ExtensionResourceName); } - - /// - /// Gets the resource Id using the ParentResource. - /// - private string GetResourceIdWithParentResource() - { -#pragma warning disable 618 - - return ResourceIdUtility.GetResourceId( - subscriptionId: this.SubscriptionId.Value, - resourceGroupName: this.ResourceGroupName, - parentResource: this.ParentResource, - resourceType: this.ResourceType, - resourceName: this.ResourceName); - -#pragma warning restore 618 - } } } \ No newline at end of file