Skip to content

Commit

Permalink
Removing trailing spaces
Browse files Browse the repository at this point in the history
cleaning up script validation
  • Loading branch information
joel74 committed Aug 27, 2023
1 parent 0e885ab commit a993579
Show file tree
Hide file tree
Showing 35 changed files with 184 additions and 182 deletions.
2 changes: 2 additions & 0 deletions F5-LTM/F5-LTM.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Describe 'Get-BigIPPartition' -Tags 'Unit' {
$Link -replace 'localhost', $this.Name
} -PassThru

# Add the mock session to the Script scope
$Script:F5Session = $mocksession
#endregion Arrange: Initialize Mocks

It "Requests BigIP partitions *" {
Expand Down
4 changes: 2 additions & 2 deletions F5-LTM/F5-LTM.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ GUID = 'f4649254-d64a-407d-822f-66a4618ed5fb'
Author = 'Joel Newton'

# Company or vendor of this module
CompanyName = 'SpringCM, a DocuSign company'
CompanyName = ''

# Copyright statement for this module
Copyright = '(c) 2020 Joel Newton. All rights reserved.'
Copyright = '(c) 2023 Joel Newton. All rights reserved.'

# Description of the functionality provided by this module
Description = 'This module uses the REST API in the F5 LTM v11.6 and higher to query and manipulate the F5 LTM device.'
Expand Down
18 changes: 9 additions & 9 deletions F5-LTM/Private/Add-ObjectDetail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
Helper function to decorate an object with
- A TypeName
- New properties
- Default parameters
- Default parameters
.PARAMETER InputObject
Object to decorate. Accepts pipeline input.
.PARAMETER TypeName
Typename to insert.
This will show up when you use Get-Member against the resulting object.
.PARAMETER PropertyToAdd
Add these noteproperties.
Format is a hashtable with Key (Property Name) = Value (Property Value).
Example to add a One and Date property:
Expand Down Expand Up @@ -86,7 +86,7 @@
.NOTES
This breaks the 'do one thing' rule from certain perspectives...
The goal is to decorate an object all in one shot
This abstraction simplifies decorating an object, with a slight trade-off in performance. For example:
10,000 objects, add a property and typename:
Expand All @@ -98,7 +98,7 @@
.LINK
https://raw.githubusercontent.com/RamblingCookieMonster/PSStash/master/PSStash/Private/Add-ObjectDetail.ps1
#>
[cmdletBinding()]
[cmdletBinding()]
param(
[Parameter( Mandatory = $false,
Position=0,
Expand All @@ -110,7 +110,7 @@
[string]$TypeName,

[Parameter( Mandatory = $false,
Position=2)]
Position=2)]
[System.Collections.Hashtable]$PropertyToAdd,

[Parameter( Mandatory = $false,
Expand All @@ -121,7 +121,7 @@

[boolean]$Passthru = $True
)

Begin
{
if($PSBoundParameters.ContainsKey('DefaultProperties'))
Expand All @@ -142,7 +142,7 @@
foreach($Key in $PropertyToAdd.Keys)
{
#Add some noteproperties. Slightly faster than Add-Member.
$Object.PSObject.Properties.Add( ( New-Object PSNoteProperty($Key, $PropertyToAdd[$Key]) ) )
$Object.PSObject.Properties.Add( ( New-Object PSNoteProperty($Key, $PropertyToAdd[$Key]) ) )
}
}
'TypeName'
Expand Down
68 changes: 34 additions & 34 deletions F5-LTM/Private/ArgumentCompletion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
$Script:F5LTMPublicCommands = Get-ChildItem -Path ($PSScriptRoot -replace 'Private','Public') -Filter '*.ps1' -Recurse | Select-Object -ExpandProperty BaseName
function Get-F5Command {
<#
.SYNOPSIS
(Get-Command -Module F5-LTM) adversely affects module import performance.
.SYNOPSIS
(Get-Command -Module F5-LTM) adversely affects module import performance.
This is a much faster alternative without resorting to static command names
for Register-ArgumentCompleter -Command parameters.
#>
Expand All @@ -27,15 +27,15 @@ function CompleteMonitorName {
$wordToComplete,
$commandAst,
$fakeBoundParameters)
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-HealthMonitor -F5Session $Session -Partition $fakeBoundParameters.Partition -Type $fakeBoundParameters.Type | Where-Object { $_.name -like "$wordToComplete*" } | ForEach-Object {
if ($fakeBoundParameters.Partition) {
$_.name
} else {
$_.fullPath
$_.fullPath
}
}
}
}
}
function CompleteMonitorType {
Expand All @@ -44,7 +44,7 @@ function CompleteMonitorType {
$wordToComplete,
$commandAst,
$fakeBoundParameters)
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-HealthMonitorType -F5Session $Session | Where-Object { $_ -like "$wordToComplete*" }
}
Expand All @@ -55,10 +55,10 @@ function CompleteNodeAddress {
$wordToComplete,
$commandAst,
$fakeBoundParameters)
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-Node -F5Session $Session -Partition $fakeBoundParameters.Partition |
Where-Object { $_.address -like "$wordToComplete*" } |
Get-Node -F5Session $Session -Partition $fakeBoundParameters.Partition |
Where-Object { $_.address -like "$wordToComplete*" } |
Select-Object -ExpandProperty address
}
}
Expand All @@ -68,15 +68,15 @@ function CompleteNodeName {
$wordToComplete,
$commandAst,
$fakeBoundParameters)
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-Node -F5Session $Session -Partition $fakeBoundParameters.Partition | Where-Object { $_.name -like "$wordToComplete*" } | ForEach-Object {
if ($fakeBoundParameters.Partition) {
$_.name
} else {
$_.fullPath
$_.fullPath
}
}
}
}
}
function CompleteBIGIPPartition {
Expand All @@ -85,7 +85,7 @@ function CompleteBIGIPPartition {
$wordToComplete,
$commandAst,
$fakeBoundParameters)
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-BIGIPPartition -F5Session $Session | Where-Object { $_ -like "$wordToComplete*" }
}
Expand All @@ -97,10 +97,10 @@ function CompletePoolMemberAddress {
$commandAst,
$fakeBoundParameters)
if ($fakeBoundParameters.PoolName) {
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-PoolMember -F5Session $Session -PoolName $fakeBoundParameters.PoolName -Partition $fakeBoundParameters.Partition -Name (Invoke-NullCoalescing {$fakeBoundParameters.Name} {'*'}) |
Where-Object { $_.address -like "$wordToComplete*" } |
Get-PoolMember -F5Session $Session -PoolName $fakeBoundParameters.PoolName -Partition $fakeBoundParameters.Partition -Name (Invoke-NullCoalescing {$fakeBoundParameters.Name} {'*'}) |
Where-Object { $_.address -like "$wordToComplete*" } |
Select-Object -ExpandProperty address
}
}
Expand All @@ -112,10 +112,10 @@ function CompletePoolMemberName {
$commandAst,
$fakeBoundParameters)
if ($fakeBoundParameters.PoolName) {
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-PoolMember -F5Session $Session -PoolName $fakeBoundParameters.PoolName -Partition $fakeBoundParameters.Partition -Address (Invoke-NullCoalescing {$fakeBoundParameters.Address} {'*'}) |
Where-Object { $_.name -like "$wordToComplete*" } |
Get-PoolMember -F5Session $Session -PoolName $fakeBoundParameters.PoolName -Partition $fakeBoundParameters.Partition -Address (Invoke-NullCoalescing {$fakeBoundParameters.Address} {'*'}) |
Where-Object { $_.name -like "$wordToComplete*" } |
Select-Object -ExpandProperty name
}
}
Expand All @@ -127,10 +127,10 @@ function CompletePoolMonitorName {
$commandAst,
$fakeBoundParameters)
if ($fakeBoundParameters.PoolName) {
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-PoolMonitor -F5Session $Session -PoolName $fakeBoundParameters.PoolName -Partition $fakeBoundParameters.Partition |
Where-Object { $_.name -match "\b$wordToComplete*" } |
Get-PoolMonitor -F5Session $Session -PoolName $fakeBoundParameters.PoolName -Partition $fakeBoundParameters.Partition |
Where-Object { $_.name -match "\b$wordToComplete*" } |
Select-Object -ExpandProperty name
}
}
Expand All @@ -141,15 +141,15 @@ function CompletePoolName {
$wordToComplete,
$commandAst,
$fakeBoundParameters)
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-Pool -F5Session $Session -Partition $fakeBoundParameters.Partition | Where-Object { $_.name -like "$wordToComplete*" -or $_.fullPath -like "$wordToComplete*" } | ForEach-Object {
if ($fakeBoundParameters.Partition) {
$_.name
} else {
$_.fullPath
$_.fullPath
}
}
}
}
}
function CompleteRuleName {
Expand All @@ -158,15 +158,15 @@ function CompleteRuleName {
$wordToComplete,
$commandAst,
$fakeBoundParameters)
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-iRule -F5Session $Session -Partition $fakeBoundParameters.Partition | Where-Object { $_.name -like "$wordToComplete*" -or $_.fullPath -like "$wordToComplete" } | ForEach-Object {
if ($fakeBoundParameters.Partition) {
$_.name
} else {
$_.fullPath
$_.fullPath
}
}
}
}
}
function CompleteVirtualServerName {
Expand All @@ -175,15 +175,15 @@ function CompleteVirtualServerName {
$wordToComplete,
$commandAst,
$fakeBoundParameters)
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
$Session = Get-CompleteSession $fakeBoundParameters.F5Session
if ($Session) {
Get-VirtualServer -F5Session $Session -Partition $fakeBoundParameters.Partition | Where-Object { $_.name -like "$wordToComplete*" -or $_.fullPath -like "$wordToComplete" } | ForEach-Object {
if ($fakeBoundParameters.Partition) {
$_.name
} else {
$_.fullPath
$_.fullPath
}
}
}
}
}
if (Get-Command Register-ArgumentCompleter -ErrorAction Ignore)
Expand Down Expand Up @@ -232,17 +232,17 @@ if (Get-Command Register-ArgumentCompleter -ErrorAction Ignore)
-CommandName @(Get-F5Command '*') `
-ParameterName Partition `
-ScriptBlock $function:CompletePartition

Register-ArgumentCompleter `
-CommandName 'Get-BIGIPPartition' `
-ParameterName Name `
-ScriptBlock $function:CompleteBIGIPPartition

Register-ArgumentCompleter `
-CommandName @(Get-F5Command '*-Pool*') `
-ParameterName PoolName `
-ScriptBlock $function:CompletePoolName

Register-ArgumentCompleter `
-CommandName 'Get-iRule' `
-ParameterName Name `
Expand Down
8 changes: 4 additions & 4 deletions F5-LTM/Private/Invoke-F5RestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Function Invoke-F5RestMethod {
[OutputType([Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject])]
[OutputType([String])]
[OutputType([bool])]
param (
param (
[Parameter(Mandatory)][Microsoft.PowerShell.Commands.WebRequestMethod]$Method,
[Parameter(Mandatory)][uri]$URI,
[Parameter(Mandatory)]$F5Session,
Expand Down Expand Up @@ -40,10 +40,10 @@ Function Invoke-F5RestMethod {
try {
$message = $_.ErrorDetails.Message | ConvertFrom-json | Select-Object -expandproperty message
} catch {
$message = [string]$_.ErrorDetails.Message
$message = [string]$_.ErrorDetails.Message
}
$ErrorOutput = '"{0} {1}: {2}' -f $_.Exception.Response.StatusCode.value__,$_.Exception.Response.StatusDescription,(Invoke-NullCoalescing {$message} {$ErrorMessage})
$ErrorOutput = '"{0} {1}: {2}' -f $_.Exception.Response.StatusCode.value__,$_.Exception.Response.StatusDescription,(Invoke-NullCoalescing {$message} {$ErrorMessage})
Write-Error $ErrorOutput
}
}
}
}
6 changes: 3 additions & 3 deletions F5-LTM/Private/Invoke-NullCoalescing.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Function Invoke-NullCoalescing {
[Parameter(ValueFromPipeline, ParameterSetName='InputObject')]
[psobject]
$InputObject
)
Process {
)

Process {
if ($pscmdlet.ParameterSetName -eq 'InputObject') {
if ($PrimaryExpr -eq $null) {
Foreach-Object $AlternateExpr -InputObject $InputObject
Expand Down
2 changes: 1 addition & 1 deletion F5-LTM/Private/Join-Object.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
$AllProperty = $LeftProperty + $RightProperty | Select-Object -Unique

$LeftGroups = $Left | Group-Object $($On) -AsHashTable -AsString
$RightGroups = $Right | Group-Object $($OnRight) -AsHashTable -AsString
$RightGroups = $Right | Group-Object $($OnRight) -AsHashTable -AsString
}
process {
if ($null -eq $Left -and $null -eq $Right) {
Expand Down
2 changes: 1 addition & 1 deletion F5-LTM/Private/Resolve-NestedStats.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.SYNOPSIS
Between v11.6 and v12.0, there were breaking changes in regards to the JSON format returned for various iControlREST requests, such as when retrieving the system version or pool member stats.
Specifically, instead of the data existing in an "entries" property directly underneath the parent JSON object, it is now enclosed in "nestedStats" property within a custom PS object whose name resembles a self-link with the member name repeated.
To resolve this discrepancy, this function performs version-specific transformations to the JSON data and returns it in a standardized format with the "entries" property at the top.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")]
Expand Down
2 changes: 1 addition & 1 deletion F5-LTM/Public/Get-BIGIPPartition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
$URI = ($F5Session.BaseURL -replace 'ltm/','sys/folder') + '/{0}?$select=name,subPath' -f $itemname
$JSON = Invoke-F5RestMethod -Method Get -Uri $URI -F5Session $F5Session
Invoke-NullCoalescing {$JSON.items} {$JSON} |
Invoke-NullCoalescing {$JSON.items} {$JSON} |
Where-Object { $_.subPath -eq '/' -and ([string]::IsNullOrEmpty($Name) -or $Name -contains $_.name) } |
Select-Object -ExpandProperty name
}
Expand Down
2 changes: 1 addition & 1 deletion F5-LTM/Public/Get-F5Status.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Function Get-F5Status{
<#
.SYNOPSIS
.SYNOPSIS
Test whether the specified F5 is currently in active or standby failover mode
#>
[cmdletBinding()]
Expand Down
2 changes: 1 addition & 1 deletion F5-LTM/Public/Get-HealthMonitor.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
[string]$Partition,

[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
[string[]]$Type
)
Expand Down
4 changes: 2 additions & 2 deletions F5-LTM/Public/Get-HealthMonitorType.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
foreach ($itemname in $Name) {
$URI = $F5Session.BaseURL + 'monitor/'
$JSON = Invoke-F5RestMethod -Method Get -Uri $URI -F5Session $F5Session
$JSON.items.reference | ForEach-Object {
$JSON.items.reference | ForEach-Object {
[Regex]::Match($_.Link,'(?<=/)[^/?]*(?=\?)').Value |
Where-Object { $_ -like $itemname }
}
}
}
}
}
Loading

0 comments on commit a993579

Please sign in to comment.