Skip to content

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

Merged
merged 8 commits into from
Jun 13, 2018

Conversation

vladimir-shcherbakov
Copy link
Contributor

@vladimir-shcherbakov vladimir-shcherbakov commented May 8, 2018

Description

Checklist

@vladimir-shcherbakov
Copy link
Contributor Author

iss #5415

@vladimir-shcherbakov vladimir-shcherbakov force-pushed the iss#5415 branch 3 times, most recently from cdbda1a to 770fbc0 Compare May 16, 2018 01:16
@maddieclayton
Copy link
Contributor

@vladimir-shcherbakov is this ready for review? If not, please add the "Do not merge" tag.

@vladimir-shcherbakov
Copy link
Contributor Author

@maddieclayton
Yes, it's ready.

@vladimir-shcherbakov vladimir-shcherbakov changed the title [Design] Tab completer for existing resources (Iss #5415) Tab completer for existing resources (Iss #5415) May 23, 2018
}

var instance = AzureSession.Instance;
var client = instance.ClientFactory.CreateCustomArmClient<ResourceManagementClient>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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" +
Copy link
Contributor

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.

Copy link
Contributor Author

@vladimir-shcherbakov vladimir-shcherbakov Jun 8, 2018

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))
Copy link
Contributor

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)?

Copy link
Contributor Author

@vladimir-shcherbakov vladimir-shcherbakov Jun 8, 2018

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})";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subscription spelled wrong

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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)]
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@maddieclayton
Copy link
Contributor

@vladimir-shcherbakov Looks like your test is failing on travis - please check

@maddieclayton
Copy link
Contributor

@vladimir-shcherbakov Can you remove ResourceNameCompleter?

@vladimir-shcherbakov
Copy link
Contributor Author

ResourceNameCompleter removed


var client = AzureSession.Instance.ClientFactory.CreateArmClient<ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);

client.SubscriptionId = context.Subscription.Id;
Copy link
Contributor

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

@maddieclayton
Copy link
Contributor

@vladimir-shcherbakov One small comment then LGTM. Updated your PR to include the changelog fix, so should pass this time.

maddieclayton
maddieclayton previously approved these changes Jun 12, 2018
@praries880
Copy link
Contributor

@praries880 praries880 changed the base branch from preview to release-06-15-18 June 13, 2018 17:46
@praries880 praries880 merged commit 036d75f into Azure:release-06-15-18 Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants