replaced hardcoded text by enums in some functions

This commit is contained in:
2022-12-05 17:48:20 +03:00
parent 4fc6bac4b5
commit a1b03b81c0
4 changed files with 39 additions and 27 deletions

View File

@@ -5,16 +5,13 @@ function Invoke-Request {
[methods]
$Method,
[parameter(Mandatory=$true)]
[ValidateSet("user","vlan","subnets","addresses","sections","vrf","l2domains","tools")]
[string]
[controllers]
$Controller,
[parameter(Mandatory=$false)]
[ValidateSet("address","tag","subnet","vlan","vrf","section")]
[string]
[types]
$Type,
[parameter(Mandatory=$false)]
[ValidateSet("nameservers")]
[string]
[subcontrollers]
$SubController,
[Parameter(Mandatory=$false)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
@@ -49,7 +46,7 @@ function Invoke-Request {
Headers = $_headers
}
if ($Method -eq [methods]::POST -or $Method -eq [methods]) {
if ($Method -eq [methods]::POST -or $Method -eq [methods]::PATCH) {
if ($Params -is [PSCustomObject]) {
$_params = @{};
$Params | Get-Member -MemberType *Property | Where-Object {
@@ -63,11 +60,10 @@ function Invoke-Request {
$_response = Invoke-RestMethod @_arguments
if ($_response.code -match "20\d") {
switch ($Type) {
"address" { $_response.data | ForEach-Object { New-Object -TypeName "Address" -ArgumentList $_.psobject.properties.value } }
"subnet" { $_response.data | ForEach-Object { New-Object -TypeName "Subnetwork" -ArgumentList $_.psobject.properties.value } }
"tag" { $_response.data | ForEach-Object { New-Object -TypeName "Tag" -ArgumentList $_.psobject.properties.value } }
Default { $_response.data }
if ($Type) {
{ $_response.data | ForEach-Object { New-Object -TypeName $Type -ArgumentList $_.psobject.properties.value } }
} else {
$_response.data
}
} else {
throw ("Error - $($_response.code)")