first working types

This commit is contained in:
2022-12-06 17:20:45 +03:00
parent a1b03b81c0
commit 7d0d1b53ae
14 changed files with 129 additions and 75 deletions

View File

@@ -2,16 +2,16 @@ function Invoke-Request {
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[methods]
[PS.IPAM.methods]
$Method,
[parameter(Mandatory=$true)]
[controllers]
[PS.IPAM.controllers]
$Controller,
[parameter(Mandatory=$false)]
[types]
[PS.IPAM.types]
$Type,
[parameter(Mandatory=$false)]
[subcontrollers]
[PS.IPAM.subcontrollers]
$SubController,
[Parameter(Mandatory=$false)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
@@ -25,7 +25,7 @@ function Invoke-Request {
if ($_tokenStatus -eq "NoToken") { throw "No session available!" }
if ($_tokenStatus -eq "Expired") { Update-Session }
$Controller = $Controller.ToLower()
$Controller = $Controller
$_uri = "$($script:ipamURL)/api/$($script:ipamAppID)/$Controller"
if ($SubController) { $_uri += "/$SubController" }
@@ -46,7 +46,7 @@ function Invoke-Request {
Headers = $_headers
}
if ($Method -eq [methods]::POST -or $Method -eq [methods]::PATCH) {
if ($Method -eq [PS.IPAM.methods]::POST -or $Method -eq [PS.IPAM.methods]::PATCH) {
if ($Params -is [PSCustomObject]) {
$_params = @{};
$Params | Get-Member -MemberType *Property | Where-Object {
@@ -60,10 +60,22 @@ function Invoke-Request {
$_response = Invoke-RestMethod @_arguments
if ($_response.code -match "20\d") {
if ($Type) {
{ $_response.data | ForEach-Object { New-Object -TypeName $Type -ArgumentList $_.psobject.properties.value } }
if ($Type -is [PS.IPAM.types]) {
switch ($Type) {
"vlan" {
$_response.data | ForEach-Object {
New-Object -TypeName ([PS.IPAM.Vlan]) -ArgumentList (@($_.psobject.properties.value[0..6]) + ($_ | Select-Object -Property custom_* -ExcludeProperty custom_*))
}; break
}
"subnetwork" {
$_response.data | ForEach-Object {
New-Object -TypeName ([PS.IPAM.Subnetwork]) -ArgumentList (@($_.psobject.properties.value[0..30]) + ($_ | Select-Object -Property custom_* -ExcludeProperty custom_*))
}; break
}
Default { $_response.data | ForEach-Object { New-Object -TypeName ("PS.IPAM.$Type") -ArgumentList $_.psobject.properties.value } }
}
} else {
$_response.data
return $_response.data
}
} else {
throw ("Error - $($_response.code)")