-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Add ResourceGroup completer #4721
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
Add ResourceGroup completer #4721
Conversation
|
@azuresdkci Test this please |
| try | ||
| { | ||
| var instance = AzureSession.Instance; | ||
| var client = instance.ClientFactory.CreateCustomArmClient<ResourceManagementClient>( |
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.
Use the simpler CreateArmClient method here: https://github.com/Azure/azure-powershell/blob/preview/src/Common/Commands.Common.Authentication.Abstractions/Interfaces/IClientFactory.cs#L39
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.
Staying the same as discussed offline
| instance.AuthenticationFactory.GetServiceClientCredentials(context, AzureEnvironment.Endpoint.ResourceManager), | ||
| instance.ClientFactory.GetCustomHandlers()); | ||
| //var client = AzureSession.Instance.ClientFactory.CreateArmClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager); | ||
| client.SubscriptionId = context.Subscription.Id; |
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.
If you use this method, you will not need to set the subscription id
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.
Same
| { | ||
| if (resourceGroups.Result != null) | ||
| { | ||
| var resourceGroupList = resourceGroups.Result.ToList(); |
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 write it to a list instead of just using it in the ForEach?
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.
Also, here we are making a conscious decision to only use the first page of results each time. We should probably call this out with a comment. BTW - ho9w many resource groups are in the first page of results?
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.
I couldn't figure out how many are in the first page - it wasn't in any of the code or documentation about IPage or List and it's more than my biggest subscription (92). Not sure if there's another place I should look.
|
|
||
| else | ||
| { | ||
| #if DEBUG |
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.
Seems like this if should surround the entire else clause
|
|
||
| else | ||
| { | ||
| #if DEBUG |
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.
same comment
| { | ||
| if (defaultResourceGroup != null) | ||
| { | ||
| if (resourceGroupNames.Contains(defaultResourceGroup)) |
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.
What if the default resource group is on page 2 of the results? Seems like we should always include the defautl resource group at the beginning
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.
If the user types out part of a name not including the default resource group, I think it makes sense not to include the default resource group. Let me know if I should include it.
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.
Agreed, but it still could be in the second page of results
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.
Still waiting to hear back from the Resources team about if it is possible to query Resource Groups by name
| public void ReturnsEmptyListWhenNoResourceGroupsExist() | ||
| { | ||
| IList<string> resourceGroupsReturned = new List<string>(); | ||
|
|
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.
remove extra lines between statements.
| { | ||
| IList<string> resourceGroupsReturned = new List<string>(); | ||
| resourceGroupsReturned.Add("test1"); | ||
|
|
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.
remove extra lines
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.
(apply everywhere in this file)
| resourceGroupsReturned.Add("test3"); | ||
| resourceGroupsReturned.Add("test4"); | ||
|
|
||
| Assert.Equal(ResourceGroupCompleterAttribute.GetResourceGroups(resourceGroupsReturned, null), new string[] { "test1", "test2", "test3", "test4" }); |
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.
consider using Assert.Collection for succinctly testing the properties of a known collection and its elements, when in a known order. Note this this is advisroy only (and prompting you to check out the assertiosn available int eh xunit library)
| { | ||
| if (defaultResourceGroup != null) | ||
| { | ||
| if (resourceGroupNames.Contains(defaultResourceGroup)) |
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.
Agreed, but it still could be in the second page of results
| { | ||
| IAzureContext context = AzureRmProfileProvider.Instance.Profile.DefaultContext; | ||
| var resourceGroupNamesCopy = ResourceGroupNames; | ||
| if (context.ExtendedProperties.ContainsKey(Resources.DefaultResourceGroupKey)) |
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.
Use context.IsPropertySet
| lock (_lock) | ||
| { | ||
| _resourceGroupNames = new List<string>(); | ||
| IAzureContext context = AzureRmProfileProvider.Instance.Profile.DefaultContext; |
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.
How long is this taking? I wonder if we will need to do some caching here. Let's discuss and decide how to proceed.
…nto ResourceCompleter1
|
@maddieclayton there are merge conflicts after the namespace update |
|
Optimistic on-demand run here: https://azuresdkci.westus2.cloudapp.azure.com/view/PowerShell/job/powershell-demand/47/ |
|
@markcowl Are there more changes that this PR needs? |
markcowl
left a comment
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.
A couple of comments. Overall, this looks good.
| } | ||
| } | ||
|
|
||
| return _resourceGroupNamesDictionary[contextHash]; |
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.
so, if we haven't previously cached a value and the call actually times out in production, this will fall through to here, which will null ref, I think. We probably need to store the result in a local variable and return that, with the default value beign returned if the call to list resource groups times out.
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.
Done
| { | ||
| public class ResourceGroupCompleterUnitTests | ||
| { | ||
| [Fact] |
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.
To test completely, we should think about throwing an exception from the client, verifying the behavior.
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.
Done
|
@azuresdkci Test this please |
Description
Creates a ResourceGroupCompleter. Shows the first 50 resource groups that match the string the user has types. Default resource group will be put first in the list if it has been set. #4665
This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.
General Guidelines
Testing Guidelines
Cmdlet Signature Guidelines
ShouldProcessand haveSupportShouldProcess=truespecified in the cmdlet attribute. You can find more information onShouldProcesshere.OutputTypeattribute if any output is produced - if the cmdlet produces no output, it should implement aPassThruparameter.Cmdlet Parameter Guidelines