Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Client-side filtering #393

Merged
merged 18 commits into from Jan 24, 2018
Merged

Conversation

brywang-msft
Copy link
Collaborator

Fixes:

  • Quick fix for when psmeta file doesn't contain optional properties

Features:

  • Client-side filtering support. Azure/AzureStack will automatically add client-side filtering for the "Name" property of the object when *_Get and *_List cmdlets are combined. In general usage, this feature is not recommended. Multiple filters are AND'd together.
  • run-tests.ps1 has -Tag support

Example of filtering:

# Get all batch accounts
$accounts = Get-BatchAccount
$accounts.Count # 3
$accounts.Name # "test", "tom", "bob"
$accounts = Get-BatchAccount -Name test -ResourceGroupName test
$accounts.Count # 1
$accounts = Get-BatchAccount -Name t* -ResourceGroupName test
$accounts.Count #2

"clientSideParameterSet": "BatchAccount_Get",
"filters": ...
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently, I see only one element is allowed.
Should we support an array of x-ps-client-side-filter in x-ps-cmdlet-info Object for providing this wild card support for other clientSideParameterSet parameter sets?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Field Name | Type | Description
---|:---:|---
type | `string` | Type of filter. Supported: 'wildcard', 'logicalOperation'
Copy link
Collaborator

Choose a reason for hiding this comment

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

logicalOperation [](start = 58, length = 16)

What is the purpose of logicalOperation type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if (-not $clientSideParameterSet) {
# Warning: Missing client-side parameter
Write-Warning "Required server-side parameter '$($parameterDetailEntry.Value.Name)' is not required by the client-side, which will cause issues in client-side filtering. Can't include client-side filtering."
$valid = $false
Copy link
Collaborator

Choose a reason for hiding this comment

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

$valid [](start = 40, length = 6)

Is this required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


$regex = $Filter.Value.Replace($Filter.Character, ".*")
($Result.($Filter.Property)) -match $regex
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please consider using System.Management.Automation.WildcardPattern.

For example:
$inputNameWithOptionalWildcard = "Module*"
$resultName = "ModuleName"

$wildcardOptions = [System.Management.Automation.WildcardOptions]::CultureInvariant -bor [System.Management.Automation.WildcardOptions]::IgnoreCase
$wildcardPattern = New-Object System.Management.Automation.WildcardPattern $inputNameWithOptionalWildcard,$wildcardOptions
$wildcardPattern.IsMatch($resultName)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed to change default to '%' but option to change needs to stay (for cases where '%' is valid in the parameter string).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@brywang-msft
Copy link
Collaborator Author

brywang-msft commented Jan 18, 2018

Also move strings to Resources.psd1

Fixed: 4d0c04f

foreach ($parameterDetailEntry in $parametersDetail.GetEnumerator()) {
$getParameters += $parameterDetailEntry.Value
if ($parameterDetailEntry.Value.ContainsKey('Alias')) {
if ($parameterDetailEntry.Value.Alias -eq 'Name') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actual parameter name of a resource can be Name itself. In that case, wildcard functionality is not enabled, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

bmanikm
bmanikm previously approved these changes Jan 23, 2018
Copy link
Collaborator

@bmanikm bmanikm left a comment

Choose a reason for hiding this comment

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

:shipit:

@brywang-msft
Copy link
Collaborator Author

Add 'powershellWildcard' filter

@brywang-msft
Copy link
Collaborator Author

Add option for Azure not to automatically generate filter

@brywang-msft brywang-msft merged commit 21671ec into PowerShell:developer Jan 24, 2018
@brywang-msft brywang-msft deleted the 1-16-2018 branch January 24, 2018 21:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants