mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-15 02:35:46 +00:00
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:
parent
ddf1d22e18
commit
8167b0dbf0
61 changed files with 2779 additions and 2737 deletions
10
.vscode/settings.json
vendored
Normal file
10
.vscode/settings.json
vendored
Normal 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,
|
||||
}
|
||||
}
|
||||
|
|
@ -105,6 +105,7 @@ function Get-NetboxCircuit {
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process {
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'ById' {
|
||||
foreach ($i in $ID) {
|
||||
|
|
@ -129,3 +130,4 @@ function Get-NetboxCircuit {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -54,6 +54,7 @@ function New-NetboxCircuit {
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
|
||||
$Method = 'POST'
|
||||
|
||||
|
|
@ -65,3 +66,4 @@ function New-NetboxCircuit {
|
|||
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -85,6 +85,7 @@ function Get-NetboxDCIMDevice {
|
|||
|
||||
#endregion Parameters
|
||||
|
||||
process {
|
||||
if ($null -ne $Status) {
|
||||
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
|
||||
}
|
||||
|
|
@ -97,3 +98,4 @@ function Get-NetboxDCIMDevice {
|
|||
|
||||
InvokeNetboxRequest -URI $URI -Raw:$Raw
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,8 @@
|
|||
|
||||
|
||||
function New-NetboxDCIMDevice {
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding(ConfirmImpact = 'low',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([pscustomobject])]
|
||||
#region Parameters
|
||||
param
|
||||
|
|
@ -67,15 +68,15 @@ function New-NetboxDCIMDevice {
|
|||
# if ($null -ne $Device_Role) {
|
||||
# # Validate device role?
|
||||
# }
|
||||
#
|
||||
|
||||
# if ($null -ne $Device_Type) {
|
||||
# # Validate device type?
|
||||
# }
|
||||
#
|
||||
|
||||
# if ($null -ne $Status) {
|
||||
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
|
||||
# }
|
||||
#
|
||||
|
||||
# if ($null -ne $Face) {
|
||||
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
|
||||
# }
|
||||
|
|
@ -86,5 +87,7 @@ function New-NetboxDCIMDevice {
|
|||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($Name, 'Create new Device')) {
|
||||
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
|
||||
}
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ function Set-NetboxDCIMDevice {
|
|||
# if ($null -ne $Status) {
|
||||
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
|
||||
# }
|
||||
#
|
||||
|
||||
# if ($null -ne $Face) {
|
||||
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
|
||||
# }
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ function Add-NetboxDCIMInterfaceConnection {
|
|||
}
|
||||
|
||||
# Verify if both Interfaces exist
|
||||
$I_A = Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop
|
||||
$I_B = Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop
|
||||
Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop | Out-null
|
||||
Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop | Out-null
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ function Get-NetboxDCIMInterface {
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process {
|
||||
if ($null -ne $Form_Factor) {
|
||||
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
|
||||
}
|
||||
|
|
@ -59,3 +60,4 @@ function Get-NetboxDCIMInterface {
|
|||
|
||||
InvokeNetboxRequest -URI $URI -Raw:$Raw
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,8 @@
|
|||
|
||||
|
||||
function Set-NetboxDCIMInterface {
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding(ConfirmImpact = 'Medium',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
(
|
||||
|
|
@ -88,9 +89,11 @@ function Set-NetboxDCIMInterface {
|
|||
|
||||
$URI = BuildNewURI -Segments $Segments
|
||||
|
||||
if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) {
|
||||
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ function Get-NetboxDCIMSite {
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process {
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'ById' {
|
||||
foreach ($Site_ID in $ID) {
|
||||
|
|
@ -105,4 +106,5 @@ function Get-NetboxDCIMSite {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
|
||||
function New-NetboxIPAMPrefix {
|
||||
[CmdletBinding(ConfirmImpact = 'low',
|
||||
SupportsShouldProcess = $true)]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
|
|
@ -55,5 +57,7 @@ function New-NetboxIPAMPrefix {
|
|||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($Prefix, 'Create new Prefix')) {
|
||||
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,8 @@
|
|||
Additional information about the function.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding(ConfirmImpact = 'low',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
(
|
||||
|
|
@ -64,7 +65,7 @@
|
|||
)
|
||||
|
||||
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
|
||||
#
|
||||
|
||||
# if ($null -ne $Role) {
|
||||
# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
|
||||
# }
|
||||
|
|
@ -75,5 +76,7 @@
|
|||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($nae, 'Create new Vlan $($vid)')) {
|
||||
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
|
||||
}
|
||||
}
|
||||
|
|
@ -141,6 +141,7 @@ function Get-NetboxVirtualMachine {
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process {
|
||||
if ($null -ne $Status) {
|
||||
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
|
||||
}
|
||||
|
|
@ -153,3 +154,4 @@ function Get-NetboxVirtualMachine {
|
|||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,8 @@
|
|||
|
||||
|
||||
function New-NetboxVirtualMachine {
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding(ConfirmImpact = 'low',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([pscustomobject])]
|
||||
param
|
||||
(
|
||||
|
|
@ -47,12 +48,12 @@ function New-NetboxVirtualMachine {
|
|||
)
|
||||
|
||||
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
|
||||
#
|
||||
|
||||
# # Validate the status against the APIDefinition
|
||||
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
|
||||
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
|
||||
# }
|
||||
#
|
||||
|
||||
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
|
||||
|
|
@ -61,8 +62,10 @@ function New-NetboxVirtualMachine {
|
|||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) {
|
||||
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ function Set-NetboxVirtualMachine {
|
|||
# if ($null -ne $Status) {
|
||||
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
|
||||
# }
|
||||
#
|
||||
|
||||
process {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
|
||||
|
||||
Write-Verbose "Obtaining VM from ID $Id"
|
||||
|
|
@ -70,3 +71,4 @@ function Set-NetboxVirtualMachine {
|
|||
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -84,6 +84,7 @@ function Get-NetboxVirtualMachineInterface {
|
|||
[switch]$Raw
|
||||
)
|
||||
|
||||
process {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||
|
|
@ -92,3 +93,4 @@ function Get-NetboxVirtualMachineInterface {
|
|||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
}
|
||||
}
|
||||
|
|
@ -3323,15 +3323,15 @@ function New-NetboxDCIMDevice {
|
|||
# if ($null -ne $Device_Role) {
|
||||
# # Validate device role?
|
||||
# }
|
||||
#
|
||||
|
||||
# if ($null -ne $Device_Type) {
|
||||
# # Validate device type?
|
||||
# }
|
||||
#
|
||||
|
||||
# if ($null -ne $Status) {
|
||||
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
|
||||
# }
|
||||
#
|
||||
|
||||
# if ($null -ne $Face) {
|
||||
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
|
||||
# }
|
||||
|
|
@ -3610,7 +3610,7 @@ function New-NetboxIPAMVLAN {
|
|||
)
|
||||
|
||||
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
|
||||
#
|
||||
|
||||
# if ($null -ne $Role) {
|
||||
# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
|
||||
# }
|
||||
|
|
@ -3677,12 +3677,12 @@ function New-NetboxVirtualMachine {
|
|||
)
|
||||
|
||||
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
|
||||
#
|
||||
|
||||
# # Validate the status against the APIDefinition
|
||||
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
|
||||
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
|
||||
# }
|
||||
#
|
||||
|
||||
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
|
||||
|
|
@ -4160,7 +4160,7 @@ function Set-NetboxDCIMDevice {
|
|||
# if ($null -ne $Status) {
|
||||
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
|
||||
# }
|
||||
#
|
||||
|
||||
# if ($null -ne $Face) {
|
||||
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
|
||||
# }
|
||||
|
|
@ -4774,7 +4774,7 @@ function Set-NetboxVirtualMachine {
|
|||
# if ($null -ne $Status) {
|
||||
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
|
||||
# }
|
||||
#
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
|
||||
|
||||
Write-Verbose "Obtaining VM from ID $Id"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue