-
Notifications
You must be signed in to change notification settings - Fork 4k
Tab completer for existing resources (Iss #5415) #6163
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
Tab completer for existing resources (Iss #5415) #6163
Conversation
iss #5415 |
cdbda1a
to
770fbc0
Compare
@vladimir-shcherbakov is this ready for review? If not, please add the "Do not merge" tag. |
@maddieclayton |
} | ||
|
||
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.
I fixed the CreateArmClient so we can just use this call now: https://github.com/Azure/azure-powershell/blob/preview/src/ResourceManager/Common/Commands.ResourceManager.Common/ArgumentCompleters/ResourceGroupCompleter.cs#L51
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.
fixed
instance.AuthenticationFactory.GetServiceClientCredentials(context, AzureEnvironment.Endpoint.ResourceManager), | ||
instance.ClientFactory.GetCustomHandlers()); | ||
|
||
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.
This can be removed once the call above is changed.
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.
fixed
IEnumerable<string> resourceInfoList; | ||
try | ||
{ | ||
resourceInfoList = client.Resources.List(odata) |
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.
This should be an async call so that we can have an automatic timeout (we don't want to have this pending for more than a few seconds, as it completely disables the powershell window) - see here: https://github.com/Azure/azure-powershell/blob/preview/src/ResourceManager/Common/Commands.ResourceManager.Common/ArgumentCompleters/ResourceGroupCompleter.cs#L53
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.
fixed
$"$resourceGroupParameterName = \"{resourceGroupParameterName ?? "$Null"}\"\n" + | ||
$"$nodeServiceParameterName = \"{nodeServiceParameterName ?? "$Null"}\"\n" + | ||
"$ids = [Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.ResourceNameCompleterAttribute]::GetResources($resourceType)\n" + | ||
"if ($resourceGroupParameterName -ne $Null -and $fakeBoundParameters.Contains($resourceGroupParameterName)) { $ids = $ids | Where-Object { $_.Group -eq $resourceGroupParameterName }}\n" + |
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 resourcegroupname is not null, you should make the SDK call with the resourcegroupname set - this will probably be a lot faster than getting by type and then filtering by resourcegroup.
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.
In this context, if a user has provided a resource group name:
Get-AzrureRmSomething -ResouceGroupName "grName" -SomethingName ...
It gets used as a filter for the next SomethingName
argument.
base(CreateScriptBlock( | ||
resourceType, | ||
resourceGroupParameterName, | ||
nodeServiceParameterName)) |
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 happens if the resource is further than two levels deep (as in the case of SQL resources)?
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.
Depth more than two levels is not supported now.
for example, for this resource id:
/subscriptions/{sub-id}/resourceGroups/{rg-name}/providers/Microsoft.Sql/servers/{server-name}/databases/{db-name}/key1/val1
it returns
{db-name}
I think if a request follows to support depth more than two levels - it can be quickly satisfied without breaking changes.
private static class Patterns | ||
{ | ||
// example: /subscriptions/1c638cf4-608f-4ee6-b680-c329e824c3a8/resourceGroups/rgrssdfw69c0219330/providers/Microsoft.Sql/servers/sqlserver2c5254480/databases/master | ||
private const string SubscripitonId = @"([0-9a-f]{8}[-][0-9a-f]{4}[-][0-9a-f]{4}[-][0-9a-f]{4}[-][0-9a-f]{12})"; |
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.
subscription spelled wrong
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.
fixed
|
||
public static ResourceInfo FromResourceId(string resourceId) | ||
{ | ||
var match = Regex.Match(resourceId, Patterns.ResourceId, RegexOptions.IgnoreCase); |
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.
The numbers here seem a little magically to me, but this is fine as long as you've tested it on resources at multiple levels.
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.
2 levels only
@@ -48,5 +48,19 @@ public void TestResourceGroupCompleter() | |||
{ | |||
ProfileController.NewInstance.RunPsTest(xunitLogger, "72f988bf-86f1-41af-91ab-2d7cd011db47", "Test-ResourceGroupCompleter"); | |||
} | |||
|
|||
[Fact] | |||
[Trait(Category.AcceptanceType, Category.Flaky)] |
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 did you add flaky?
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.
copied from other completes tests.
fixed
Assert-AreEqualArray $resourceNames $expectResourceNames | ||
# change time to update the cache | ||
[Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.ResourceNameCompleterAttribute]::TimeToUpdate = [System.TimeSpan]::FromSeconds(1) | ||
Start-Sleep -Seconds 1 |
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 wait-seconds: https://github.com/Azure/azure-powershell/blob/preview/src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/Common.ps1#L307. We don't allow sleeps in tests.
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.
fixed
Assert-AreEqualArray $resourceIds $expectResourceIds | ||
# change time to update the cache | ||
[Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.ResourceIdCompleterAttribute]::TimeToUpdate = [System.TimeSpan]::FromSeconds(1) | ||
Start-Sleep -Seconds 1 |
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 here.
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.
fixed
@vladimir-shcherbakov Looks like your test is failing on travis - please check |
@vladimir-shcherbakov Can you remove ResourceNameCompleter? |
9e171ed
to
f5f60eb
Compare
ResourceNameCompleter removed |
|
||
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.
Remove this, the "createarmclient" call does this automatically
@vladimir-shcherbakov One small comment then LGTM. Updated your PR to include the changelog fix, so should pass this time. |
Description
Checklist
CONTRIBUTING.md
platyPS
module