Fix PSSA Warning (#20)

* Fix trailing white space

using Invoke-ScriptAnalyzer -Fix -Path . -Recurse

* add settings.json for configure Visual Code (Formatter)

* PSSA: Fix Command accepts pipeline input but has not defined a process block

* PSSA: Fix PSUseDeclaredVarsMoreThanAssignments

The variable 'I_B' is assigned but never used
The variable 'I_A' is assigned but never used

* PSSA: Fix PSUseShouldProcessForStateChangingFunctions

Function New-/Set-... has verb that could change system state. Therefore, the function has to support 'ShouldProcess'
This commit is contained in:
Alexis La Goutte 2021-07-23 22:06:42 +02:00 committed by GitHub
parent ddf1d22e18
commit 8167b0dbf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 2779 additions and 2737 deletions

10
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,10 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
"powershell.scriptAnalysis.settingsPath": ".vscode/PSScriptAnalyzerSettings.psd1",
"powershell.codeFormatting.newLineAfterCloseBrace": false,
"[markdown]": {
"files.trimTrailingWhitespace": false,
}
}

View file

@ -105,6 +105,7 @@ function Get-NetboxCircuit {
[switch]$Raw [switch]$Raw
) )
process {
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($i in $ID) { foreach ($i in $ID) {
@ -129,3 +130,4 @@ function Get-NetboxCircuit {
} }
} }
} }
}

View file

@ -54,6 +54,7 @@ function New-NetboxCircuit {
[switch]$Raw [switch]$Raw
) )
process {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits')) $Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
$Method = 'POST' $Method = 'POST'
@ -65,3 +66,4 @@ function New-NetboxCircuit {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
} }
} }
}

View file

@ -85,6 +85,7 @@ function Get-NetboxDCIMDevice {
#endregion Parameters #endregion Parameters
process {
if ($null -ne $Status) { if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
} }
@ -97,3 +98,4 @@ function Get-NetboxDCIMDevice {
InvokeNetboxRequest -URI $URI -Raw:$Raw InvokeNetboxRequest -URI $URI -Raw:$Raw
} }
}

View file

@ -13,7 +13,8 @@
function New-NetboxDCIMDevice { function New-NetboxDCIMDevice {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
#region Parameters #region Parameters
param param
@ -67,15 +68,15 @@ function New-NetboxDCIMDevice {
# if ($null -ne $Device_Role) { # if ($null -ne $Device_Role) {
# # Validate device role? # # Validate device role?
# } # }
#
# if ($null -ne $Device_Type) { # if ($null -ne $Device_Type) {
# # Validate device type? # # Validate device type?
# } # }
#
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }
@ -86,5 +87,7 @@ function New-NetboxDCIMDevice {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Name, 'Create new Device')) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
} }
}

View file

@ -67,7 +67,7 @@ function Set-NetboxDCIMDevice {
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }

View file

@ -54,8 +54,8 @@ function Add-NetboxDCIMInterfaceConnection {
} }
# Verify if both Interfaces exist # Verify if both Interfaces exist
$I_A = Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop | Out-null
$I_B = Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop | Out-null
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections')) $Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))

View file

@ -47,6 +47,7 @@ function Get-NetboxDCIMInterface {
[switch]$Raw [switch]$Raw
) )
process {
if ($null -ne $Form_Factor) { if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
} }
@ -59,3 +60,4 @@ function Get-NetboxDCIMInterface {
InvokeNetboxRequest -URI $URI -Raw:$Raw InvokeNetboxRequest -URI $URI -Raw:$Raw
} }
}

View file

@ -13,7 +13,8 @@
function Set-NetboxDCIMInterface { function Set-NetboxDCIMInterface {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -88,9 +89,11 @@ function Set-NetboxDCIMInterface {
$URI = BuildNewURI -Segments $Segments $URI = BuildNewURI -Segments $Segments
if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
}
end { end {

View file

@ -81,6 +81,7 @@ function Get-NetboxDCIMSite {
[switch]$Raw [switch]$Raw
) )
process {
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'ById' { 'ById' {
foreach ($Site_ID in $ID) { foreach ($Site_ID in $ID) {
@ -105,4 +106,5 @@ function Get-NetboxDCIMSite {
} }
} }
} }
}

View file

@ -13,6 +13,8 @@
function New-NetboxIPAMPrefix { function New-NetboxIPAMPrefix {
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[CmdletBinding()] [CmdletBinding()]
param param
( (
@ -55,5 +57,7 @@ function New-NetboxIPAMPrefix {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Prefix, 'Create new Prefix')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
} }
}

View file

@ -40,7 +40,8 @@
Additional information about the function. Additional information about the function.
#> #>
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -64,7 +65,7 @@
) )
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
#
# if ($null -ne $Role) { # if ($null -ne $Role) {
# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole # $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
# } # }
@ -75,5 +76,7 @@
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($nae, 'Create new Vlan $($vid)')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
} }
}

View file

@ -141,6 +141,7 @@ function Get-NetboxVirtualMachine {
[switch]$Raw [switch]$Raw
) )
process {
if ($null -ne $Status) { if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
} }
@ -153,3 +154,4 @@ function Get-NetboxVirtualMachine {
InvokeNetboxRequest -URI $uri -Raw:$Raw InvokeNetboxRequest -URI $uri -Raw:$Raw
} }
}

View file

@ -13,7 +13,8 @@
function New-NetboxVirtualMachine { function New-NetboxVirtualMachine {
[CmdletBinding()] [CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])] [OutputType([pscustomobject])]
param param
( (
@ -47,12 +48,12 @@ function New-NetboxVirtualMachine {
) )
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext # $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
#
# # Validate the status against the APIDefinition # # Validate the status against the APIDefinition
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) { # if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) # throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
# } # }
#
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
@ -61,8 +62,10 @@ function New-NetboxVirtualMachine {
$URI = BuildNewURI -Segments $URIComponents.Segments $URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
} }
}

View file

@ -53,7 +53,8 @@ function Set-NetboxVirtualMachine {
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus # $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
# } # }
#
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
Write-Verbose "Obtaining VM from ID $Id" Write-Verbose "Obtaining VM from ID $Id"
@ -70,3 +71,4 @@ function Set-NetboxVirtualMachine {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
} }
} }
}

View file

@ -84,6 +84,7 @@ function Get-NetboxVirtualMachineInterface {
[switch]$Raw [switch]$Raw
) )
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters $URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
@ -92,3 +93,4 @@ function Get-NetboxVirtualMachineInterface {
InvokeNetboxRequest -URI $uri -Raw:$Raw InvokeNetboxRequest -URI $uri -Raw:$Raw
} }
}

View file

@ -3323,15 +3323,15 @@ function New-NetboxDCIMDevice {
# if ($null -ne $Device_Role) { # if ($null -ne $Device_Role) {
# # Validate device role? # # Validate device role?
# } # }
#
# if ($null -ne $Device_Type) { # if ($null -ne $Device_Type) {
# # Validate device type? # # Validate device type?
# } # }
#
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }
@ -3610,7 +3610,7 @@ function New-NetboxIPAMVLAN {
) )
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus # $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
#
# if ($null -ne $Role) { # if ($null -ne $Role) {
# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole # $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
# } # }
@ -3677,12 +3677,12 @@ function New-NetboxVirtualMachine {
) )
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext # $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
#
# # Validate the status against the APIDefinition # # Validate the status against the APIDefinition
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) { # if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', ')) # throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
# } # }
#
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus #$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines')) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
@ -4160,7 +4160,7 @@ function Set-NetboxDCIMDevice {
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus # $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# } # }
#
# if ($null -ne $Face) { # if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace # $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# } # }
@ -4774,7 +4774,7 @@ function Set-NetboxVirtualMachine {
# if ($null -ne $Status) { # if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus # $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
# } # }
#
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id)) $Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
Write-Verbose "Obtaining VM from ID $Id" Write-Verbose "Obtaining VM from ID $Id"