Skip to content

Commit

Permalink
Merge pull request #7 from alagoutte/filtering-like
Browse files Browse the repository at this point in the history
Add like option for Filtering
  • Loading branch information
alagoutte committed Jul 21, 2021
2 parents 58742d5 + d1bd179 commit c82d546
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions PowerFMG/Private/RestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ function Invoke-FMGRestMethod {
$afilter += ("contain")
$afilter += ($filter_value)
}
"like" {
$afilter += ("like")
$afilter += ("%" + $filter_value + "%")
}
#by default set to equal..
default {
$afilter += ("==")
Expand Down
6 changes: 3 additions & 3 deletions PowerFMG/Public/pm/firewall/address.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ function Get-FMGFirewallAddress {
Get address named myFMGAddress
.EXAMPLE
Get-FMGFirewallAddress -name FMG -filter_type contains
Get-FMGFirewallAddress -name FMG -filter_type like
Get address contains with *FMG*
Get address like with %FMG%
.EXAMPLE
Get-FMGFirewallAddress -uuid 9e73a10e-1772-51ea-a8d7-297686fd7702
Expand All @@ -234,7 +234,7 @@ function Get-FMGFirewallAddress {
[Parameter (ParameterSetName = "name")]
[Parameter (ParameterSetName = "uuid")]
[Parameter (ParameterSetName = "filter")]
[ValidateSet('equal', 'contains')]
[ValidateSet('equal', 'contains', 'like')]
[string]$filter_type = "equal",
[Parameter (Mandatory = $false)]
[Parameter (ParameterSetName = "filter")]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,20 @@ and Filter Operators :
For `Invoke-FMGRestMethod` and `Get-XXX` cmdlet like `Get-FMGFirewallAddress`, it is possible to using some helper filter (`-filter_attribute`, `-filter_type`, `-filter_value`)

```powershell
# Get NetworkDevice named myFMG
# Get Firewall Address named myFMG
Get-FMGFirewallAddress -name myFMG
...
# Get NetworkDevice contains myFMG
Get-FMGFirewallAddress -name myFMG -filter_type contains
# Get Firewall Address where (like) %myFMG%
Get-FMGFirewallAddress -name myFMG -filter_type like
...
# Get NetworkDevice where subnet equal 192.0.2.0 255.255.255.0
# Get Firewall Address where subnet equal 192.0.2.0 255.255.255.0
Get-FMGFirewallAddress -filter_attribute subnet -filter_type equal -filter_value 192.0.2.0 255.255.255.0
...
```
Actually, support only `equal` and `contains` filter type
Actually, support only `equal`, `contains` and `like` filter type

### Invoke API
for example to get FortiManager System Status Info
Expand Down
5 changes: 5 additions & 0 deletions Tests/integration/FirewallAddress.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Describe "Get Firewall Address" {

Context "Search" {

It "Search Address with like (%login%)" {
$address = Get-FMGFirewallAddress -filter_type like -filter_value login
@($address).count | Should -Not -Be 0
}

It "Search Address by name ($pester_address1)" {
$address = Get-FMGFirewallAddress -name $pester_address1
@($address).count | Should -be 1
Expand Down

0 comments on commit c82d546

Please sign in to comment.