mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-15 02:35:46 +00:00
Version 1.4 (#14)
* Connect(Setup): Fix indent (using Visual code Formatter) * Setup(Functions): Fix indent (using Visual Code Formatter) * Support(Setup): Fix indent (using Visual Code Formatter) * InvokeNetboxRequest(Helpers): Fix indent (using Visual Code Formatter) * Add Set-netboxCipherSSL for enable TLS1.1 and TLS1.2 (for PS 5.0) From PowerAruba/FortiPower Module :) * Add Set-NetboxUnstrustedSSL for disable SSL chain test (for PS 5.0 From PowerAruba/FortiPwoer Module :) * Add Get/Set netboxInvokeParms for Get and Set Invoke Params (array) Like -SkipCertificate, Timeout... * InvokeNetboxRequest: Add to Splat NetboxInvokeParams * Connect: Add SkipCertificateCheck parameter (for PS5 and Core) Also enable TLS 1.1 and 1.2 for PS5 * PSSA: Add Github Actions for launch PSSA (PowerShell Script Analyzer) when launch PR (#11) Add also vscode/PSScriptAnalyzerSettings.psd1 for Settings for PSSA (can be reuse also for vscode...) * Update psproj * Correct typo * Correct brace formatting * Add Get/Set timeout functions * Add Get/Set timeout functions * Add TimeoutSeconds parameter and logic to Connect-NetboxAPI - Updated `InvokeNetboxRequest` to use `NetboxConfig.Timeout` - Updated `Get-NetboxAPIDefinition` to use `NetboxConfig.Timeout` * Trim whitespaces * Add Get-NetboxVersion function * Remove API Definition caching and replace with Netbox version check * Increment version to 1.4 Co-authored-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Co-authored-by: Ben Claussen <claussen@neonet.org>
This commit is contained in:
parent
1f89363cbd
commit
739f5e98e2
22 changed files with 539 additions and 198 deletions
16
.github/workflows/pssa.yml
vendored
Normal file
16
.github/workflows/pssa.yml
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
name: CI
|
||||
on: [pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
name: Run PSSA
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: lint
|
||||
uses: docker://devblackops/github-action-psscriptanalyzer:2.3.0
|
||||
with:
|
||||
settingsPath: .vscode/PSScriptAnalyzerSettings.psd1
|
||||
sendComment: false
|
||||
failOnInfos: true
|
||||
failOnErrors: true
|
||||
failOnWarnings: true
|
||||
5
.vscode/PSScriptAnalyzerSettings.psd1
vendored
Normal file
5
.vscode/PSScriptAnalyzerSettings.psd1
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
@{
|
||||
ExcludeRules = @(
|
||||
'PSUseToExportFieldsInManifest'
|
||||
)
|
||||
}
|
||||
|
|
@ -24,8 +24,8 @@ function InvokeNetboxRequest {
|
|||
|
||||
[pscustomobject]$Body = $null,
|
||||
|
||||
[ValidateRange(0, 60)]
|
||||
[uint16]$Timeout = 5,
|
||||
[ValidateRange(1, 65535)]
|
||||
[uint16]$Timeout = (Get-NetboxTimeout),
|
||||
|
||||
[ValidateSet('GET', 'PATCH', 'PUT', 'POST', 'DELETE', 'OPTIONS', IgnoreCase = $true)]
|
||||
[string]$Method = 'GET',
|
||||
|
|
@ -47,6 +47,8 @@ function InvokeNetboxRequest {
|
|||
'Verbose' = $VerbosePreference
|
||||
}
|
||||
|
||||
$splat += Get-NetboxInvokeParams
|
||||
|
||||
if ($Body) {
|
||||
Write-Verbose "BODY: $($Body | ConvertTo-Json -Compress)"
|
||||
$null = $splat.Add('Body', ($Body | ConvertTo-Json -Compress))
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@
|
|||
.PARAMETER URI
|
||||
The full URI for the resource such as "https://netbox.domain.com:8443"
|
||||
|
||||
.PARAMETER SkipCertificateCheck
|
||||
A description of the SkipCertificateCheck parameter.
|
||||
|
||||
.PARAMETER TimeoutSeconds
|
||||
The number of seconds before the HTTP call times out. Defaults to 30 seconds
|
||||
|
||||
.EXAMPLE
|
||||
PS C:\> Connect-NetboxAPI -Hostname "netbox.domain.com"
|
||||
|
||||
|
|
@ -49,7 +55,14 @@
|
|||
|
||||
[Parameter(ParameterSetName = 'URI',
|
||||
Mandatory = $true)]
|
||||
[string]$URI
|
||||
[string]$URI,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[switch]$SkipCertificateCheck = $false,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[ValidateRange(1, 65535)]
|
||||
[uint16]$TimeoutSeconds = 30
|
||||
)
|
||||
|
||||
if (-not $Credential) {
|
||||
|
|
@ -63,7 +76,22 @@
|
|||
}
|
||||
}
|
||||
|
||||
$null = Set-NetboxCredential -Credential $Credential
|
||||
$invokeParams = @{ SkipCertificateCheck = $SkipCertificateCheck; }
|
||||
|
||||
if ("Desktop" -eq $PSVersionTable.PsEdition) {
|
||||
#Remove -SkipCertificateCheck from Invoke Parameter (not supported <= PS 5)
|
||||
$invokeParams.remove("SkipCertificateCheck")
|
||||
}
|
||||
|
||||
#for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust
|
||||
if ("Desktop" -eq $PSVersionTable.PsEdition) {
|
||||
#Enable TLS 1.1 and 1.2
|
||||
Set-NetboxCipherSSL
|
||||
if ($SkipCertificateCheck) {
|
||||
#Disable SSL chain trust...
|
||||
Set-NetboxuntrustedSSL
|
||||
}
|
||||
}
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'Manual' {
|
||||
|
|
@ -79,8 +107,11 @@
|
|||
}
|
||||
|
||||
$null = Set-NetboxHostName -Hostname $uriBuilder.Host
|
||||
$null = Set-NetboxCredential -Credential $Credential
|
||||
$null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme
|
||||
$null = Set-NetboxHostPort -Port $uriBuilder.Port
|
||||
$null = Set-NetboxInvokeParams -invokeParams $invokeParams
|
||||
$null = Set-NetboxTimeout -TimeoutSeconds $TimeoutSeconds
|
||||
|
||||
try {
|
||||
Write-Verbose "Verifying API connectivity..."
|
||||
|
|
@ -95,12 +126,21 @@
|
|||
}
|
||||
}
|
||||
|
||||
Write-Verbose "Caching API definition"
|
||||
$script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition
|
||||
# Write-Verbose "Caching API definition"
|
||||
# $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition
|
||||
#
|
||||
# if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) {
|
||||
# $Script:NetboxConfig.Connected = $false
|
||||
# throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)"
|
||||
# }
|
||||
|
||||
if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) {
|
||||
Write-Verbose "Checking Netbox version compatibility"
|
||||
$script:NetboxConfig.NetboxVersion = Get-NetboxVersion
|
||||
if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 2.8) {
|
||||
$Script:NetboxConfig.Connected = $false
|
||||
throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)"
|
||||
throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')"
|
||||
} else {
|
||||
Write-Verbose "Found compatible version [$($script:NetboxConfig.NetboxVersion.'netbox-version')]!"
|
||||
}
|
||||
|
||||
$script:NetboxConfig.Connected = $true
|
||||
|
|
|
|||
11
Functions/Setup/Get-NetboxInvokeParams.ps1
Normal file
11
Functions/Setup/Get-NetboxInvokeParams.ps1
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
function Get-NetboxInvokeParams {
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
Write-Verbose "Getting Netbox InvokeParams"
|
||||
if ($null -eq $script:NetboxConfig.InvokeParams) {
|
||||
throw "Netbox Invoke Params is not set! You may set it with Set-NetboxInvokeParams -InvokeParams ..."
|
||||
}
|
||||
|
||||
$script:NetboxConfig.InvokeParams
|
||||
}
|
||||
13
Functions/Setup/Get-NetboxTimeout.ps1
Normal file
13
Functions/Setup/Get-NetboxTimeout.ps1
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
function Get-NetboxTimeout {
|
||||
[CmdletBinding()]
|
||||
[OutputType([uint16])]
|
||||
param ()
|
||||
|
||||
Write-Verbose "Getting Netbox Timeout"
|
||||
if ($null -eq $script:NetboxConfig.Timeout) {
|
||||
throw "Netbox Timeout is not set! You may set it with Set-NetboxTimeout -TimeoutSeconds [uint16]"
|
||||
}
|
||||
|
||||
$script:NetboxConfig.Timeout
|
||||
}
|
||||
15
Functions/Setup/Get-NetboxVersion.ps1
Normal file
15
Functions/Setup/Get-NetboxVersion.ps1
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
function Get-NetboxVersion {
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('status'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{
|
||||
'format' = 'json'
|
||||
}
|
||||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck
|
||||
|
||||
InvokeNetboxRequest -URI $URI
|
||||
}
|
||||
8
Functions/Setup/Set-NetboxCipherSSL.ps1
Normal file
8
Functions/Setup/Set-NetboxCipherSSL.ps1
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Function Set-NetboxCipherSSL {
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")]
|
||||
Param( )
|
||||
# Hack for allowing TLS 1.1 and TLS 1.2 (by default it is only SSL3 and TLS (1.0))
|
||||
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
|
||||
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
|
||||
|
||||
}
|
||||
14
Functions/Setup/Set-NetboxInvokeParams.ps1
Normal file
14
Functions/Setup/Set-NetboxInvokeParams.ps1
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function Set-NetboxInvokeParams {
|
||||
[CmdletBinding(ConfirmImpact = 'Low',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([string])]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[array]$InvokeParams
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ShouldProcess('Netbox Invoke Params', 'Set')) {
|
||||
$script:NetboxConfig.InvokeParams = $InvokeParams
|
||||
$script:NetboxConfig.InvokeParams
|
||||
}
|
||||
}
|
||||
17
Functions/Setup/Set-NetboxTimeout.ps1
Normal file
17
Functions/Setup/Set-NetboxTimeout.ps1
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
function Set-NetboxTimeout {
|
||||
[CmdletBinding(ConfirmImpact = 'Low',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([uint16])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $false)]
|
||||
[ValidateRange(1, 65535)]
|
||||
[uint16]$TimeoutSeconds = 30
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ShouldProcess('Netbox Timeout', 'Set')) {
|
||||
$script:NetboxConfig.Timeout = $TimeoutSeconds
|
||||
$script:NetboxConfig.Timeout
|
||||
}
|
||||
}
|
||||
19
Functions/Setup/Set-NetboxUnstrustedSSL.ps1
Normal file
19
Functions/Setup/Set-NetboxUnstrustedSSL.ps1
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Function Set-NetboxUntrustedSSL {
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")]
|
||||
Param( )
|
||||
# Hack for allowing untrusted SSL certs with https connections
|
||||
Add-Type -TypeDefinition @"
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
public class TrustAllCertsPolicy : ICertificatePolicy {
|
||||
public bool CheckValidationResult(
|
||||
ServicePoint srvPoint, X509Certificate certificate,
|
||||
WebRequest request, int certificateProblem) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
[System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy
|
||||
|
||||
}
|
||||
|
|
@ -21,9 +21,9 @@ function Get-NetboxAPIDefinition {
|
|||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('docs'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi'}
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi' }
|
||||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck
|
||||
|
||||
InvokeNetboxRequest -URI $URI -Timeout 10
|
||||
InvokeNetboxRequest -URI $URI
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
$uriSegments = [System.Collections.ArrayList]::new(@('extras'))
|
||||
|
||||
$uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json'} -SkipConnectedCheck
|
||||
$uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json' } -SkipConnectedCheck
|
||||
|
||||
InvokeNetboxRequest -URI $uri
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
#
|
||||
# Generated by: Ben Claussen
|
||||
#
|
||||
# Generated on: 2021-03-31
|
||||
# Generated on: 2021-07-22
|
||||
#
|
||||
|
||||
@{
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
RootModule = 'NetboxPS.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '1.3.3'
|
||||
ModuleVersion = '1.4'
|
||||
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
|
|
|
|||
|
|
@ -108,6 +108,13 @@
|
|||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxHostScheme_ps1" ExportFunctions="True">Functions\Setup\Get-NetboxHostScheme.ps1</File>
|
||||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxHostPort_ps1" ExportFunctions="True">Functions\Setup\Set-NetboxHostPort.ps1</File>
|
||||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxHostPort_ps1" ExportFunctions="True">Functions\Setup\Get-NetboxHostPort.ps1</File>
|
||||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxInvokeParams_ps1" ExportFunctions="True">Functions\Setup\Get-NetboxInvokeParams.ps1</File>
|
||||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxCipherSSL_ps1" ExportFunctions="True">Functions\Setup\Set-NetboxCipherSSL.ps1</File>
|
||||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxInvokeParams_ps1" ExportFunctions="True">Functions\Setup\Set-NetboxInvokeParams.ps1</File>
|
||||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxUnstrustedSSL_ps1" ExportFunctions="True">Functions\Setup\Set-NetboxUnstrustedSSL.ps1</File>
|
||||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxTimeout_ps1" ExportFunctions="True">Functions\Setup\Set-NetboxTimeout.ps1</File>
|
||||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxTimeout_ps1" ExportFunctions="True">Functions\Setup\Get-NetboxTimeout.ps1</File>
|
||||
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVersion_ps1" ExportFunctions="True">Functions\Setup\Get-NetboxVersion.ps1</File>
|
||||
</Files>
|
||||
<StartupScript>R:\Netbox\NetboxPS\Test-Module.ps1</StartupScript>
|
||||
</Project>
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
#
|
||||
# Generated by: Ben Claussen
|
||||
#
|
||||
# Generated on: 2021-03-31
|
||||
# Generated on: 2021-07-22
|
||||
#
|
||||
|
||||
@{
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
RootModule = 'NetboxPS.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '1.3.3'
|
||||
ModuleVersion = '1.4'
|
||||
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
|
|
|
|||
|
|
@ -490,6 +490,12 @@ function Connect-NetboxAPI {
|
|||
.PARAMETER URI
|
||||
The full URI for the resource such as "https://netbox.domain.com:8443"
|
||||
|
||||
.PARAMETER SkipCertificateCheck
|
||||
A description of the SkipCertificateCheck parameter.
|
||||
|
||||
.PARAMETER TimeoutSeconds
|
||||
The number of seconds before the HTTP call times out. Defaults to 30 seconds
|
||||
|
||||
.EXAMPLE
|
||||
PS C:\> Connect-NetboxAPI -Hostname "netbox.domain.com"
|
||||
|
||||
|
|
@ -518,7 +524,14 @@ function Connect-NetboxAPI {
|
|||
|
||||
[Parameter(ParameterSetName = 'URI',
|
||||
Mandatory = $true)]
|
||||
[string]$URI
|
||||
[string]$URI,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[switch]$SkipCertificateCheck = $false,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[ValidateRange(1, 65535)]
|
||||
[uint16]$TimeoutSeconds = 30
|
||||
)
|
||||
|
||||
if (-not $Credential) {
|
||||
|
|
@ -532,7 +545,22 @@ function Connect-NetboxAPI {
|
|||
}
|
||||
}
|
||||
|
||||
$null = Set-NetboxCredential -Credential $Credential
|
||||
$invokeParams = @{ SkipCertificateCheck = $SkipCertificateCheck; }
|
||||
|
||||
if ("Desktop" -eq $PSVersionTable.PsEdition) {
|
||||
#Remove -SkipCertificateCheck from Invoke Parameter (not supported <= PS 5)
|
||||
$invokeParams.remove("SkipCertificateCheck")
|
||||
}
|
||||
|
||||
#for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust
|
||||
if ("Desktop" -eq $PSVersionTable.PsEdition) {
|
||||
#Enable TLS 1.1 and 1.2
|
||||
Set-NetboxCipherSSL
|
||||
if ($SkipCertificateCheck) {
|
||||
#Disable SSL chain trust...
|
||||
Set-NetboxuntrustedSSL
|
||||
}
|
||||
}
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'Manual' {
|
||||
|
|
@ -548,8 +576,11 @@ function Connect-NetboxAPI {
|
|||
}
|
||||
|
||||
$null = Set-NetboxHostName -Hostname $uriBuilder.Host
|
||||
$null = Set-NetboxCredential -Credential $Credential
|
||||
$null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme
|
||||
$null = Set-NetboxHostPort -Port $uriBuilder.Port
|
||||
$null = Set-NetboxInvokeParams -invokeParams $invokeParams
|
||||
$null = Set-NetboxTimeout -TimeoutSeconds $TimeoutSeconds
|
||||
|
||||
try {
|
||||
Write-Verbose "Verifying API connectivity..."
|
||||
|
|
@ -564,12 +595,21 @@ function Connect-NetboxAPI {
|
|||
}
|
||||
}
|
||||
|
||||
Write-Verbose "Caching API definition"
|
||||
$script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition
|
||||
# Write-Verbose "Caching API definition"
|
||||
# $script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition
|
||||
#
|
||||
# if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) {
|
||||
# $Script:NetboxConfig.Connected = $false
|
||||
# throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)"
|
||||
# }
|
||||
|
||||
if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) {
|
||||
Write-Verbose "Checking Netbox version compatibility"
|
||||
$script:NetboxConfig.NetboxVersion = Get-NetboxVersion
|
||||
if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 2.8) {
|
||||
$Script:NetboxConfig.Connected = $false
|
||||
throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)"
|
||||
throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')"
|
||||
} else {
|
||||
Write-Verbose "Found compatible version [$($script:NetboxConfig.NetboxVersion.'netbox-version')]!"
|
||||
}
|
||||
|
||||
$script:NetboxConfig.Connected = $true
|
||||
|
|
@ -729,11 +769,11 @@ function Get-NetboxAPIDefinition {
|
|||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('docs'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi'}
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi' }
|
||||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck
|
||||
|
||||
InvokeNetboxRequest -URI $URI -Timeout 10
|
||||
InvokeNetboxRequest -URI $URI
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -1745,6 +1785,22 @@ function Get-NetboxHostScheme {
|
|||
|
||||
#endregion
|
||||
|
||||
#region File Get-NetboxInvokeParams.ps1
|
||||
|
||||
function Get-NetboxInvokeParams {
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
Write-Verbose "Getting Netbox InvokeParams"
|
||||
if ($null -eq $script:NetboxConfig.InvokeParams) {
|
||||
throw "Netbox Invoke Params is not set! You may set it with Set-NetboxInvokeParams -InvokeParams ..."
|
||||
}
|
||||
|
||||
$script:NetboxConfig.InvokeParams
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Get-NetboxIPAMAddress.ps1
|
||||
|
||||
function Get-NetboxIPAMAddress {
|
||||
|
|
@ -2553,6 +2609,44 @@ function Get-NetboxTenant {
|
|||
|
||||
#endregion
|
||||
|
||||
#region File Get-NetboxTimeout.ps1
|
||||
|
||||
|
||||
function Get-NetboxTimeout {
|
||||
[CmdletBinding()]
|
||||
[OutputType([uint16])]
|
||||
param ()
|
||||
|
||||
Write-Verbose "Getting Netbox Timeout"
|
||||
if ($null -eq $script:NetboxConfig.Timeout) {
|
||||
throw "Netbox Timeout is not set! You may set it with Set-NetboxTimeout -TimeoutSeconds [uint16]"
|
||||
}
|
||||
|
||||
$script:NetboxConfig.Timeout
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Get-NetboxVersion.ps1
|
||||
|
||||
|
||||
function Get-NetboxVersion {
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('status'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{
|
||||
'format' = 'json'
|
||||
}
|
||||
|
||||
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck
|
||||
|
||||
InvokeNetboxRequest -URI $URI
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Get-NetboxVirtualizationCluster.ps1
|
||||
|
||||
<#
|
||||
|
|
@ -2995,8 +3089,8 @@ function InvokeNetboxRequest {
|
|||
|
||||
[pscustomobject]$Body = $null,
|
||||
|
||||
[ValidateRange(0, 60)]
|
||||
[uint16]$Timeout = 5,
|
||||
[ValidateRange(1, 65535)]
|
||||
[uint16]$Timeout = (Get-NetboxTimeout),
|
||||
|
||||
[ValidateSet('GET', 'PATCH', 'PUT', 'POST', 'DELETE', 'OPTIONS', IgnoreCase = $true)]
|
||||
[string]$Method = 'GET',
|
||||
|
|
@ -3018,6 +3112,8 @@ function InvokeNetboxRequest {
|
|||
'Verbose' = $VerbosePreference
|
||||
}
|
||||
|
||||
$splat += Get-NetboxInvokeParams
|
||||
|
||||
if ($Body) {
|
||||
Write-Verbose "BODY: $($Body | ConvertTo-Json -Compress)"
|
||||
$null = $splat.Add('Body', ($Body | ConvertTo-Json -Compress))
|
||||
|
|
@ -3936,6 +4032,19 @@ function Remove-NetboxVirtualMachine {
|
|||
|
||||
#endregion
|
||||
|
||||
#region File Set-NetboxCipherSSL.ps1
|
||||
|
||||
Function Set-NetboxCipherSSL {
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")]
|
||||
Param( )
|
||||
# Hack for allowing TLS 1.1 and TLS 1.2 (by default it is only SSL3 and TLS (1.0))
|
||||
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
|
||||
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Set-NetboxCredential.ps1
|
||||
|
||||
function Set-NetboxCredential {
|
||||
|
|
@ -4338,6 +4447,25 @@ function Set-NetboxHostScheme {
|
|||
|
||||
#endregion
|
||||
|
||||
#region File Set-NetboxInvokeParams.ps1
|
||||
|
||||
function Set-NetboxInvokeParams {
|
||||
[CmdletBinding(ConfirmImpact = 'Low',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([string])]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[array]$InvokeParams
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ShouldProcess('Netbox Invoke Params', 'Set')) {
|
||||
$script:NetboxConfig.InvokeParams = $InvokeParams
|
||||
$script:NetboxConfig.InvokeParams
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Set-NetboxIPAMAddress.ps1
|
||||
|
||||
<#
|
||||
|
|
@ -4534,6 +4662,52 @@ function Set-NetboxIPAMPrefix {
|
|||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Set-NetboxTimeout.ps1
|
||||
|
||||
|
||||
function Set-NetboxTimeout {
|
||||
[CmdletBinding(ConfirmImpact = 'Low',
|
||||
SupportsShouldProcess = $true)]
|
||||
[OutputType([uint16])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $false)]
|
||||
[ValidateRange(1, 65535)]
|
||||
[uint16]$TimeoutSeconds = 30
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ShouldProcess('Netbox Timeout', 'Set')) {
|
||||
$script:NetboxConfig.Timeout = $TimeoutSeconds
|
||||
$script:NetboxConfig.Timeout
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Set-NetboxUnstrustedSSL.ps1
|
||||
|
||||
Function Set-NetboxUntrustedSSL {
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")]
|
||||
Param( )
|
||||
# Hack for allowing untrusted SSL certs with https connections
|
||||
Add-Type -TypeDefinition @"
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
public class TrustAllCertsPolicy : ICertificatePolicy {
|
||||
public bool CheckValidationResult(
|
||||
ServicePoint srvPoint, X509Certificate certificate,
|
||||
WebRequest request, int certificateProblem) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
[System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Set-NetboxVirtualMachine.ps1
|
||||
|
|
@ -4786,7 +4960,7 @@ function VerifyAPIConnectivity {
|
|||
|
||||
$uriSegments = [System.Collections.ArrayList]::new(@('extras'))
|
||||
|
||||
$uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json'} -SkipConnectedCheck
|
||||
$uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json' } -SkipConnectedCheck
|
||||
|
||||
InvokeNetboxRequest -URI $uri
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue