-
Notifications
You must be signed in to change notification settings - Fork 4k
Support ResourceGroupNameEquals and ResourceNameEquals as parameters in Find-AzureRmResource #3257
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ public sealed class FindAzureResourceCmdlet : ResourceManagerCmdletBase | |
private readonly List<Guid> subscriptionIds = new List<Guid>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the resource name parameter. | ||
/// Gets or sets the resource name for query as contains. | ||
/// </summary> | ||
[Alias("Name")] | ||
[Parameter(ParameterSetName = FindAzureResourceCmdlet.ListResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name substring. e.g. if your resource name is testResource, you can specify test.")] | ||
|
@@ -67,6 +67,15 @@ public sealed class FindAzureResourceCmdlet : ResourceManagerCmdletBase | |
[ValidateNotNullOrEmpty] | ||
public string ResourceNameContains { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the resource name for query as equals. | ||
/// </summary> | ||
[Parameter(ParameterSetName = FindAzureResourceCmdlet.ListResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name for a full match. e.g. if your resource name is testResource, you can specify testResource.")] | ||
[Parameter(ParameterSetName = FindAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name for a full match. e.g. if your resource name is testResource, you can specify testResource.")] | ||
[Parameter(ParameterSetName = FindAzureResourceCmdlet.MultiSubscriptionListResourcesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource name for a full match. e.g. if your resource name is testResource, you can specify testResource.")] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceNameEquals { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the resource type parameter. | ||
/// </summary> | ||
|
@@ -118,14 +127,22 @@ public sealed class FindAzureResourceCmdlet : ResourceManagerCmdletBase | |
public string TagValue { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the resource group name. | ||
/// Gets or sets the resource group name for query as contains. | ||
/// </summary> | ||
[Alias("ResourceGroupName")] | ||
[Parameter(Mandatory = false, ParameterSetName = FindAzureResourceCmdlet.ListResourcesParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name substring.")] | ||
[Parameter(Mandatory = false, ParameterSetName = FindAzureResourceCmdlet.MultiSubscriptionListResourcesParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name substring.")] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceGroupNameContains { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the resource group name for query as equals. | ||
/// </summary> | ||
[Parameter(Mandatory = false, ParameterSetName = FindAzureResourceCmdlet.ListResourcesParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name for a full match.")] | ||
[Parameter(Mandatory = false, ParameterSetName = FindAzureResourceCmdlet.MultiSubscriptionListResourcesParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name for a full match.")] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceGroupNameEquals { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the expand properties property. | ||
/// </summary> | ||
|
@@ -254,8 +271,10 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesTypeCollect | |
extensionResourceName: null); | ||
|
||
var odataQuery = QueryFilterBuilder.CreateFilter( | ||
subscriptionId: null, | ||
resourceGroup: this.ResourceGroupNameEquals, | ||
resourceType: null, | ||
resourceName: null, | ||
resourceName: this.ResourceNameEquals, | ||
tagName: this.TagName, | ||
tagValue: this.TagValue, | ||
filter: this.ODataQuery, | ||
|
@@ -279,10 +298,10 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInTenant() | |
{ | ||
var filterQuery = QueryFilterBuilder | ||
.CreateFilter( | ||
subscriptionIds: new Guid[] { this.SubscriptionId.Value }, | ||
resourceGroup: null, | ||
subscriptionId: this.SubscriptionId.HasValue ? this.SubscriptionId.Value.ToString() : null, | ||
resourceGroup: this.ResourceGroupNameEquals, | ||
resourceType: this.ResourceType, | ||
resourceName: null, | ||
resourceName: this.ResourceNameEquals, | ||
tagName: this.TagName, | ||
tagValue: this.TagValue, | ||
filter: this.ODataQuery, | ||
|
@@ -306,8 +325,10 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInResourceG | |
{ | ||
var filterQuery = QueryFilterBuilder | ||
.CreateFilter( | ||
subscriptionId: null, | ||
resourceGroup: this.ResourceGroupNameEquals, | ||
resourceType: this.ResourceType, | ||
resourceName: null, | ||
resourceName: this.ResourceNameEquals, | ||
tagName: this.TagName, | ||
tagValue: this.TagValue, | ||
filter: this.ODataQuery, | ||
|
@@ -333,8 +354,10 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInSubscript | |
{ | ||
var filterQuery = QueryFilterBuilder | ||
.CreateFilter( | ||
subscriptionId: null, | ||
resourceGroup: null, | ||
resourceType: this.ResourceType, | ||
resourceName: null, | ||
resourceName: this.ResourceNameEquals, | ||
tagName: this.TagName, | ||
tagValue: this.TagValue, | ||
filter: this.ODataQuery, | ||
|
@@ -429,7 +452,7 @@ private bool IsResourceTypeCollectionGet() | |
private bool IsSubscriptionLevelResourceTypeCollectionGet() | ||
{ | ||
return this.SubscriptionId.HasValue && | ||
this.ResourceGroupNameContains == null && | ||
!this.ResourceGroupNameAvailable() && | ||
(this.ResourceType != null || this.ExtensionResourceType != null); | ||
} | ||
|
||
|
@@ -439,7 +462,7 @@ private bool IsSubscriptionLevelResourceTypeCollectionGet() | |
private bool IsResourceGroupLevelResourceTypeCollectionGet() | ||
{ | ||
return this.SubscriptionId.HasValue && | ||
this.ResourceGroupNameContains != null && | ||
this.ResourceGroupNameAvailable() && | ||
(this.ResourceType != null || this.ExtensionResourceType != null); | ||
} | ||
|
||
|
@@ -450,7 +473,7 @@ private bool IsResourceGroupLevelResourceTypeCollectionGet() | |
private bool IsTenantLevelResourceTypeCollectionGet() | ||
{ | ||
return this.SubscriptionId == null && | ||
this.ResourceGroupNameContains == null && | ||
!this.ResourceGroupNameAvailable() && | ||
(this.ResourceType != null || this.ExtensionResourceType != null); | ||
} | ||
|
||
|
@@ -460,7 +483,7 @@ private bool IsTenantLevelResourceTypeCollectionGet() | |
private bool IsSubscriptionLevelQuery() | ||
{ | ||
return this.SubscriptionId.HasValue && | ||
this.ResourceGroupNameContains == null; | ||
!this.ResourceGroupNameAvailable(); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -469,11 +492,19 @@ private bool IsSubscriptionLevelQuery() | |
private bool IsResourceGroupLevelQuery() | ||
{ | ||
return this.SubscriptionId.HasValue && | ||
this.ResourceGroupNameContains != null && | ||
this.ResourceGroupNameAvailable() && | ||
(this.TagName != null || | ||
this.TagValue != null || | ||
this.ResourceType != null || | ||
this.ExtensionResourceType != null); | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if resource group name is availabe in parameters. | ||
/// </summary> | ||
private bool ResourceGroupNameAvailable() | ||
{ | ||
return this.ResourceGroupNameContains != null || this.ResourceGroupNameEquals != null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string.IsNullOrEmpty is better here, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems we have been doing null check for all parameters. I think we can keep it consistent. |
||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing the support for multiple subIds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't have any scenario that has mutiple subsIds in our repo now.