From 09cd00dc6619a6526881389eb21638cdbf111704 Mon Sep 17 00:00:00 2001 From: Arnike Date: Mon, 5 Dec 2022 08:48:37 +0300 Subject: [PATCH 1/9] Base --- .gitignore | 3 + README.md | 1 + classlib/address.cs | 73 ++++++++++++++ classlib/classlib.csproj | 9 ++ classlib/enum.cs | 6 ++ classlib/subnet.cs | 95 ++++++++++++++++++ classlib/tag.cs | 43 ++++++++ ...e-PSIPAMRequest.ps1 => Invoke-Request.ps1} | 22 +++- functions/private/Test-PSIPAMSession.ps1 | 15 --- functions/private/Test-Session.ps1 | 19 ++++ ...e-PSIPAMSession.ps1 => Update-Session.ps1} | 8 +- functions/public/Get-Address.ps1 | 68 +++++++++++++ ...PAMFirstFreeIP.ps1 => Get-FirstFreeIP.ps1} | 8 +- ...et-PSIPAML2Domain.ps1 => Get-L2Domain.ps1} | 6 +- ...SIPAMNameserver.ps1 => Get-Nameserver.ps1} | 6 +- functions/public/Get-PSIPAMTags.ps1 | 26 ----- ...-PSIPAMAddress.ps1 => Get-Permissions.ps1} | 10 +- ...{Get-PSIPAMSection.ps1 => Get-Section.ps1} | 6 +- .../{Get-PSIPAMSubnet.ps1 => Get-Subnet.ps1} | 16 +-- ...PAMSubnetUsage.ps1 => Get-SubnetUsage.ps1} | 8 +- functions/public/Get-Tag.ps1 | 37 +++++++ .../{Get-PSIPAMVlan.ps1 => Get-Vlan.ps1} | 6 +- .../public/{Get-PSIPAMVrf.ps1 => Get-Vrf.ps1} | 6 +- ...{New-PSIPAMAddress.ps1 => New-Address.ps1} | 8 +- ...PAMFirstFreeIP.ps1 => New-FirstFreeIP.ps1} | 8 +- functions/public/New-PSIPAMSession.ps1 | 37 ------- functions/public/New-Session.ps1 | 53 ++++++++++ .../{New-PSIPAMSubnet.ps1 => New-Subnet.ps1} | 8 +- ...e-PSIPAMAddress.ps1 => Remove-Address.ps1} | 6 +- ...{Set-PSIPAMAddress.ps1 => Set-Address.ps1} | 8 +- .../{Set-PSIPAMSubnet.ps1 => Set-Subnet.ps1} | 0 old/address.ps1 | 75 ++++++++++++++ old/tag.ps1 | 33 ++++++ ps.ipam.psd1 | Bin 5904 -> 3138 bytes types/types.ps1xml | 51 ++++++++++ 35 files changed, 642 insertions(+), 142 deletions(-) create mode 100644 .gitignore create mode 100644 classlib/address.cs create mode 100644 classlib/classlib.csproj create mode 100644 classlib/enum.cs create mode 100644 classlib/subnet.cs create mode 100644 classlib/tag.cs rename functions/private/{Invoke-PSIPAMRequest.ps1 => Invoke-Request.ps1} (64%) delete mode 100644 functions/private/Test-PSIPAMSession.ps1 create mode 100644 functions/private/Test-Session.ps1 rename functions/private/{Update-PSIPAMSession.ps1 => Update-Session.ps1} (58%) create mode 100644 functions/public/Get-Address.ps1 rename functions/public/{Get-PSIPAMFirstFreeIP.ps1 => Get-FirstFreeIP.ps1} (82%) rename functions/public/{Get-PSIPAML2Domain.ps1 => Get-L2Domain.ps1} (87%) rename functions/public/{Get-PSIPAMNameserver.ps1 => Get-Nameserver.ps1} (82%) delete mode 100644 functions/public/Get-PSIPAMTags.ps1 rename functions/public/{Get-PSIPAMAddress.ps1 => Get-Permissions.ps1} (92%) rename functions/public/{Get-PSIPAMSection.ps1 => Get-Section.ps1} (90%) rename functions/public/{Get-PSIPAMSubnet.ps1 => Get-Subnet.ps1} (90%) rename functions/public/{Get-PSIPAMSubnetUsage.ps1 => Get-SubnetUsage.ps1} (84%) create mode 100644 functions/public/Get-Tag.ps1 rename functions/public/{Get-PSIPAMVlan.ps1 => Get-Vlan.ps1} (89%) rename functions/public/{Get-PSIPAMVrf.ps1 => Get-Vrf.ps1} (81%) rename functions/public/{New-PSIPAMAddress.ps1 => New-Address.ps1} (97%) rename functions/public/{New-PSIPAMFirstFreeIP.ps1 => New-FirstFreeIP.ps1} (96%) delete mode 100644 functions/public/New-PSIPAMSession.ps1 create mode 100644 functions/public/New-Session.ps1 rename functions/public/{New-PSIPAMSubnet.ps1 => New-Subnet.ps1} (97%) rename functions/public/{Remove-PSIPAMAddress.ps1 => Remove-Address.ps1} (90%) rename functions/public/{Set-PSIPAMAddress.ps1 => Set-Address.ps1} (97%) rename functions/public/{Set-PSIPAMSubnet.ps1 => Set-Subnet.ps1} (100%) create mode 100644 old/address.ps1 create mode 100644 old/tag.ps1 create mode 100644 types/types.ps1xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b061a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.dll +bin +obj \ No newline at end of file diff --git a/README.md b/README.md index ded5ff1..a8bce5c 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ [![License](https://img.shields.io/badge/license-GPL2+-blue.svg)](https://git.arnike.ru/Arnike/ps.ipam/src/branch/main/LICENSE) ![Powershell](https://img.shields.io/badge/powershell-v5.1+-blue.svg) +![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/ps.ipam)

PS.IPAM

diff --git a/classlib/address.cs b/classlib/address.cs new file mode 100644 index 0000000..7f411fb --- /dev/null +++ b/classlib/address.cs @@ -0,0 +1,73 @@ +namespace PS.IPAM; +using System; + +public class Address { + public int Id { get; } + public int SubnetId { get; } + public string Ip { get; } + public bool IsGateway { get; } + public string Description { get; } + public string Hostname { get; } + public string MAC { get; } + public string Owner { get; } + public int TagId { get; } + public int DeviceId { get; } + public string Location { get; } + public int Port { get; } + public string Note { get; } + public DateTime? LastSeen { get; } + public bool ExcludePing { get; } + public int PTRignore { get; } + public int PTR { get; } + public string FirewallAddressObject { get; } + public DateTime? EditDate { get; } + public int CustomerId { get; } + + public Address( + int id, + int subnetId, + string ip, + bool is_gateway, + string description, + string hostname, + string mac, + string owner, + int tag, + int deviceId, + string location, + int port, + string note, + DateTime? lastSeen, + bool excludePing, + int PTRignore, + int PTR, + string firewallAddressObject, + DateTime? editDate, + int customer_id + ) { + this.Id = id; + this.SubnetId = subnetId; + this.Ip = ip; + this.IsGateway = is_gateway; + this.Description = description; + this.Hostname = hostname; + this.MAC = mac; + this.Owner = owner; + this.TagId = tag; + this.DeviceId = deviceId; + this.Location = location; + this.Port = port; + this.Note = note; + this.EditDate = lastSeen; + this.ExcludePing = excludePing; + this.PTRignore = PTRignore; + this.PTR = PTR; + this.FirewallAddressObject = firewallAddressObject; + this.EditDate = editDate; + this.CustomerId = customer_id; + } + + public override string ToString() { + return this.Ip; + } +} \ No newline at end of file diff --git a/classlib/classlib.csproj b/classlib/classlib.csproj new file mode 100644 index 0000000..cfadb03 --- /dev/null +++ b/classlib/classlib.csproj @@ -0,0 +1,9 @@ + + + + net7.0 + enable + enable + + + diff --git a/classlib/enum.cs b/classlib/enum.cs new file mode 100644 index 0000000..23d694b --- /dev/null +++ b/classlib/enum.cs @@ -0,0 +1,6 @@ +namespace PS.IPAM; +using System; + +enum Parameters { + IsGateway = "is_gateway"; +} \ No newline at end of file diff --git a/classlib/subnet.cs b/classlib/subnet.cs new file mode 100644 index 0000000..e3aca08 --- /dev/null +++ b/classlib/subnet.cs @@ -0,0 +1,95 @@ +namespace PS.IPAM; +using System; + +public class Subnetwork { + public int Id { get; } + public string Subnet { get; } + public int Mask { get; } + public int SectionId { get; } + public string Description { get; } + public string LinkedSubnet { get; } + public int FirewallAddressObject { get; } + public int VrfId { get; } + public int MasterSubnetId { get; } + public bool AllowRequests { get; } + public int VlanId { get; } + public bool ShowName { get; } + public int Device { get; } + public bool PingSubnet { get; } + public bool DiscoverSubnet { get; } + public bool ResolveDNS { get; } + public Subnetwork( + int id, + string subnet, + int mask, + int sectionId, + string description, + string linkedSubnet, + int firewallAddressObject, + int vrfId, + int masterSubnetId, + string permissions, + bool allowRequests, + int vlanId, + bool showName, + int device, + bool pingSubnet, + bool discoverSubnet, + bool resolveDNS + ) { + this.Id = id; + this.Subnet = subnet; + this.Mask = mask; + this.SectionId = sectionId; + this.Description = description; + this.LinkedSubnet = linkedSubnet; + this.FirewallAddressObject = firewallAddressObject; + this.VrfId = vrfId; + this.MasterSubnetId = masterSubnetId; + this.AllowRequests = allowRequests; + this.VlanId = vlanId; + this.ShowName = showName; + this.Device = device; + this.PingSubnet = pingSubnet; + this.DiscoverSubnet = discoverSubnet; + this.ResolveDNS = resolveDNS; + } + + public override string ToString() + { + return $"{this.Subnet}/{this.Mask}"; + } +} + +id : 1 +subnet : fd13:6d20:29dc:cf27:: +mask : 64 +sectionId : 2 +description : Private subnet 1 +linked_subnet : +firewallAddressObject : +vrfId : 0 +masterSubnetId : 0 +allowRequests : 1 +vlanId : 1 +showName : 1 +device : 0 +permissions : {"3":"1","2":"2"} +pingSubnet : 0 +discoverSubnet : 0 +resolveDNS : 0 +DNSrecursive : 0 +DNSrecords : 0 +nameserverId : 0 +scanAgent : +customer_id : +isFolder : 0 +isFull : 0 +isPool : 0 +tag : 2 +threshold : 0 +location : +editDate : +lastScan : +lastDiscovery : +calculation : @{Type=IPv6; Host address=/; Host address (uncompressed)=/; Subnet prefix=fd13:6d20:29dc:cf27::/64; Prefix length=64; Subnet Reverse DNS=7.2.f.c.c.d.9.2.0.2.d.6.3.1.d.f.ip6.arpa; Min host IP=fd13:6d20:29dc:cf27::; Max host IP=fd13:6d20:29dc:cf27:ffff:ffff:ffff:ffff; Number of hosts=18446744073709551616; Address type=NET_IPV6} \ No newline at end of file diff --git a/classlib/tag.cs b/classlib/tag.cs new file mode 100644 index 0000000..8b79ac0 --- /dev/null +++ b/classlib/tag.cs @@ -0,0 +1,43 @@ +namespace PS.IPAM; + +public class Tag { + public int Id { get; } + public string Type { get; } + public bool ShowTag { get; } + public string BGColor { get; } + public string FGColor { get; } + public bool Compress { get; } + public bool Locked { get; } + public bool UpdateTag { get; } + + public Tag( + int id, + string type, + bool showTag, + string BGColor, + string FGColor, + string compress, + string locked, + bool updateTag + ) { + this.Id = id; + this.Type = type; + this.ShowTag = showTag; + this.BGColor = BGColor; + this.FGColor = FGColor; + this.Compress = this.StringToBool(compress); + this.Locked = this.StringToBool(locked); + this.UpdateTag = updateTag; + } + + public override string ToString() { + return this.Type; + } + + private bool StringToBool(string str) { + if (str == "Yes") { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/functions/private/Invoke-PSIPAMRequest.ps1 b/functions/private/Invoke-Request.ps1 similarity index 64% rename from functions/private/Invoke-PSIPAMRequest.ps1 rename to functions/private/Invoke-Request.ps1 index 00040bf..fd15398 100644 --- a/functions/private/Invoke-PSIPAMRequest.ps1 +++ b/functions/private/Invoke-Request.ps1 @@ -1,4 +1,4 @@ -function Invoke-PSIPAMRequest { +function Invoke-Request { [CmdletBinding()] param ( [parameter(Mandatory=$true)] @@ -10,6 +10,10 @@ function Invoke-PSIPAMRequest { [string] $Controller, [parameter(Mandatory=$false)] + [ValidateSet("address","tag","subnet")] + [string] + $Type, + [parameter(Mandatory=$false)] [ValidateSet("nameservers")] [string] $SubController, @@ -20,10 +24,10 @@ function Invoke-PSIPAMRequest { [array] $Identifiers ) - $_tokenStatus = Test-PSIPAMSession + $_tokenStatus = Test-Session if ($_tokenStatus -eq "NoToken") { throw "No session available!" } - if ($_tokenStatus -eq "Expired") { Update-PSIPAMSession } + if ($_tokenStatus -eq "Expired") { Update-Session } $Controller = $Controller.ToLower() @@ -34,7 +38,10 @@ function Invoke-PSIPAMRequest { $_headers = @{ "Accept" = "application/json" "Content-Type" = "application/json" - "token" = $script:ipamToken + } + switch ($script:ipamAuthType) { + "Credentials" { $_headers.Add("token", $script:ipamToken) } + "Token" { $_headers.Add("phpipam-token", $script:ipamToken) } } $_arguments = @{ @@ -57,7 +64,12 @@ function Invoke-PSIPAMRequest { $_response = Invoke-RestMethod @_arguments if ($_response.code -match "20\d") { - return $_response.data + switch ($Type) { + "address" { $_response.data | ForEach-Object { New-Object -TypeName "PS.IPAM.Address" -ArgumentList $_.psobject.properties.value } } + "subnet" { $_response.data | ForEach-Object { New-Object -TypeName "PS.IPAM.Subnetwork" -ArgumentList $_.psobject.properties.value } } + "tag" { $_response.data | ForEach-Object { New-Object -TypeName "PS.IPAM.Tag" -ArgumentList $_.psobject.properties.value } } + Default { $_response.data } + } } else { throw ("Error - $($_response.code)") } diff --git a/functions/private/Test-PSIPAMSession.ps1 b/functions/private/Test-PSIPAMSession.ps1 deleted file mode 100644 index 4c4cf77..0000000 --- a/functions/private/Test-PSIPAMSession.ps1 +++ /dev/null @@ -1,15 +0,0 @@ -function Test-PSIPAMSession { - [CmdletBinding()] - param ( - - ) - if ($script:ipamToken) { - if ($script:ipamExpires -lt (Get-Date)) { - return "Expired" - } else { - return "Valid" - } - } else { - return "NoToken" - } -} \ No newline at end of file diff --git a/functions/private/Test-Session.ps1 b/functions/private/Test-Session.ps1 new file mode 100644 index 0000000..a1ab7c8 --- /dev/null +++ b/functions/private/Test-Session.ps1 @@ -0,0 +1,19 @@ +function Test-Session { + [CmdletBinding()] + param ( + + ) + if ($script:ipamToken) { + if ($script:ipamExpires -eq "Never") { + return "Valid" + } else { + if ($script:ipamExpires -lt (Get-Date)) { + return "Expired" + } else { + return "Valid" + } + } + } else { + return "NoToken" + } +} \ No newline at end of file diff --git a/functions/private/Update-PSIPAMSession.ps1 b/functions/private/Update-Session.ps1 similarity index 58% rename from functions/private/Update-PSIPAMSession.ps1 rename to functions/private/Update-Session.ps1 index d8ade10..e583084 100644 --- a/functions/private/Update-PSIPAMSession.ps1 +++ b/functions/private/Update-Session.ps1 @@ -1,18 +1,18 @@ -function Update-PSIPAMSession { +function Update-Session { [CmdletBinding()] param ( [switch] $Force ) - $_tokenStatus = Test-PSIPAMSession + $_tokenStatus = Test-Session if ($_tokenStatus -eq "NoToken") { throw "No session available!" } if ($_tokenStatus -eq "Valid") { - return (Invoke-PSIPAMRequest -Method PATCH -Controller user).expires + return (Invoke-Request -Method PATCH -Controller user).expires } if ($_tokenStatus -eq "Expired" -or $Force) { - New-PSIPAMSession -URL $script:ipamURL -AppID $script:ipamAppID -Credentials $script:ipamCredentials + New-Session -URL $script:ipamURL -AppID $script:ipamAppID -Credentials $script:ipamCredentials return $script:ipamExpires } } \ No newline at end of file diff --git a/functions/public/Get-Address.ps1 b/functions/public/Get-Address.ps1 new file mode 100644 index 0000000..a3efc3c --- /dev/null +++ b/functions/public/Get-Address.ps1 @@ -0,0 +1,68 @@ +function Get-Address { + [CmdletBinding(DefaultParameterSetName="ByID")] + [OutputType('address')] + param ( + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] + [ValidateScript({ $_ -match "^\d+$" })] + [ValidateNotNullOrEmpty()] + [string] + $Id, + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByIP")] + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="BySubnetId")] + [ValidateScript({[ipaddress] $_})] + [ValidateNotNullOrEmpty()] + [string] + $IP, + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByHostName")] + [ValidateNotNullOrEmpty()] + [string] + $HostName, + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByTag")] + [ValidateScript({ $_ -match "^\d+$" })] + [ValidateNotNullOrEmpty()] + [string] + $TagId, + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetId")] + [ValidateScript({ $_ -match "^\d+$" })] + [ValidateNotNullOrEmpty()] + [string] + $SubnetId, + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetCIDR")] + [ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})] + [ValidateNotNullOrEmpty()] + [string] + $SubnetCIDR + ) + process { + $_params = @{ + Controller = "addresses" + Method = "GET" + Type = "address" + } + switch ($PSCmdlet.ParameterSetName) { + "ByID" { $_identifiers = @($id) } + "ByIP" { $_identifiers = ("search",$IP) } + "ByHostName" { $_identifiers = ("search_hostname",$HostName) } + "ByTag" { $_identifiers = ("tags",$TagId,"addresses") } + "BySubnetId" { + if ($IP) { + $_identifiers = ($IP,$SubnetId) + } else { + $_params.Item("Controller") = "subnets" + $_identifiers = ($SubnetId,"addresses") + } + } + "BySubnetCIDR" { + $_params.Item("Controller") = "subnets" + $_subnetId = (Get-Subnet -CIDR $SubnetCIDR).id + if (!$_subnetId) { throw "Cannot find subnet!" } + + $_identifiers = ($_subnetId,"addresses") + } + } + $_params.Add("Identifiers",$_identifiers) + + Invoke-Request @_params + } +} +Export-ModuleMember -Function Get-Address \ No newline at end of file diff --git a/functions/public/Get-PSIPAMFirstFreeIP.ps1 b/functions/public/Get-FirstFreeIP.ps1 similarity index 82% rename from functions/public/Get-PSIPAMFirstFreeIP.ps1 rename to functions/public/Get-FirstFreeIP.ps1 index 47215d2..c5702d8 100644 --- a/functions/public/Get-PSIPAMFirstFreeIP.ps1 +++ b/functions/public/Get-FirstFreeIP.ps1 @@ -1,4 +1,4 @@ -function Get-PSIPAMFirstFreeIP { +function Get-FirstFreeIP { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")] @@ -20,14 +20,14 @@ function Get-PSIPAMFirstFreeIP { switch ($PSCmdlet.ParameterSetName) { "ByID" { $_subnetId = $Id } "ByCIDR" { - $_subnetId = (Get-PSIPAMSubnet -CIDR $CIDR).id + $_subnetId = (Get-Subnet -CIDR $CIDR).id if (!$_subnetId) { throw "Cannot find subnet!" } } } $_identifiers = @($_subnetId,"first_free") $_params.Add("Identifiers",$_identifiers) - return Invoke-PSIPAMRequest @_params | Select-Object @{n="Ip";e={$_}} + return Invoke-Request @_params | Select-Object @{n="Ip";e={$_}} } } -Export-ModuleMember -Function Get-PSIPAMFirstFreeIP \ No newline at end of file +Export-ModuleMember -Function Get-FirstFreeIP \ No newline at end of file diff --git a/functions/public/Get-PSIPAML2Domain.ps1 b/functions/public/Get-L2Domain.ps1 similarity index 87% rename from functions/public/Get-PSIPAML2Domain.ps1 rename to functions/public/Get-L2Domain.ps1 index 2a20537..d61bf48 100644 --- a/functions/public/Get-PSIPAML2Domain.ps1 +++ b/functions/public/Get-L2Domain.ps1 @@ -1,4 +1,4 @@ -function Get-PSIPAML2Domain { +function Get-L2Domain { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] @@ -19,8 +19,8 @@ function Get-PSIPAML2Domain { $_params.Add("Identifiers",$_identifiers) - Invoke-PSIPAMRequest @_params | ` + Invoke-Request @_params | ` Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru } } -Export-ModuleMember -Function Get-PSIPAML2Domain \ No newline at end of file +Export-ModuleMember -Function Get-L2Domain \ No newline at end of file diff --git a/functions/public/Get-PSIPAMNameserver.ps1 b/functions/public/Get-Nameserver.ps1 similarity index 82% rename from functions/public/Get-PSIPAMNameserver.ps1 rename to functions/public/Get-Nameserver.ps1 index 8c6fa3b..f487108 100644 --- a/functions/public/Get-PSIPAMNameserver.ps1 +++ b/functions/public/Get-Nameserver.ps1 @@ -1,4 +1,4 @@ -function Get-PSIPAMNameserver { +function Get-Nameserver { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] @@ -22,8 +22,8 @@ function Get-PSIPAMNameserver { $_identifiers = @($_nameserverId) $_params.Add("Identifiers",$_identifiers) - Invoke-PSIPAMRequest @_params | Select-Object @{n="address";e={$_.namesrv1}},* | Select-Object -ExcludeProperty namesrv1 | ` + Invoke-Request @_params | Select-Object @{n="address";e={$_.namesrv1}},* | Select-Object -ExcludeProperty namesrv1 | ` Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru } } -Export-ModuleMember -Function Get-PSIPAMNameserver \ No newline at end of file +Export-ModuleMember -Function Get-Nameserver \ No newline at end of file diff --git a/functions/public/Get-PSIPAMTags.ps1 b/functions/public/Get-PSIPAMTags.ps1 deleted file mode 100644 index cd8f0ec..0000000 --- a/functions/public/Get-PSIPAMTags.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -function Get-PSIPAMTags { - [CmdletBinding()] - param ( - [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] - [ValidateScript({ $_ -match "^\d+$" })] - [ValidateNotNullOrEmpty()] - [string] - $Id - ) - process { - [string[]]$visiblePropertiesList = @('Id','Name') - $visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList) - - $_params = @{ - Controller = "addresses" - Method = "GET" - } - $_identifiers = @("tags") - if ($Id) { $_identifiers += $Id } - $_params.Add("Identifiers",$_identifiers) - - Invoke-PSIPAMRequest @_params | ` - Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru - } -} -Export-ModuleMember -Function Get-PSIPAMTags \ No newline at end of file diff --git a/functions/public/Get-PSIPAMAddress.ps1 b/functions/public/Get-Permissions.ps1 similarity index 92% rename from functions/public/Get-PSIPAMAddress.ps1 rename to functions/public/Get-Permissions.ps1 index 252536c..d86b94c 100644 --- a/functions/public/Get-PSIPAMAddress.ps1 +++ b/functions/public/Get-Permissions.ps1 @@ -1,5 +1,5 @@ -function Get-PSIPAMAddress { - [CmdletBinding(DefaultParameterSetName="ByID")] +function Get-Permissions { + [CmdletBinding()] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [ValidateScript({ $_ -match "^\d+$" })] @@ -55,7 +55,7 @@ function Get-PSIPAMAddress { } "BySubnetCIDR" { $_params.Item("Controller") = "subnets" - $_subnetId = (Get-PSIPAMSubnet -CIDR $SubnetCIDR).id + $_subnetId = (Get-Subnet -CIDR $SubnetCIDR).id if (!$_subnetId) { throw "Cannot find subnet!" } $_identifiers = ($_subnetId,"addresses") @@ -63,8 +63,8 @@ function Get-PSIPAMAddress { } $_params.Add("Identifiers",$_identifiers) - Invoke-PSIPAMRequest @_params | ` + Invoke-Request @_params | ` Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru } } -Export-ModuleMember -Function Get-PSIPAMAddress \ No newline at end of file +Export-ModuleMember -Function Get-Permissions \ No newline at end of file diff --git a/functions/public/Get-PSIPAMSection.ps1 b/functions/public/Get-Section.ps1 similarity index 90% rename from functions/public/Get-PSIPAMSection.ps1 rename to functions/public/Get-Section.ps1 index 0894b1d..30caca2 100644 --- a/functions/public/Get-PSIPAMSection.ps1 +++ b/functions/public/Get-Section.ps1 @@ -1,4 +1,4 @@ -function Get-PSIPAMSection { +function Get-Section { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")] @@ -25,8 +25,8 @@ function Get-PSIPAMSection { } $_params.Add("Identifiers",$_identifiers) - Invoke-PSIPAMRequest @_params | ` + Invoke-Request @_params | ` Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru } } -Export-ModuleMember Get-PSIPAMSection \ No newline at end of file +Export-ModuleMember Get-Section \ No newline at end of file diff --git a/functions/public/Get-PSIPAMSubnet.ps1 b/functions/public/Get-Subnet.ps1 similarity index 90% rename from functions/public/Get-PSIPAMSubnet.ps1 rename to functions/public/Get-Subnet.ps1 index 0d22635..205a749 100644 --- a/functions/public/Get-PSIPAMSubnet.ps1 +++ b/functions/public/Get-Subnet.ps1 @@ -1,4 +1,4 @@ -function Get-PSIPAMSubnet { +function Get-Subnet { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")] @@ -58,6 +58,7 @@ function Get-PSIPAMSubnet { $_params = @{ Controller = "subnets" Method = "GET" + Type = "subnet" } switch ($PSCmdlet.ParameterSetName) { "ByCIDR" { @@ -82,7 +83,7 @@ function Get-PSIPAMSubnet { } "BySectionName" { $_params.Item("Controller") = "sections" - $_sectionId = (Get-PSIPAMSection -Name $SectionName).id + $_sectionId = (Get-Section -Name $SectionName).id if (!$_sectionId) { throw "Cannot find section!" } $_identifiers = @($_sectionId,"subnets") @@ -97,7 +98,7 @@ function Get-PSIPAMSubnet { $_params.Item("Controller") = "vlan" $_vlanId = $VlanId if ($SectionId) { $_sectionId = $SectionId } - if ($SectionName){ $_sectionId = (Get-PSIPAMSection -Name $SectionName).id } + if ($SectionName){ $_sectionId = (Get-Section -Name $SectionName).id } $_identifiers = @($_vlanId,"subnets") @@ -105,10 +106,10 @@ function Get-PSIPAMSubnet { } "ByVlanNumber" { $_params.Item("Controller") = "vlan" - $_vlans = Get-PSIPAMVlan -Number $VlanNumber + $_vlans = Get-Vlan -Number $VlanNumber if ($VlanDomain) { $_vlans = $_vlans | Where-Object {$_.domainId -eq $VlanDomain} } if ($SectionId) { $_sectionId = $SectionId } - if ($SectionName){ $_sectionId = (Get-PSIPAMSection -Name $SectionName).id } + if ($SectionName){ $_sectionId = (Get-Section -Name $SectionName).id } $_vlanId = $_vlans.vlanId @@ -122,8 +123,7 @@ function Get-PSIPAMSubnet { } $_params.Add("Identifiers",$_identifiers) - Invoke-PSIPAMRequest @_params | ` - Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru + Invoke-Request @_params } } -Export-ModuleMember Get-PSIPAMSubnet \ No newline at end of file +Export-ModuleMember Get-Subnet \ No newline at end of file diff --git a/functions/public/Get-PSIPAMSubnetUsage.ps1 b/functions/public/Get-SubnetUsage.ps1 similarity index 84% rename from functions/public/Get-PSIPAMSubnetUsage.ps1 rename to functions/public/Get-SubnetUsage.ps1 index 7b8b550..4cf1cbf 100644 --- a/functions/public/Get-PSIPAMSubnetUsage.ps1 +++ b/functions/public/Get-SubnetUsage.ps1 @@ -1,4 +1,4 @@ -function Get-PSIPAMSubnetUsage { +function Get-SubnetUsage { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")] @@ -19,7 +19,7 @@ function Get-PSIPAMSubnetUsage { } switch ($PSCmdlet.ParameterSetName) { "ByCIDR" { - $_subnetId = (Get-PSIPAMSubnet -CIDR $CIDR).id + $_subnetId = (Get-Subnet -CIDR $CIDR).id if (!$_subnetId) { throw "Cannot find subnet!" } } "ByID" { $_subnetId = $Id } @@ -27,7 +27,7 @@ function Get-PSIPAMSubnetUsage { $_identifiers = @($_subnetId,"usage") $_params.Add("Identifiers",$_identifiers) - return Invoke-PSIPAMRequest @_params + return Invoke-Request @_params } } -Export-ModuleMember -Function Get-PSIPAMSubnetUsage \ No newline at end of file +Export-ModuleMember -Function Get-SubnetUsage \ No newline at end of file diff --git a/functions/public/Get-Tag.ps1 b/functions/public/Get-Tag.ps1 new file mode 100644 index 0000000..02cec76 --- /dev/null +++ b/functions/public/Get-Tag.ps1 @@ -0,0 +1,37 @@ +function Get-Tag { + [CmdletBinding(DefaultParameterSetName="NoParams")] + [OutputType('tag')] + param ( + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] + [ValidateScript({ $_ -match "^\d+$" })] + [ValidateNotNullOrEmpty()] + [string] + $Id, + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")] + [ValidateNotNullOrEmpty()] + [ps.ipam.address] + $InputObject + ) + process { + $_params = @{ + Controller = "addresses" + Method = "GET" + Type = "tag" + } + $_identifiers = @("tags") + switch ($PSCmdlet.ParameterSetName) { + "ByID" { $_identifiers += $Id } + "ByAddressObject" { + if ($InputObject.TagId) { + $_identifiers += $InputObject.TagId + } else { + return $null + } + } + } + $_params.Add("Identifiers",$_identifiers) + + Invoke-Request @_params + } +} +Export-ModuleMember -Function Get-Tag \ No newline at end of file diff --git a/functions/public/Get-PSIPAMVlan.ps1 b/functions/public/Get-Vlan.ps1 similarity index 89% rename from functions/public/Get-PSIPAMVlan.ps1 rename to functions/public/Get-Vlan.ps1 index 60634b2..10565a0 100644 --- a/functions/public/Get-PSIPAMVlan.ps1 +++ b/functions/public/Get-Vlan.ps1 @@ -1,4 +1,4 @@ -function Get-PSIPAMVlan { +function Get-Vlan { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] @@ -38,8 +38,8 @@ function Get-PSIPAMVlan { } $_params.Add("Identifiers",$_identifiers) - Invoke-PSIPAMRequest @_params | Select-Object @{n="id";e={$_.vlanId}},* | Select-Object -ExcludeProperty vlanId | ` + Invoke-Request @_params | Select-Object @{n="id";e={$_.vlanId}},* | Select-Object -ExcludeProperty vlanId | ` Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru } } -Export-ModuleMember -Function Get-PSIPAMVlan \ No newline at end of file +Export-ModuleMember -Function Get-Vlan \ No newline at end of file diff --git a/functions/public/Get-PSIPAMVrf.ps1 b/functions/public/Get-Vrf.ps1 similarity index 81% rename from functions/public/Get-PSIPAMVrf.ps1 rename to functions/public/Get-Vrf.ps1 index 6846a4c..7ab658b 100644 --- a/functions/public/Get-PSIPAMVrf.ps1 +++ b/functions/public/Get-Vrf.ps1 @@ -1,4 +1,4 @@ -function Get-PSIPAMVrf { +function Get-Vrf { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] @@ -19,8 +19,8 @@ function Get-PSIPAMVrf { $_params.Add("Identifiers",$_identifiers) - Invoke-PSIPAMRequest @_params | Select-Object @{n="id";e={$_.vrfId}},* | Select-Object -ExcludeProperty vrfId | ` + Invoke-Request @_params | Select-Object @{n="id";e={$_.vrfId}},* | Select-Object -ExcludeProperty vrfId | ` Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru } } -Export-ModuleMember -Function Get-PSIPAMVrf \ No newline at end of file +Export-ModuleMember -Function Get-Vrf \ No newline at end of file diff --git a/functions/public/New-PSIPAMAddress.ps1 b/functions/public/New-Address.ps1 similarity index 97% rename from functions/public/New-PSIPAMAddress.ps1 rename to functions/public/New-Address.ps1 index 0a70bfa..b805b86 100644 --- a/functions/public/New-PSIPAMAddress.ps1 +++ b/functions/public/New-Address.ps1 @@ -1,4 +1,4 @@ -function New-PSIPAMAddress { +function New-Address { [CmdletBinding()] param ( [parameter( @@ -172,11 +172,11 @@ function New-PSIPAMAddress { $_params.Add("Params",$_body) try { - Invoke-PSIPAMRequest @_params + Invoke-Request @_params } finally { - Get-PSIPAMAddress -SubnetId $SubnetId -Ip $Ip + Get-Address -SubnetId $SubnetId -Ip $Ip } } } -Export-ModuleMember -Function New-PSIPAMAddress \ No newline at end of file +Export-ModuleMember -Function New-Address \ No newline at end of file diff --git a/functions/public/New-PSIPAMFirstFreeIP.ps1 b/functions/public/New-FirstFreeIP.ps1 similarity index 96% rename from functions/public/New-PSIPAMFirstFreeIP.ps1 rename to functions/public/New-FirstFreeIP.ps1 index fe377dc..39c2b8b 100644 --- a/functions/public/New-PSIPAMFirstFreeIP.ps1 +++ b/functions/public/New-FirstFreeIP.ps1 @@ -1,4 +1,4 @@ -function New-PSIPAMFirstFreeIP { +function New-FirstFreeIP { [CmdletBinding()] param ( [parameter( @@ -163,10 +163,10 @@ function New-PSIPAMFirstFreeIP { $_params.Add("Params",$_body) - $_result = Invoke-PSIPAMRequest @_params + $_result = Invoke-Request @_params if ($_result) { - Get-PSIPAMAddress -SubnetId $SubnetId -IP $_result + Get-Address -SubnetId $SubnetId -IP $_result } } } -Export-ModuleMember -Function New-PSIPAMFirstFreeIP \ No newline at end of file +Export-ModuleMember -Function New-FirstFreeIP \ No newline at end of file diff --git a/functions/public/New-PSIPAMSession.ps1 b/functions/public/New-PSIPAMSession.ps1 deleted file mode 100644 index 119a59e..0000000 --- a/functions/public/New-PSIPAMSession.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -function New-PSIPAMSession { - [CmdletBinding()] - param ( - [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] - [ValidateNotNullOrEmpty()] - [string]$URL, - [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1)] - [ValidateNotNullOrEmpty()] - [string]$AppID, - [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2)] - [ValidateNotNullOrEmpty()] - [pscredential]$Credentials - ) - $_bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credentials.Password) - $_password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($_bstr) - $_uri = "$URL/api/$AppID/user" - $_auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$($Credentials.UserName):$_password")) - $_headers = @{ - "Accept" = "application/json" - "Content-Type" = "application/json" - "Authorization" = "Basic $_auth" - } - - $_response = Invoke-RestMethod -Method Post -Uri $_uri -Headers $_headers -ErrorAction SilentlyContinue - - if ($_response.success -eq $true) { - $script:ipamAuth = $true - $script:ipamToken = $_response.data.token - $script:ipamAppID = $AppID - $script:ipamURL = $URL - $script:ipamCredentials = $Credentials - $script:ipamExpires = Get-Date $_response.data.expires - } else { - $_response.error - } -} -Export-ModuleMember -Function New-PSIPAMSession \ No newline at end of file diff --git a/functions/public/New-Session.ps1 b/functions/public/New-Session.ps1 new file mode 100644 index 0000000..560594e --- /dev/null +++ b/functions/public/New-Session.ps1 @@ -0,0 +1,53 @@ +function New-Session { + [CmdletBinding(DefaultParameterSetName="Credentials")] + param ( + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] + [ValidateNotNullOrEmpty()] + [string]$URL, + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1)] + [ValidateNotNullOrEmpty()] + [string]$AppID, + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="Credentials")] + [ValidateNotNullOrEmpty()] + [pscredential]$Credentials, + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="Token")] + [ValidateNotNullOrEmpty()] + [string]$Token, + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=3)] + [switch]$IgnoreSSL = $false + ) + switch ($PSCmdlet.ParameterSetName) { + "Credentials" { + $_bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credentials.Password) + $_password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($_bstr) + $_uri = "$URL/api/$AppID/user" + $_auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$($Credentials.UserName):$_password")) + $_headers = @{ + "Accept" = "application/json" + "Content-Type" = "application/json" + "Authorization" = "Basic $_auth" + } + + $_response = Invoke-RestMethod -Method Post -Uri $_uri -Headers $_headers -ErrorAction SilentlyContinue + + if ($_response.success -ne $true) { return $_response.error } + + $script:ipamAuthType = "Credentials" + $script:ipamAuth = $true + $script:ipamToken = $_response.data.token + $script:ipamAppID = $AppID + $script:ipamURL = $URL + $script:ipamCredentials = $Credentials + $script:ipamExpires = Get-Date $_response.data.expires + } + "Token" { + $script:ipamAuthType = "Token" + $script:ipamAuth = $true + $script:ipamToken = $Token + $script:ipamAppID = $AppID + $script:ipamURL = $URL + $script:ipamExpires = "Never" + } + } +} +Export-ModuleMember -Function New-Session \ No newline at end of file diff --git a/functions/public/New-PSIPAMSubnet.ps1 b/functions/public/New-Subnet.ps1 similarity index 97% rename from functions/public/New-PSIPAMSubnet.ps1 rename to functions/public/New-Subnet.ps1 index d655d34..72db734 100644 --- a/functions/public/New-PSIPAMSubnet.ps1 +++ b/functions/public/New-Subnet.ps1 @@ -1,4 +1,4 @@ -function New-PSIPAMSubnet { +function New-Subnet { [CmdletBinding()] param ( [parameter( @@ -193,10 +193,10 @@ function New-PSIPAMSubnet { $_params.Add("Params",$_body) - $_result = Invoke-PSIPAMRequest @_params + $_result = Invoke-Request @_params if ($_result) { - return Get-PSIPAMSubnet -CIDR $_result + return Get-Subnet -CIDR $_result } } } -Export-ModuleMember -Function New-PSIPAMSubnet \ No newline at end of file +Export-ModuleMember -Function New-Subnet \ No newline at end of file diff --git a/functions/public/Remove-PSIPAMAddress.ps1 b/functions/public/Remove-Address.ps1 similarity index 90% rename from functions/public/Remove-PSIPAMAddress.ps1 rename to functions/public/Remove-Address.ps1 index 49d31b0..fba0892 100644 --- a/functions/public/Remove-PSIPAMAddress.ps1 +++ b/functions/public/Remove-Address.ps1 @@ -1,4 +1,4 @@ -function Remove-PSIPAMAddress { +function Remove-Address { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")] @@ -29,7 +29,7 @@ function Remove-PSIPAMAddress { } $_params.Add("Identifiers",$_identifiers) - Invoke-PSIPAMRequest @_params + Invoke-Request @_params } } -Export-ModuleMember Remove-PSIPAMAddress \ No newline at end of file +Export-ModuleMember Remove-Address \ No newline at end of file diff --git a/functions/public/Set-PSIPAMAddress.ps1 b/functions/public/Set-Address.ps1 similarity index 97% rename from functions/public/Set-PSIPAMAddress.ps1 rename to functions/public/Set-Address.ps1 index df04f00..a9c0693 100644 --- a/functions/public/Set-PSIPAMAddress.ps1 +++ b/functions/public/Set-Address.ps1 @@ -1,4 +1,4 @@ -function Set-PSIPAMAddress { +function Set-Address { [CmdletBinding()] param ( [parameter( @@ -162,11 +162,11 @@ function Set-PSIPAMAddress { $_params.Add("Params",$_body) try { - Invoke-PSIPAMRequest @_params + Invoke-Request @_params } finally { - Get-PSIPAMAddress -Id $Id + Get-Address -Id $Id } } } -Export-ModuleMember -Function Set-PSIPAMAddress \ No newline at end of file +Export-ModuleMember -Function Set-Address \ No newline at end of file diff --git a/functions/public/Set-PSIPAMSubnet.ps1 b/functions/public/Set-Subnet.ps1 similarity index 100% rename from functions/public/Set-PSIPAMSubnet.ps1 rename to functions/public/Set-Subnet.ps1 diff --git a/old/address.ps1 b/old/address.ps1 new file mode 100644 index 0000000..8c0f9c6 --- /dev/null +++ b/old/address.ps1 @@ -0,0 +1,75 @@ +Add-Type @' +using System; +namespace ps.ipam { + public class address { + public int Id { get; set; } + public int SubnetId { get; set; } + public string Ip { get; set; } + public bool IsGateway { get; set; } + public string Description { get; set; } + public string Hostname { get; set; } + public string MAC { get; set; } + public string Owner { get; set; } + public int TagId { get; set; } + public int DeviceId { get; set; } + public string Location { get; set; } + public int Port { get; set; } + public string Note { get; set; } + public DateTime? LastSeen { get; set; } + public bool ExcludePing { get; set; } + public int PTRignore { get; set; } + public int PTR { get; set; } + public string FirewallAddressObject { get; set; } + public DateTime? EditDate { get; set; } + public int CustomerId { get; set; } + + public address( + int id, + int subnetId, + string ip, + bool is_gateway, + string description, + string hostname, + string mac, + string owner, + int tag, + int deviceId, + string location, + int port, + string note, + DateTime? lastSeen, + bool excludePing, + int PTRignore, + int PTR, + string firewallAddressObject, + DateTime? editDate, + int customer_id + ) { + this.Id = id; + this.SubnetId = subnetId; + this.Ip = ip; + this.IsGateway = is_gateway; + this.Description = description; + this.Hostname = hostname; + this.MAC = mac; + this.Owner = owner; + this.TagId = tag; + this.DeviceId = deviceId; + this.Location = location; + this.Port = port; + this.Note = note; + this.EditDate = lastSeen; + this.ExcludePing = excludePing; + this.PTRignore = PTRignore; + this.PTR = PTR; + this.FirewallAddressObject = firewallAddressObject; + this.EditDate = editDate; + this.CustomerId = customer_id; + } + + public override string ToString() { + return this.Ip; + } + } +} +'@ \ No newline at end of file diff --git a/old/tag.ps1 b/old/tag.ps1 new file mode 100644 index 0000000..5d9d06e --- /dev/null +++ b/old/tag.ps1 @@ -0,0 +1,33 @@ +class tag { + [int]$id + [string]$Type + [bool]$ShowTag + [System.Drawing.Color]$BGColor + [System.Drawing.Color]$FGColor + [bool]$Compress + [bool]$Locked + [bool]$UpdateTag + + tag ([int]$id,[string]$type,[bool]$showTag,[string]$BGColor,[string]$FGColor,[string]$compress,[string]$locked,[bool]$updateTag) { + $this.id = $id + $this.Type = $type + $this.ShowTag = $showTag + $this.BGColor = $BGColor + $this.FGColor = $FGColor + $this.Compress = $this.ToBool($compress) + $this.Locked = $this.ToBool($locked) + $this.UpdateTag = $updateTag + } + + [string] ToString() { + return $this.Type + } + + hidden [bool]ToBool([string]$str) { + if ($str -eq "Yes") { + return $true + } else { + return $false + } + } +} \ No newline at end of file diff --git a/ps.ipam.psd1 b/ps.ipam.psd1 index 24b4119bd8f43db8793b49ee6feed488fedfef0a..a267af202bedc582590ac48b703deaac6e4e444d 100644 GIT binary patch literal 3138 zcmcJR+fN!%5XR@ZN&g2D9?(QVX^m}@CK7LHqJ(&R@}?CzQQ=9|lzIe&f^?Y+ITq804e1{T@9b?t_?o?ThrI@aQCY%yP2?2p_|TCQY6 z_RB~P(dhAX?c{E(G(isdhamO&jgX63Be0tGWM5e8=-;8&W$%giGbeL}YzLizJ!G(i zsNatLa%%w%{hc5=06Xi+S9a!EignL6CoBU(TJyqj9m8M%hk|*WDjsgkXdT+QeY3r( z%r(Ak*|vSKkM^1W>#S9NTkdJY?X2TrmAy}VYw_IVt%}4Zy4!q>=B(7nO>Ax0C<~s= z^0@gd1pju?9ui^2^%gAU)g!Htw^iP%*cFpJIVmGmBWGRK1aa)%R5i-=gUfVzCSrSh z9b-{iLs(>E+<@idB>HVuZ{eFYuyzc3I!jsq63tV*^O`T`af>{L?5mbSgig@_7*)DLN zJ8+3O1)9r|W22hV9M5V*;OG{iDepOH)%1_id~!Adst~l-gOB=E!J+Gppl97b0)qOn z-_Cqq(@N&G%$=;SL$}cb7f4Uco@qGu%VcnG88>&;wtV4idAgKhx<> zuiHzTUzmU;CiP3U0@4vomCL@%+__^O=DcQp4Az)?SB1Y@WMd|ia;p2@9eQP+@7b%R zzEzw~a?h)PFv3cOE~jj1UbJ}&9kpUd@ZDu<)QP}8z2P;+e#U*rwtDRUVf;FSB5ZYY z?ax^ETCZ_0QUN;Qs(61+>+ad+%zq2jo_Uxja#-IP9JD6^sy79+k YN*%=afymuCwA-Q2gvyz%L7_j}U(oBU@c;k- literal 5904 zcmd^@TW?!M5Xa{kiSKZvJUB=sG@(@i38_}oRFTrCYA)}NFTvm&wnJJ~e0Avmx8v=e z^*KIH3V8uV&bjRD%zy5)=kLFE>}&hVcC4^BHnpDJ+Q|BP8e7LEHnf4B7Pi!zf!60? zrA*hdnb!A3In$1@?z(}lZ><&Q$p5uCP4t_KZmDZeysqto{iN%e_W!1RBdvYV^F^TP zh<2zwQ~M+11xJ1_>|?k_3Fnf{j#XDLZM69>QR+LwK>+fa7JmrLCZ!ke;15*D<1 zZI|YJU2a!A$yhoU&p-sgJTs~~R+ z9T?opP4)p(PVKn1N1(@Z^w3Mmnn`!!?M9Nx5c0(1WxTRa%9_m07PDxsUks%88Ei)q9^4iFIgu;)ea0e&Qri zsD=|KJ=ulK?FAb%UD6@)9n>T;7u%+Q;fG| z*4u&;z|9sbTq#zFf+jv!vd^HA;!Hf~;%PRbZ#c4geqtoGoqXZpjO3k!&RT?ycceSV&S{G?8&4kDJ_UdtdiorvM(>G!uF5r{ zBC|W$BYl_Ps}U08>F_*E!JH1=6S++jDxa0oH={ya_@i5Ir;5}&+HoOdbSHF~>CaDH z%rnVL(RyimjCS>2Q>;+Wv@3mE%B_Hv7Qx=sbpLAQ^CTWXD!rEzDmL^pkDveC5)pH} z=Gd#VW2B2$=-c{T>STJVYtjy>$Y=7K2qVui|M7C2_Ef3JIbM-)n(?^|8R4gZlai*)}Cr%$ig4^R5n8E|-P__wvD zF9w@Yo~(F21Rs+F(c@L_Oqj40@tsaPRgZ4+=Vop`C0Bj=rzGLeSF#0J + + + ps.ipam.address + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Id + Ip + Hostname + Description + + + + DefaultKeyPropertySet + + Id + + + + + + + + ps.ipam.tag + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Id + Type + + + + DefaultKeyPropertySet + + Id + + + + + + + \ No newline at end of file From affbd18de26d9114db17375a9853766506f4a2d5 Mon Sep 17 00:00:00 2001 From: Arnike Date: Mon, 5 Dec 2022 14:08:59 +0300 Subject: [PATCH 2/9] classlib all types implemented --- classlib/address.cs | 9 ++- classlib/classlib.csproj | 3 +- classlib/domain.cs | 27 +++++++ classlib/enum.cs | 6 -- classlib/section.cs | 54 ++++++++++++++ classlib/subnet.cs | 42 ++--------- classlib/tag.cs | 1 + classlib/vlan.cs | 32 ++++++++ classlib/vrf.cs | 32 ++++++++ functions/public/New-Session.ps1 | 1 + old/address.ps1 | 75 ------------------- old/tag.ps1 | 33 --------- ps.ipam.psd1 | Bin 3138 -> 3336 bytes types/types.ps1xml | 121 +++++++++++++++++++++++++++++++ 14 files changed, 282 insertions(+), 154 deletions(-) create mode 100644 classlib/domain.cs delete mode 100644 classlib/enum.cs create mode 100644 classlib/section.cs create mode 100644 classlib/vlan.cs create mode 100644 classlib/vrf.cs delete mode 100644 old/address.ps1 delete mode 100644 old/tag.ps1 diff --git a/classlib/address.cs b/classlib/address.cs index 7f411fb..2546695 100644 --- a/classlib/address.cs +++ b/classlib/address.cs @@ -1,6 +1,7 @@ namespace PS.IPAM; using System; +[Serializable] public class Address { public int Id { get; } public int SubnetId { get; } @@ -13,11 +14,11 @@ public class Address { public int TagId { get; } public int DeviceId { get; } public string Location { get; } - public int Port { get; } + public string Port { get; } public string Note { get; } public DateTime? LastSeen { get; } public bool ExcludePing { get; } - public int PTRignore { get; } + public bool PTRignore { get; } public int PTR { get; } public string FirewallAddressObject { get; } public DateTime? EditDate { get; } @@ -35,11 +36,11 @@ public class Address { int tag, int deviceId, string location, - int port, + string port, string note, DateTime? lastSeen, bool excludePing, - int PTRignore, + bool PTRignore, int PTR, string firewallAddressObject, DateTime? editDate, diff --git a/classlib/classlib.csproj b/classlib/classlib.csproj index cfadb03..b3c1ee9 100644 --- a/classlib/classlib.csproj +++ b/classlib/classlib.csproj @@ -1,9 +1,10 @@ - net7.0 + netstandard2.1 enable enable + latest diff --git a/classlib/domain.cs b/classlib/domain.cs new file mode 100644 index 0000000..36b8530 --- /dev/null +++ b/classlib/domain.cs @@ -0,0 +1,27 @@ +namespace PS.IPAM; +using System; + +[Serializable] +public class Domain { + public int Id { get; } + public string Name { get; } + public string Description { get; } + public string Sections { get; } + + public Domain ( + int id, + string name, + string description, + string sections + ) { + this.Id = id; + this.Name = name; + this.Description = description; + this.Sections = sections; + } + + public override string ToString() + { + return this.Name; + } +} \ No newline at end of file diff --git a/classlib/enum.cs b/classlib/enum.cs deleted file mode 100644 index 23d694b..0000000 --- a/classlib/enum.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace PS.IPAM; -using System; - -enum Parameters { - IsGateway = "is_gateway"; -} \ No newline at end of file diff --git a/classlib/section.cs b/classlib/section.cs new file mode 100644 index 0000000..8f33f8b --- /dev/null +++ b/classlib/section.cs @@ -0,0 +1,54 @@ +namespace PS.IPAM; +using System; + +[Serializable] +public class Section { + public int Id { get; } + public string Name { get; } + public string Description { get; } + public int MasterSectionId { get; } + public string Permissions { get; } + public bool StrictMode { get; } + public string SubnetOrdering { get; } + public int Order { get; } + public DateTime? EditDate { get; } + public bool ShowVlan { get; } + public bool ShowVRF { get; } + public bool ShowSupernetOnly { get; } + public int DNSId { get; } + + public Section ( + int id, + string name, + string description, + int masterSectionId, + string permissions, + bool strictMode, + string subnetOrdering, + int order, + DateTime? editDate, + bool showVlan, + bool showVRF, + bool showSupernetOnly, + int dnsId + ) { + this.Id = id; + this.Name = name; + this.Description = description; + this.MasterSectionId = masterSectionId; + this.Permissions = permissions; + this.StrictMode = strictMode; + this.SubnetOrdering = subnetOrdering; + this.Order = order; + this.EditDate = editDate; + this.ShowVlan = showVlan; + this.ShowVRF = showVRF; + this.ShowSupernetOnly = showSupernetOnly; + this.DNSId = dnsId; + } + + public override string ToString() + { + return this.Name; + } +} \ No newline at end of file diff --git a/classlib/subnet.cs b/classlib/subnet.cs index e3aca08..bc8d07d 100644 --- a/classlib/subnet.cs +++ b/classlib/subnet.cs @@ -1,6 +1,7 @@ namespace PS.IPAM; using System; +[Serializable] public class Subnetwork { public int Id { get; } public string Subnet { get; } @@ -55,41 +56,12 @@ public class Subnetwork { this.ResolveDNS = resolveDNS; } - public override string ToString() - { + public string GetCIDR() { return $"{this.Subnet}/{this.Mask}"; } -} -id : 1 -subnet : fd13:6d20:29dc:cf27:: -mask : 64 -sectionId : 2 -description : Private subnet 1 -linked_subnet : -firewallAddressObject : -vrfId : 0 -masterSubnetId : 0 -allowRequests : 1 -vlanId : 1 -showName : 1 -device : 0 -permissions : {"3":"1","2":"2"} -pingSubnet : 0 -discoverSubnet : 0 -resolveDNS : 0 -DNSrecursive : 0 -DNSrecords : 0 -nameserverId : 0 -scanAgent : -customer_id : -isFolder : 0 -isFull : 0 -isPool : 0 -tag : 2 -threshold : 0 -location : -editDate : -lastScan : -lastDiscovery : -calculation : @{Type=IPv6; Host address=/; Host address (uncompressed)=/; Subnet prefix=fd13:6d20:29dc:cf27::/64; Prefix length=64; Subnet Reverse DNS=7.2.f.c.c.d.9.2.0.2.d.6.3.1.d.f.ip6.arpa; Min host IP=fd13:6d20:29dc:cf27::; Max host IP=fd13:6d20:29dc:cf27:ffff:ffff:ffff:ffff; Number of hosts=18446744073709551616; Address type=NET_IPV6} \ No newline at end of file + public override string ToString() + { + return this.GetCIDR(); + } +} \ No newline at end of file diff --git a/classlib/tag.cs b/classlib/tag.cs index 8b79ac0..9030726 100644 --- a/classlib/tag.cs +++ b/classlib/tag.cs @@ -1,5 +1,6 @@ namespace PS.IPAM; +[Serializable] public class Tag { public int Id { get; } public string Type { get; } diff --git a/classlib/vlan.cs b/classlib/vlan.cs new file mode 100644 index 0000000..2e7cff1 --- /dev/null +++ b/classlib/vlan.cs @@ -0,0 +1,32 @@ +namespace PS.IPAM; +using System; + +[Serializable] +public class Vlan { + public int Id { get; } + public int DomainId { get; } + public string Name { get; } + public int Number { get; } + public string Description { get; } + public DateTime? EditDate { get; } + public Vlan ( + int id, + int domainId, + string name, + int number, + string description, + DateTime? editDate + ) { + this.Id = id; + this.DomainId = domainId; + this.Name = name; + this.Number = number; + this.Description = description; + this.EditDate = editDate; + } + + public override string ToString() + { + return $"{this.Number}"; + } +} \ No newline at end of file diff --git a/classlib/vrf.cs b/classlib/vrf.cs new file mode 100644 index 0000000..39654c3 --- /dev/null +++ b/classlib/vrf.cs @@ -0,0 +1,32 @@ +namespace PS.IPAM; +using System; + +[Serializable] +public class Vrf { + public int Id { get; } + public string Name { get; } + public string RouteDistinguisher { get; } + public string Description { get; } + public string Sections { get; } + public DateTime? EditDate { get; } + + public Vrf( + int id, + string name, + string rd, + string description, + string sections, + DateTime? editDate + ) { + this.Id = id; + this.Name = name; + this.RouteDistinguisher = rd; + this.Description = description; + this.Sections = sections; + this.EditDate = editDate; + } + public override string ToString() + { + return this.Name; + } +} \ No newline at end of file diff --git a/functions/public/New-Session.ps1 b/functions/public/New-Session.ps1 index 560594e..1757310 100644 --- a/functions/public/New-Session.ps1 +++ b/functions/public/New-Session.ps1 @@ -3,6 +3,7 @@ function New-Session { param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] [ValidateNotNullOrEmpty()] + [validatescript({$_.startswith("http")})] [string]$URL, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1)] [ValidateNotNullOrEmpty()] diff --git a/old/address.ps1 b/old/address.ps1 deleted file mode 100644 index 8c0f9c6..0000000 --- a/old/address.ps1 +++ /dev/null @@ -1,75 +0,0 @@ -Add-Type @' -using System; -namespace ps.ipam { - public class address { - public int Id { get; set; } - public int SubnetId { get; set; } - public string Ip { get; set; } - public bool IsGateway { get; set; } - public string Description { get; set; } - public string Hostname { get; set; } - public string MAC { get; set; } - public string Owner { get; set; } - public int TagId { get; set; } - public int DeviceId { get; set; } - public string Location { get; set; } - public int Port { get; set; } - public string Note { get; set; } - public DateTime? LastSeen { get; set; } - public bool ExcludePing { get; set; } - public int PTRignore { get; set; } - public int PTR { get; set; } - public string FirewallAddressObject { get; set; } - public DateTime? EditDate { get; set; } - public int CustomerId { get; set; } - - public address( - int id, - int subnetId, - string ip, - bool is_gateway, - string description, - string hostname, - string mac, - string owner, - int tag, - int deviceId, - string location, - int port, - string note, - DateTime? lastSeen, - bool excludePing, - int PTRignore, - int PTR, - string firewallAddressObject, - DateTime? editDate, - int customer_id - ) { - this.Id = id; - this.SubnetId = subnetId; - this.Ip = ip; - this.IsGateway = is_gateway; - this.Description = description; - this.Hostname = hostname; - this.MAC = mac; - this.Owner = owner; - this.TagId = tag; - this.DeviceId = deviceId; - this.Location = location; - this.Port = port; - this.Note = note; - this.EditDate = lastSeen; - this.ExcludePing = excludePing; - this.PTRignore = PTRignore; - this.PTR = PTR; - this.FirewallAddressObject = firewallAddressObject; - this.EditDate = editDate; - this.CustomerId = customer_id; - } - - public override string ToString() { - return this.Ip; - } - } -} -'@ \ No newline at end of file diff --git a/old/tag.ps1 b/old/tag.ps1 deleted file mode 100644 index 5d9d06e..0000000 --- a/old/tag.ps1 +++ /dev/null @@ -1,33 +0,0 @@ -class tag { - [int]$id - [string]$Type - [bool]$ShowTag - [System.Drawing.Color]$BGColor - [System.Drawing.Color]$FGColor - [bool]$Compress - [bool]$Locked - [bool]$UpdateTag - - tag ([int]$id,[string]$type,[bool]$showTag,[string]$BGColor,[string]$FGColor,[string]$compress,[string]$locked,[bool]$updateTag) { - $this.id = $id - $this.Type = $type - $this.ShowTag = $showTag - $this.BGColor = $BGColor - $this.FGColor = $FGColor - $this.Compress = $this.ToBool($compress) - $this.Locked = $this.ToBool($locked) - $this.UpdateTag = $updateTag - } - - [string] ToString() { - return $this.Type - } - - hidden [bool]ToBool([string]$str) { - if ($str -eq "Yes") { - return $true - } else { - return $false - } - } -} \ No newline at end of file diff --git a/ps.ipam.psd1 b/ps.ipam.psd1 index a267af202bedc582590ac48b703deaac6e4e444d..a08729afadeaf464337b2063dc92f40edfd0d691 100644 GIT binary patch delta 133 zcmX>k(IK@VjM+7rA%`K6p%@5r7%~}>7-E1plOYdC2Qj1q#ZtktsX%@nkX-^)R{|8t zV@Ls#ML^PsL65<3b2RgMc6LvOWQKf(yvb9!!Y5mCDamFsE(}D>4EA*)kmu delta 50 zcmeB>IwY|njF~luA(J6#^K9nz?EK0Mo(#zh`3!jsp$tU~nUkw|lqVnH;+UMkBR5%t G=K%m?`wkia diff --git a/types/types.ps1xml b/types/types.ps1xml index d2f7654..a56619e 100644 --- a/types/types.ps1xml +++ b/types/types.ps1xml @@ -48,4 +48,125 @@ + + ps.ipam.domain + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Id + Name + + + + DefaultKeyPropertySet + + Id + + + + + + + + ps.ipam.section + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Id + Name + MasterSectionId + StrictMode + + + + DefaultKeyPropertySet + + Id + + + + + + + + ps.ipam.vlan + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Id + Name + DomainId + Number + + + + DefaultKeyPropertySet + + Id + + + + + + + + ps.ipam.vrf + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Id + Name + + + + DefaultKeyPropertySet + + Id + + + + + + + + ps.ipam.subnet + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Id + Name + DomainId + Number + + + + DefaultKeyPropertySet + + Id + + + + + + \ No newline at end of file From c4b15d73875ae6ed2674c4c5c3906a9b3eeb840e Mon Sep 17 00:00:00 2001 From: Arnike Date: Mon, 5 Dec 2022 15:29:03 +0300 Subject: [PATCH 3/9] enums --- .gitignore | 3 ++- classlib/{ => class}/address.cs | 0 classlib/{ => class}/domain.cs | 0 classlib/{ => class}/section.cs | 0 classlib/{ => class}/subnet.cs | 0 classlib/{ => class}/tag.cs | 0 classlib/{ => class}/vlan.cs | 0 classlib/{ => class}/vrf.cs | 0 classlib/enum/controllers.cs | 14 ++++++++++++++ classlib/enum/methods.cs | 9 +++++++++ classlib/enum/subcontrollers.cs | 7 +++++++ functions/private/Invoke-Request.ps1 | 2 +- 12 files changed, 33 insertions(+), 2 deletions(-) rename classlib/{ => class}/address.cs (100%) rename classlib/{ => class}/domain.cs (100%) rename classlib/{ => class}/section.cs (100%) rename classlib/{ => class}/subnet.cs (100%) rename classlib/{ => class}/tag.cs (100%) rename classlib/{ => class}/vlan.cs (100%) rename classlib/{ => class}/vrf.cs (100%) create mode 100644 classlib/enum/controllers.cs create mode 100644 classlib/enum/methods.cs create mode 100644 classlib/enum/subcontrollers.cs diff --git a/.gitignore b/.gitignore index b061a64..4abcf34 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.dll bin -obj \ No newline at end of file +obj +.code-workspace diff --git a/classlib/address.cs b/classlib/class/address.cs similarity index 100% rename from classlib/address.cs rename to classlib/class/address.cs diff --git a/classlib/domain.cs b/classlib/class/domain.cs similarity index 100% rename from classlib/domain.cs rename to classlib/class/domain.cs diff --git a/classlib/section.cs b/classlib/class/section.cs similarity index 100% rename from classlib/section.cs rename to classlib/class/section.cs diff --git a/classlib/subnet.cs b/classlib/class/subnet.cs similarity index 100% rename from classlib/subnet.cs rename to classlib/class/subnet.cs diff --git a/classlib/tag.cs b/classlib/class/tag.cs similarity index 100% rename from classlib/tag.cs rename to classlib/class/tag.cs diff --git a/classlib/vlan.cs b/classlib/class/vlan.cs similarity index 100% rename from classlib/vlan.cs rename to classlib/class/vlan.cs diff --git a/classlib/vrf.cs b/classlib/class/vrf.cs similarity index 100% rename from classlib/vrf.cs rename to classlib/class/vrf.cs diff --git a/classlib/enum/controllers.cs b/classlib/enum/controllers.cs new file mode 100644 index 0000000..7d6c6a6 --- /dev/null +++ b/classlib/enum/controllers.cs @@ -0,0 +1,14 @@ +namespace PS.IPAM; +using System; + +[Serializable] +public enum controllers { + user, + vlan, + subnets, + addresses, + sections, + vrf, + l2domains, + tools +} \ No newline at end of file diff --git a/classlib/enum/methods.cs b/classlib/enum/methods.cs new file mode 100644 index 0000000..4cdee6b --- /dev/null +++ b/classlib/enum/methods.cs @@ -0,0 +1,9 @@ +namespace PS.IPAM; +using System; + +public enum methods { + GET, + POST, + PATCH, + DELETE +} \ No newline at end of file diff --git a/classlib/enum/subcontrollers.cs b/classlib/enum/subcontrollers.cs new file mode 100644 index 0000000..4565802 --- /dev/null +++ b/classlib/enum/subcontrollers.cs @@ -0,0 +1,7 @@ +namespace PS.IPAM; +using System; + +[Serializable] +public enum subcontrollers { + nameservers +} \ No newline at end of file diff --git a/functions/private/Invoke-Request.ps1 b/functions/private/Invoke-Request.ps1 index fd15398..843242f 100644 --- a/functions/private/Invoke-Request.ps1 +++ b/functions/private/Invoke-Request.ps1 @@ -10,7 +10,7 @@ function Invoke-Request { [string] $Controller, [parameter(Mandatory=$false)] - [ValidateSet("address","tag","subnet")] + [ValidateSet("address","tag","subnet","vlan","vrf","section")] [string] $Type, [parameter(Mandatory=$false)] From 4fc6bac4b55bc2290ee45eaa8a966c589937a596 Mon Sep 17 00:00:00 2001 From: Arnike Date: Mon, 5 Dec 2022 16:51:33 +0300 Subject: [PATCH 4/9] subnet type --- classlib/class/subnet.cs | 50 ++++++++++++++++++++++++---- classlib/enum/subcontrollers.cs | 11 +++++- functions/private/Invoke-Request.ps1 | 11 +++--- ps.ipam.psm1 | 2 ++ 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/classlib/class/subnet.cs b/classlib/class/subnet.cs index bc8d07d..809d00f 100644 --- a/classlib/class/subnet.cs +++ b/classlib/class/subnet.cs @@ -9,15 +9,28 @@ public class Subnetwork { public int SectionId { get; } public string Description { get; } public string LinkedSubnet { get; } - public int FirewallAddressObject { get; } + public string FirewallAddressObject { get; } public int VrfId { get; } public int MasterSubnetId { get; } public bool AllowRequests { get; } public int VlanId { get; } public bool ShowName { get; } - public int Device { get; } + public int DeviceId { get; } + public string Permissions { get; } public bool PingSubnet { get; } public bool DiscoverSubnet { get; } + public bool DNSRecursive { get; } + public bool DNSRecords { get; } + public int NameserverId { get; } + public bool ScanAgent { get; } + public bool IsFolder { get; } + public bool IsFull { get; } + public int TagId { get; } + public int Threshold { get; } + public int LocationId { get; } + public DateTime? EditDate { get; } + public DateTime? LastScan { get; } + public DateTime? LastDiscovery { get; } public bool ResolveDNS { get; } public Subnetwork( int id, @@ -26,16 +39,28 @@ public class Subnetwork { int sectionId, string description, string linkedSubnet, - int firewallAddressObject, + string firewallAddressObject, int vrfId, int masterSubnetId, - string permissions, bool allowRequests, int vlanId, bool showName, - int device, + int deviceId, + string permissions, bool pingSubnet, bool discoverSubnet, + bool dnsRecursive, + bool dnsRecords, + int nameserverId, + bool scanAgent, + bool isFolder, + bool isFull, + int tagId, + int threshold, + int locationId, + DateTime? editDate, + DateTime? lastScan, + DateTime? lastDiscovery, bool resolveDNS ) { this.Id = id; @@ -50,9 +75,22 @@ public class Subnetwork { this.AllowRequests = allowRequests; this.VlanId = vlanId; this.ShowName = showName; - this.Device = device; + this.DeviceId = deviceId; + this.Permissions = permissions; this.PingSubnet = pingSubnet; this.DiscoverSubnet = discoverSubnet; + this.DNSRecursive = dnsRecursive; + this.DNSRecords = dnsRecords; + this.NameserverId = nameserverId; + this.ScanAgent = scanAgent; + this.IsFolder = isFolder; + this.IsFull = isFull; + this.TagId = tagId; + this.Threshold = threshold; + this.LocationId = locationId; + this.EditDate = editDate; + this.LastScan = lastScan; + this.LastDiscovery = lastDiscovery; this.ResolveDNS = resolveDNS; } diff --git a/classlib/enum/subcontrollers.cs b/classlib/enum/subcontrollers.cs index 4565802..a674d67 100644 --- a/classlib/enum/subcontrollers.cs +++ b/classlib/enum/subcontrollers.cs @@ -3,5 +3,14 @@ using System; [Serializable] public enum subcontrollers { - nameservers + nameservers, + tags, + devices, + device_types, + vlans, + vrfs, + scanagents, + locations, + nat, + racks } \ No newline at end of file diff --git a/functions/private/Invoke-Request.ps1 b/functions/private/Invoke-Request.ps1 index 843242f..81640b2 100644 --- a/functions/private/Invoke-Request.ps1 +++ b/functions/private/Invoke-Request.ps1 @@ -2,8 +2,7 @@ function Invoke-Request { [CmdletBinding()] param ( [parameter(Mandatory=$true)] - [ValidateSet("POST","GET","PATCH","DELETE")] - [string] + [methods] $Method, [parameter(Mandatory=$true)] [ValidateSet("user","vlan","subnets","addresses","sections","vrf","l2domains","tools")] @@ -50,7 +49,7 @@ function Invoke-Request { Headers = $_headers } - if ($Method -match "POST|PATCH") { + if ($Method -eq [methods]::POST -or $Method -eq [methods]) { if ($Params -is [PSCustomObject]) { $_params = @{}; $Params | Get-Member -MemberType *Property | Where-Object { @@ -65,9 +64,9 @@ function Invoke-Request { if ($_response.code -match "20\d") { switch ($Type) { - "address" { $_response.data | ForEach-Object { New-Object -TypeName "PS.IPAM.Address" -ArgumentList $_.psobject.properties.value } } - "subnet" { $_response.data | ForEach-Object { New-Object -TypeName "PS.IPAM.Subnetwork" -ArgumentList $_.psobject.properties.value } } - "tag" { $_response.data | ForEach-Object { New-Object -TypeName "PS.IPAM.Tag" -ArgumentList $_.psobject.properties.value } } + "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 } } } else { diff --git a/ps.ipam.psm1 b/ps.ipam.psm1 index 89aad14..1b25c40 100644 --- a/ps.ipam.psm1 +++ b/ps.ipam.psm1 @@ -1,3 +1,5 @@ +using namespace ps.ipam + Get-ChildItem "$(Split-Path $script:MyInvocation.MyCommand.Path)\functions" -Filter "*.ps1" -Recurse | ForEach-Object { . $_.FullName } From a1b03b81c0ae44b55688aed42f61e1a182e7e920 Mon Sep 17 00:00:00 2001 From: Arnike Date: Mon, 5 Dec 2022 17:48:20 +0300 Subject: [PATCH 5/9] replaced hardcoded text by enums in some functions --- classlib/enum/types.cs | 12 ++++++++++++ functions/private/Invoke-Request.ps1 | 20 ++++++++------------ functions/public/Get-Address.ps1 | 18 +++++++++--------- functions/public/Get-Tag.ps1 | 16 ++++++++++------ 4 files changed, 39 insertions(+), 27 deletions(-) create mode 100644 classlib/enum/types.cs diff --git a/classlib/enum/types.cs b/classlib/enum/types.cs new file mode 100644 index 0000000..b438a03 --- /dev/null +++ b/classlib/enum/types.cs @@ -0,0 +1,12 @@ +namespace PS.IPAM; +using System; + +public enum types { + address, + domain, + section, + subnetwork, + tag, + vlan, + vrf +} \ No newline at end of file diff --git a/functions/private/Invoke-Request.ps1 b/functions/private/Invoke-Request.ps1 index 81640b2..1a7dff9 100644 --- a/functions/private/Invoke-Request.ps1 +++ b/functions/private/Invoke-Request.ps1 @@ -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)") diff --git a/functions/public/Get-Address.ps1 b/functions/public/Get-Address.ps1 index a3efc3c..6c4610c 100644 --- a/functions/public/Get-Address.ps1 +++ b/functions/public/Get-Address.ps1 @@ -1,6 +1,6 @@ function Get-Address { [CmdletBinding(DefaultParameterSetName="ByID")] - [OutputType('address')] + [OutputType({[types]::address})] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [ValidateScript({ $_ -match "^\d+$" })] @@ -35,29 +35,29 @@ function Get-Address { ) process { $_params = @{ - Controller = "addresses" - Method = "GET" - Type = "address" + Controller = [controllers]::addresses + Method = [methods]::GET + Type = [types]::address } switch ($PSCmdlet.ParameterSetName) { "ByID" { $_identifiers = @($id) } "ByIP" { $_identifiers = ("search",$IP) } "ByHostName" { $_identifiers = ("search_hostname",$HostName) } - "ByTag" { $_identifiers = ("tags",$TagId,"addresses") } + "ByTag" { $_identifiers = ("tags",$TagId,[controllers]::addresses) } "BySubnetId" { if ($IP) { $_identifiers = ($IP,$SubnetId) } else { - $_params.Item("Controller") = "subnets" - $_identifiers = ($SubnetId,"addresses") + $_params.Item("Controller") = [controllers]::subnets + $_identifiers = ($SubnetId,[controllers]::addresses) } } "BySubnetCIDR" { - $_params.Item("Controller") = "subnets" + $_params.Item("Controller") = [controllers]::subnets $_subnetId = (Get-Subnet -CIDR $SubnetCIDR).id if (!$_subnetId) { throw "Cannot find subnet!" } - $_identifiers = ($_subnetId,"addresses") + $_identifiers = ($_subnetId,[controllers]::addresses) } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Tag.ps1 b/functions/public/Get-Tag.ps1 index 02cec76..393bc4e 100644 --- a/functions/public/Get-Tag.ps1 +++ b/functions/public/Get-Tag.ps1 @@ -1,6 +1,6 @@ function Get-Tag { [CmdletBinding(DefaultParameterSetName="NoParams")] - [OutputType('tag')] + [OutputType({[types]::tag})] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [ValidateScript({ $_ -match "^\d+$" })] @@ -9,14 +9,18 @@ function Get-Tag { $Id, [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")] [ValidateNotNullOrEmpty()] - [ps.ipam.address] - $InputObject + [PS.IPAM.Address] + $AddressObject, + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")] + [ValidateNotNullOrEmpty()] + [PS.IPAM.Subnetwork] + $SubnetObject ) process { $_params = @{ - Controller = "addresses" - Method = "GET" - Type = "tag" + Controller = [controllers]::addresses + Method = [methods]::GET + Type = [types]::tag } $_identifiers = @("tags") switch ($PSCmdlet.ParameterSetName) { From 7d0d1b53ae3875658b3501d39ed71f3824f5a14e Mon Sep 17 00:00:00 2001 From: Arnike Date: Tue, 6 Dec 2022 17:20:45 +0300 Subject: [PATCH 6/9] first working types --- classlib/class/subnet.cs | 15 +++++++++--- classlib/class/tag.cs | 1 + classlib/class/vlan.cs | 15 ++++++++---- classlib/enum/methods.cs | 1 + classlib/enum/types.cs | 15 ++++++------ functions/private/Invoke-Request.ps1 | 30 ++++++++++++++++------- functions/public/Get-Address.ps1 | 18 +++++++------- functions/public/Get-FirstFreeIP.ps1 | 14 +++++++---- functions/public/Get-L2Domain.ps1 | 25 +++++++++++--------- functions/public/Get-Subnet.ps1 | 12 ++++------ functions/public/Get-Tag.ps1 | 22 +++++++++++------ functions/public/Get-Vlan.ps1 | 34 +++++++++++++++++---------- ps.ipam.psd1 | Bin 3336 -> 3352 bytes ps.ipam.psm1 | 2 -- 14 files changed, 129 insertions(+), 75 deletions(-) diff --git a/classlib/class/subnet.cs b/classlib/class/subnet.cs index 809d00f..45cdf2a 100644 --- a/classlib/class/subnet.cs +++ b/classlib/class/subnet.cs @@ -19,19 +19,22 @@ public class Subnetwork { public string Permissions { get; } public bool PingSubnet { get; } public bool DiscoverSubnet { get; } + public bool ResolveDNS { get; } public bool DNSRecursive { get; } public bool DNSRecords { get; } public int NameserverId { get; } public bool ScanAgent { get; } public bool IsFolder { get; } public bool IsFull { get; } + public bool IsPool { get; } public int TagId { get; } public int Threshold { get; } public int LocationId { get; } public DateTime? EditDate { get; } public DateTime? LastScan { get; } public DateTime? LastDiscovery { get; } - public bool ResolveDNS { get; } + public Object Calculation { get; } + public Object? ExtendedData { get; } public Subnetwork( int id, string subnet, @@ -49,19 +52,22 @@ public class Subnetwork { string permissions, bool pingSubnet, bool discoverSubnet, + bool resolveDNS, bool dnsRecursive, bool dnsRecords, int nameserverId, bool scanAgent, bool isFolder, bool isFull, + bool isPool, int tagId, int threshold, int locationId, DateTime? editDate, DateTime? lastScan, DateTime? lastDiscovery, - bool resolveDNS + Object calculation, + Object? custom_fields ) { this.Id = id; this.Subnet = subnet; @@ -79,19 +85,22 @@ public class Subnetwork { this.Permissions = permissions; this.PingSubnet = pingSubnet; this.DiscoverSubnet = discoverSubnet; + this.ResolveDNS = resolveDNS; this.DNSRecursive = dnsRecursive; this.DNSRecords = dnsRecords; this.NameserverId = nameserverId; this.ScanAgent = scanAgent; this.IsFolder = isFolder; this.IsFull = isFull; + this.IsPool = isPool; this.TagId = tagId; this.Threshold = threshold; this.LocationId = locationId; this.EditDate = editDate; this.LastScan = lastScan; this.LastDiscovery = lastDiscovery; - this.ResolveDNS = resolveDNS; + this.Calculation = calculation; + this.ExtendedData = custom_fields; } public string GetCIDR() { diff --git a/classlib/class/tag.cs b/classlib/class/tag.cs index 9030726..ddc94e5 100644 --- a/classlib/class/tag.cs +++ b/classlib/class/tag.cs @@ -1,4 +1,5 @@ namespace PS.IPAM; +using System; [Serializable] public class Tag { diff --git a/classlib/class/vlan.cs b/classlib/class/vlan.cs index 2e7cff1..77ddb50 100644 --- a/classlib/class/vlan.cs +++ b/classlib/class/vlan.cs @@ -1,28 +1,35 @@ namespace PS.IPAM; using System; +using System.Dynamic; [Serializable] -public class Vlan { +public class Vlan : DynamicObject { public int Id { get; } public int DomainId { get; } public string Name { get; } public int Number { get; } public string Description { get; } public DateTime? EditDate { get; } + public int CustomerId { get; } + public Object? ExtendedData { get; } public Vlan ( - int id, + int vlanId, int domainId, string name, int number, string description, - DateTime? editDate + DateTime? editDate, + int customer_id, + Object? custom_fields ) { - this.Id = id; + this.Id = vlanId; this.DomainId = domainId; this.Name = name; this.Number = number; this.Description = description; this.EditDate = editDate; + this.CustomerId = customer_id; + this.ExtendedData = custom_fields; } public override string ToString() diff --git a/classlib/enum/methods.cs b/classlib/enum/methods.cs index 4cdee6b..49c8f68 100644 --- a/classlib/enum/methods.cs +++ b/classlib/enum/methods.cs @@ -1,6 +1,7 @@ namespace PS.IPAM; using System; +[Serializable] public enum methods { GET, POST, diff --git a/classlib/enum/types.cs b/classlib/enum/types.cs index b438a03..1dfaba1 100644 --- a/classlib/enum/types.cs +++ b/classlib/enum/types.cs @@ -1,12 +1,13 @@ namespace PS.IPAM; using System; +[Serializable] public enum types { - address, - domain, - section, - subnetwork, - tag, - vlan, - vrf + Address, + Domain, + Section, + Subnetwork, + Tag, + Vlan, + Vrf } \ No newline at end of file diff --git a/functions/private/Invoke-Request.ps1 b/functions/private/Invoke-Request.ps1 index 1a7dff9..926ad8a 100644 --- a/functions/private/Invoke-Request.ps1 +++ b/functions/private/Invoke-Request.ps1 @@ -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)") diff --git a/functions/public/Get-Address.ps1 b/functions/public/Get-Address.ps1 index 6c4610c..69f9bbe 100644 --- a/functions/public/Get-Address.ps1 +++ b/functions/public/Get-Address.ps1 @@ -1,6 +1,6 @@ function Get-Address { [CmdletBinding(DefaultParameterSetName="ByID")] - [OutputType({[types]::address})] + [OutputType([PS.IPAM.address])] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [ValidateScript({ $_ -match "^\d+$" })] @@ -35,29 +35,29 @@ function Get-Address { ) process { $_params = @{ - Controller = [controllers]::addresses - Method = [methods]::GET - Type = [types]::address + Controller = [PS.IPAM.controllers]::addresses + Method = [PS.IPAM.methods]::GET + Type = [PS.IPAM.types]::address } switch ($PSCmdlet.ParameterSetName) { "ByID" { $_identifiers = @($id) } "ByIP" { $_identifiers = ("search",$IP) } "ByHostName" { $_identifiers = ("search_hostname",$HostName) } - "ByTag" { $_identifiers = ("tags",$TagId,[controllers]::addresses) } + "ByTag" { $_identifiers = ("tags",$TagId,[PS.IPAM.controllers]::addresses) } "BySubnetId" { if ($IP) { $_identifiers = ($IP,$SubnetId) } else { - $_params.Item("Controller") = [controllers]::subnets - $_identifiers = ($SubnetId,[controllers]::addresses) + $_params.Item("Controller") = [PS.IPAM.controllers]::subnets + $_identifiers = ($SubnetId,[PS.IPAM.controllers]::addresses) } } "BySubnetCIDR" { - $_params.Item("Controller") = [controllers]::subnets + $_params.Item("Controller") = [PS.IPAM.controllers]::subnets $_subnetId = (Get-Subnet -CIDR $SubnetCIDR).id if (!$_subnetId) { throw "Cannot find subnet!" } - $_identifiers = ($_subnetId,[controllers]::addresses) + $_identifiers = ($_subnetId,[PS.IPAM.controllers]::addresses) } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-FirstFreeIP.ps1 b/functions/public/Get-FirstFreeIP.ps1 index c5702d8..c661ae8 100644 --- a/functions/public/Get-FirstFreeIP.ps1 +++ b/functions/public/Get-FirstFreeIP.ps1 @@ -10,19 +10,25 @@ function Get-FirstFreeIP { [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] [string] - $Id + $Id, + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")] + [ValidateNotNullOrEmpty()] + [PS.IPAM.Subnetwork] + $SubnetObject ) process { $_params = @{ - Controller = "subnets" - Method = "GET" + Controller = [PS.IPAM.controllers]::subnets + Method = [PS.IPAM.methods]::GET } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_subnetId = $Id } + "ByID" { $_subnetId = $Id; break } "ByCIDR" { $_subnetId = (Get-Subnet -CIDR $CIDR).id if (!$_subnetId) { throw "Cannot find subnet!" } + break } + "BySubnetObject" { $_subnetId = $SubnetObject.Id; break } } $_identifiers = @($_subnetId,"first_free") $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-L2Domain.ps1 b/functions/public/Get-L2Domain.ps1 index d61bf48..45bfc3b 100644 --- a/functions/public/Get-L2Domain.ps1 +++ b/functions/public/Get-L2Domain.ps1 @@ -1,26 +1,29 @@ function Get-L2Domain { - [CmdletBinding(DefaultParameterSetName="ByID")] + [CmdletBinding(DefaultParameterSetName="NoParams")] + [OutputType([PS.IPAM.Domain])] param ( - [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id ) process { - [string[]]$visiblePropertiesList = @('Id','Name','Description') - $visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList) - $_params = @{ - Controller = "l2domains" - Method = "GET" + Controller = [PS.IPAM.controllers]::l2domains + Method = [PS.IPAM.methods]::GET + Type = [PS.IPAM.types]::Domain } - $_identifiers = @($Id) + switch ($PSCmdlet.ParameterSetName) { + "ByID" { + $_identifiers = @($Id) + } + } + $_params.Add("Identifiers",$_identifiers) - Invoke-Request @_params | ` - Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru + Invoke-Request @_params } } Export-ModuleMember -Function Get-L2Domain \ No newline at end of file diff --git a/functions/public/Get-Subnet.ps1 b/functions/public/Get-Subnet.ps1 index 205a749..db4f155 100644 --- a/functions/public/Get-Subnet.ps1 +++ b/functions/public/Get-Subnet.ps1 @@ -1,5 +1,6 @@ function Get-Subnet { - [CmdletBinding(DefaultParameterSetName="ByID")] + [CmdletBinding(DefaultParameterSetName="NoParams")] + [OutputType([PS.IPAM.Subnetwork])] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")] [ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})] @@ -52,13 +53,10 @@ function Get-Subnet { $Recurse ) process { - [string[]]$visiblePropertiesList = @('Id','Subnet','Mask','Description') - $visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList) - $_params = @{ - Controller = "subnets" - Method = "GET" - Type = "subnet" + Controller = [PS.IPAM.controllers]::subnets + Method = [PS.IPAM.methods]::GET + Type = [PS.IPAM.types]::Subnetwork } switch ($PSCmdlet.ParameterSetName) { "ByCIDR" { diff --git a/functions/public/Get-Tag.ps1 b/functions/public/Get-Tag.ps1 index 393bc4e..9936ce7 100644 --- a/functions/public/Get-Tag.ps1 +++ b/functions/public/Get-Tag.ps1 @@ -1,6 +1,6 @@ function Get-Tag { [CmdletBinding(DefaultParameterSetName="NoParams")] - [OutputType({[types]::tag})] + [OutputType([PS.IPAM.Tag])] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [ValidateScript({ $_ -match "^\d+$" })] @@ -18,16 +18,24 @@ function Get-Tag { ) process { $_params = @{ - Controller = [controllers]::addresses - Method = [methods]::GET - Type = [types]::tag + Controller = [PS.IPAM.controllers]::addresses + Method = [PS.IPAM.methods]::GET + Type = [PS.IPAM.types]::tag } $_identifiers = @("tags") switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers += $Id } + "ByID" { $_identifiers += $Id; break } "ByAddressObject" { - if ($InputObject.TagId) { - $_identifiers += $InputObject.TagId + if ($AddressObject.TagId) { + $_identifiers += $AddressObject.TagId + } else { + return $null + } + break + } + "BySubnetObject" { + if ($SubnetObject.TagId) { + $_identifiers += $SubnetObject.TagId } else { return $null } diff --git a/functions/public/Get-Vlan.ps1 b/functions/public/Get-Vlan.ps1 index 10565a0..55e8d07 100644 --- a/functions/public/Get-Vlan.ps1 +++ b/functions/public/Get-Vlan.ps1 @@ -1,5 +1,6 @@ function Get-Vlan { [CmdletBinding(DefaultParameterSetName="ByID")] + [OutputType([PS.IPAM.Vlan])] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [ValidateScript({ $_ -match "^\d+$" })] @@ -15,31 +16,40 @@ function Get-Vlan { [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] [string] - $L2DomainId + $L2DomainId, + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")] + [ValidateNotNullOrEmpty()] + [PS.IPAM.Subnetwork] + $SubnetObject ) process { - [string[]]$visiblePropertiesList = @('Id','Name','Description') - $visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList) - $_params = @{ - Controller = "vlan" - Method = "GET" + Controller = [PS.IPAM.controllers]::vlan + Method = [PS.IPAM.methods]::GET + Type = [PS.IPAM.types]::Vlan } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($Id) } - "ByNumber" { $_identifiers = @("search",$Number) } + "ByID" { $_identifiers = @($Id); break } + "ByNumber" { $_identifiers = @("search",$Number); break } "ByL2Domain"{ - $_params.Item("Controller") = "l2domains" + $_params.Item("Controller") = [PS.IPAM.controllers]::l2domains $_l2domainId = $L2DomainId - $_identifiers = @($_l2domainId,"vlans") + $_identifiers = @($_l2domainId,[PS.IPAM.subcontrollers]::vlans) + break + } + "BySubnetObject" { + if ($SubnetObject.VlanId) { + $_identifiers = @($SubnetObject.VlanId); break + } else { + return $null + } } } $_params.Add("Identifiers",$_identifiers) - Invoke-Request @_params | Select-Object @{n="id";e={$_.vlanId}},* | Select-Object -ExcludeProperty vlanId | ` - Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru + Invoke-Request @_params } } Export-ModuleMember -Function Get-Vlan \ No newline at end of file diff --git a/ps.ipam.psd1 b/ps.ipam.psd1 index a08729afadeaf464337b2063dc92f40edfd0d691..456cb9fd0f96d623b4003ac0b0bc7e0ff3498115 100644 GIT binary patch delta 26 hcmeB>njy7e9y4zNLn%WNLk>eGLoq|f=Gn}-oB(L(2XO!Z delta 12 TcmbOs)giTE9`ojP%vqcOAB6;c diff --git a/ps.ipam.psm1 b/ps.ipam.psm1 index 1b25c40..89aad14 100644 --- a/ps.ipam.psm1 +++ b/ps.ipam.psm1 @@ -1,5 +1,3 @@ -using namespace ps.ipam - Get-ChildItem "$(Split-Path $script:MyInvocation.MyCommand.Path)\functions" -Filter "*.ps1" -Recurse | ForEach-Object { . $_.FullName } From 5a34f037796522ed3a469817a8a4ca35cdf26577 Mon Sep 17 00:00:00 2001 From: Arnike Date: Mon, 12 Dec 2022 13:08:04 +0300 Subject: [PATCH 7/9] Fixes, added session class --- classlib/class/address.cs | 5 +- classlib/class/section.cs | 3 + classlib/class/session.cs | 32 +++++++ classlib/class/vrf.cs | 5 +- classlib/enum/authType.cs | 8 ++ classlib/enum/methods.cs | 10 --- functions/private/Invoke-Request.ps1 | 38 +++++--- functions/private/Test-Session.ps1 | 6 +- functions/private/Update-Session.ps1 | 6 +- functions/public/Get-Address.ps1 | 14 ++- functions/public/Get-FirstFreeIP.ps1 | 5 +- functions/public/Get-L2Domain.ps1 | 12 +-- functions/public/Get-Nameserver.ps1 | 3 +- functions/public/Get-Section.ps1 | 15 ++-- functions/public/Get-Subnet.ps1 | 22 ++--- functions/public/Get-Tag.ps1 | 5 +- functions/public/Get-Vlan.ps1 | 20 +++-- functions/public/Get-Vrf.ps1 | 15 ++-- functions/public/New-Address.ps1 | 14 ++- functions/public/New-Session.ps1 | 33 ++++--- functions/public/Remove-Address.ps1 | 21 ++--- functions/public/Set-Address.ps1 | 126 +++++++-------------------- 22 files changed, 193 insertions(+), 225 deletions(-) create mode 100644 classlib/class/session.cs create mode 100644 classlib/enum/authType.cs delete mode 100644 classlib/enum/methods.cs diff --git a/classlib/class/address.cs b/classlib/class/address.cs index 2546695..1d15998 100644 --- a/classlib/class/address.cs +++ b/classlib/class/address.cs @@ -23,6 +23,7 @@ public class Address { public string FirewallAddressObject { get; } public DateTime? EditDate { get; } public int CustomerId { get; } + public Object? ExtendedData { get; } public Address( int id, @@ -44,7 +45,8 @@ public class Address { int PTR, string firewallAddressObject, DateTime? editDate, - int customer_id + int customer_id, + Object? extendedData ) { this.Id = id; this.SubnetId = subnetId; @@ -66,6 +68,7 @@ public class Address { this.FirewallAddressObject = firewallAddressObject; this.EditDate = editDate; this.CustomerId = customer_id; + this.ExtendedData = extendedData; } public override string ToString() { diff --git a/classlib/class/section.cs b/classlib/class/section.cs index 8f33f8b..c8589a7 100644 --- a/classlib/class/section.cs +++ b/classlib/class/section.cs @@ -12,6 +12,7 @@ public class Section { public string SubnetOrdering { get; } public int Order { get; } public DateTime? EditDate { get; } + public bool ShowSubnet { get; } public bool ShowVlan { get; } public bool ShowVRF { get; } public bool ShowSupernetOnly { get; } @@ -27,6 +28,7 @@ public class Section { string subnetOrdering, int order, DateTime? editDate, + bool showSubnet, bool showVlan, bool showVRF, bool showSupernetOnly, @@ -41,6 +43,7 @@ public class Section { this.SubnetOrdering = subnetOrdering; this.Order = order; this.EditDate = editDate; + this.ShowSubnet = showSubnet; this.ShowVlan = showVlan; this.ShowVRF = showVRF; this.ShowSupernetOnly = showSupernetOnly; diff --git a/classlib/class/session.cs b/classlib/class/session.cs new file mode 100644 index 0000000..774d011 --- /dev/null +++ b/classlib/class/session.cs @@ -0,0 +1,32 @@ +namespace PS.IPAM; +using System; + +[Serializable] +public class Session { + public AuthType AuthType { get; } + public string Token { get; } + public string AppID { get; } + public string URL { get; } + public DateTime? Expires { get; } + public Object? Credentials { get; } + public Session( + AuthType authType, + string token, + string appId, + string url, + DateTime? expires, + Object? credentials + ) { + AuthType = authType; + Token = token; + AppID = appId; + URL = url; + Expires = expires; + Credentials = credentials; + } + + public override string ToString() + { + return base.ToString(); + } +} \ No newline at end of file diff --git a/classlib/class/vrf.cs b/classlib/class/vrf.cs index 39654c3..92c2af9 100644 --- a/classlib/class/vrf.cs +++ b/classlib/class/vrf.cs @@ -9,6 +9,7 @@ public class Vrf { public string Description { get; } public string Sections { get; } public DateTime? EditDate { get; } + public Object? ExtendedData { get; } public Vrf( int id, @@ -16,7 +17,8 @@ public class Vrf { string rd, string description, string sections, - DateTime? editDate + DateTime? editDate, + Object? custom_fields ) { this.Id = id; this.Name = name; @@ -24,6 +26,7 @@ public class Vrf { this.Description = description; this.Sections = sections; this.EditDate = editDate; + this.ExtendedData = custom_fields; } public override string ToString() { diff --git a/classlib/enum/authType.cs b/classlib/enum/authType.cs new file mode 100644 index 0000000..bb513c6 --- /dev/null +++ b/classlib/enum/authType.cs @@ -0,0 +1,8 @@ +namespace PS.IPAM; +using System; + +[Serializable] +public enum AuthType { + credentials, + token +} \ No newline at end of file diff --git a/classlib/enum/methods.cs b/classlib/enum/methods.cs deleted file mode 100644 index 49c8f68..0000000 --- a/classlib/enum/methods.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace PS.IPAM; -using System; - -[Serializable] -public enum methods { - GET, - POST, - PATCH, - DELETE -} \ No newline at end of file diff --git a/functions/private/Invoke-Request.ps1 b/functions/private/Invoke-Request.ps1 index 926ad8a..2a81e66 100644 --- a/functions/private/Invoke-Request.ps1 +++ b/functions/private/Invoke-Request.ps1 @@ -2,7 +2,8 @@ function Invoke-Request { [CmdletBinding()] param ( [parameter(Mandatory=$true)] - [PS.IPAM.methods] + [ValidateSet("GET","POST","PATCH","DELETE")] + [string] $Method, [parameter(Mandatory=$true)] [PS.IPAM.controllers] @@ -27,7 +28,7 @@ function Invoke-Request { $Controller = $Controller - $_uri = "$($script:ipamURL)/api/$($script:ipamAppID)/$Controller" + $_uri = "$($script:psipamSession.URL)/api/$($script:psipamSession.AppID)/$Controller" if ($SubController) { $_uri += "/$SubController" } if ($Identifiers) { $_uri += "/$($Identifiers -join '/')/" } @@ -35,9 +36,9 @@ function Invoke-Request { "Accept" = "application/json" "Content-Type" = "application/json" } - switch ($script:ipamAuthType) { - "Credentials" { $_headers.Add("token", $script:ipamToken) } - "Token" { $_headers.Add("phpipam-token", $script:ipamToken) } + switch ($script:psipamSession.AuthType) { + "Credentials" { $_headers.Add("token", $script:psipamSession.Token) } + "Token" { $_headers.Add("phpipam-token", $script:psipamSession.Token) } } $_arguments = @{ @@ -46,7 +47,7 @@ function Invoke-Request { Headers = $_headers } - if ($Method -eq [PS.IPAM.methods]::POST -or $Method -eq [PS.IPAM.methods]::PATCH) { + if ($Method -eq "POST" -or $Method -eq "PATCH") { if ($Params -is [PSCustomObject]) { $_params = @{}; $Params | Get-Member -MemberType *Property | Where-Object { @@ -57,23 +58,40 @@ function Invoke-Request { $_arguments.Add("Body",($_params | ConvertTo-Json)) } - $_response = Invoke-RestMethod @_arguments + Write-Verbose -Message "Invoking web request to $($_uri), with method $($_arguments.Method), headers: $($_arguments.Headers)" + $_response = Invoke-RestMethod @_arguments + if ($_response.code -match "20\d") { if ($Type -is [PS.IPAM.types]) { switch ($Type) { - "vlan" { + "address" { + $_paramList = @("id","subnetId","ip","is_gateway","description","hostname","mac","owner","tag","deviceId","location","port","note","lastSeen","excludePing","PTRignore","PTR","firewallAddressObject","editDate","customer_id") + $_response.data | ForEach-Object { - New-Object -TypeName ([PS.IPAM.Vlan]) -ArgumentList (@($_.psobject.properties.value[0..6]) + ($_ | Select-Object -Property custom_* -ExcludeProperty custom_*)) + New-Object -TypeName ([PS.IPAM.Address]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*')) + }; break + } + "vlan" { + $_paramList = @("vlanId","domainId","name","number","description","editDate","customer_id","custom_fields") + + $_response.data | ForEach-Object { + New-Object -TypeName ([PS.IPAM.Vlan]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | 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_*)) + New-Object -TypeName ([PS.IPAM.Subnetwork]) -ArgumentList (@($_.psobject.properties.value[0..30]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*')) + }; break + } + "vrf" { + $_response.data | ForEach-Object { + New-Object -TypeName ([PS.IPAM.Vrf]) -ArgumentList (@($_.psobject.properties.value[0..5]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*')) }; break } Default { $_response.data | ForEach-Object { New-Object -TypeName ("PS.IPAM.$Type") -ArgumentList $_.psobject.properties.value } } } + } else { return $_response.data } diff --git a/functions/private/Test-Session.ps1 b/functions/private/Test-Session.ps1 index a1ab7c8..1558a55 100644 --- a/functions/private/Test-Session.ps1 +++ b/functions/private/Test-Session.ps1 @@ -3,11 +3,11 @@ function Test-Session { param ( ) - if ($script:ipamToken) { - if ($script:ipamExpires -eq "Never") { + if ($script:psipamSession) { + if ($null -eq $script:psipamSession.Expires) { return "Valid" } else { - if ($script:ipamExpires -lt (Get-Date)) { + if ($script:psipamSession.Expires -lt (Get-Date)) { return "Expired" } else { return "Valid" diff --git a/functions/private/Update-Session.ps1 b/functions/private/Update-Session.ps1 index e583084..245e35b 100644 --- a/functions/private/Update-Session.ps1 +++ b/functions/private/Update-Session.ps1 @@ -9,10 +9,10 @@ function Update-Session { throw "No session available!" } if ($_tokenStatus -eq "Valid") { - return (Invoke-Request -Method PATCH -Controller user).expires + return (Invoke-Request -Method [ps.ipam.methods]::PATCH -Controller [ps.ipam.controllers]::user).expires } if ($_tokenStatus -eq "Expired" -or $Force) { - New-Session -URL $script:ipamURL -AppID $script:ipamAppID -Credentials $script:ipamCredentials - return $script:ipamExpires + New-Session -URL $script:psipamSession.URL -AppID $script:psipamSession.AppID -Credentials $script:psipamSession.Credentials + return } } \ No newline at end of file diff --git a/functions/public/Get-Address.ps1 b/functions/public/Get-Address.ps1 index 69f9bbe..57c32cf 100644 --- a/functions/public/Get-Address.ps1 +++ b/functions/public/Get-Address.ps1 @@ -3,29 +3,25 @@ function Get-Address { [OutputType([PS.IPAM.address])] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByIP")] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="BySubnetId")] - [ValidateScript({[ipaddress] $_})] [ValidateNotNullOrEmpty()] - [string] + [ipaddress] $IP, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByHostName")] [ValidateNotNullOrEmpty()] [string] $HostName, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByTag")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $TagId, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetId")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $SubnetId, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetCIDR")] [ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})] @@ -36,7 +32,7 @@ function Get-Address { process { $_params = @{ Controller = [PS.IPAM.controllers]::addresses - Method = [PS.IPAM.methods]::GET + Method = "GET" Type = [PS.IPAM.types]::address } switch ($PSCmdlet.ParameterSetName) { diff --git a/functions/public/Get-FirstFreeIP.ps1 b/functions/public/Get-FirstFreeIP.ps1 index c661ae8..daba78f 100644 --- a/functions/public/Get-FirstFreeIP.ps1 +++ b/functions/public/Get-FirstFreeIP.ps1 @@ -7,9 +7,8 @@ function Get-FirstFreeIP { [string] $CIDR, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id, [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")] [ValidateNotNullOrEmpty()] @@ -19,7 +18,7 @@ function Get-FirstFreeIP { process { $_params = @{ Controller = [PS.IPAM.controllers]::subnets - Method = [PS.IPAM.methods]::GET + Method = "GET" } switch ($PSCmdlet.ParameterSetName) { "ByID" { $_subnetId = $Id; break } diff --git a/functions/public/Get-L2Domain.ps1 b/functions/public/Get-L2Domain.ps1 index 45bfc3b..d97694b 100644 --- a/functions/public/Get-L2Domain.ps1 +++ b/functions/public/Get-L2Domain.ps1 @@ -1,9 +1,8 @@ function Get-L2Domain { - [CmdletBinding(DefaultParameterSetName="NoParams")] + [CmdletBinding(DefaultParameterSetName="ByID")] [OutputType([PS.IPAM.Domain])] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] [int] $Id @@ -11,16 +10,11 @@ function Get-L2Domain { process { $_params = @{ Controller = [PS.IPAM.controllers]::l2domains - Method = [PS.IPAM.methods]::GET + Method = "GET" Type = [PS.IPAM.types]::Domain } - switch ($PSCmdlet.ParameterSetName) { - "ByID" { - $_identifiers = @($Id) - } - } - + $_identifiers = @($Id) $_params.Add("Identifiers",$_identifiers) Invoke-Request @_params diff --git a/functions/public/Get-Nameserver.ps1 b/functions/public/Get-Nameserver.ps1 index f487108..6e798fa 100644 --- a/functions/public/Get-Nameserver.ps1 +++ b/functions/public/Get-Nameserver.ps1 @@ -2,9 +2,8 @@ function Get-Nameserver { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id ) process { diff --git a/functions/public/Get-Section.ps1 b/functions/public/Get-Section.ps1 index 30caca2..f866064 100644 --- a/functions/public/Get-Section.ps1 +++ b/functions/public/Get-Section.ps1 @@ -1,10 +1,10 @@ function Get-Section { - [CmdletBinding(DefaultParameterSetName="ByID")] + [CmdletBinding(DefaultParameterSetName="NoParams")] + [OutputType([PS.IPAM.Section])] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id, [parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByName")] [ValidateNotNullOrEmpty()] @@ -12,12 +12,10 @@ function Get-Section { $Name ) process { - [string[]]$visiblePropertiesList = @('Id','Name','Description') - $visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList) - $_params = @{ - Controller = "sections" + Controller = [PS.IPAM.controllers]::sections Method = "GET" + Type = [PS.IPAM.types]::Section } switch ($PSCmdlet.ParameterSetName) { "ByID" { $_identifiers = @($Id) } @@ -25,8 +23,7 @@ function Get-Section { } $_params.Add("Identifiers",$_identifiers) - Invoke-Request @_params | ` - Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru + Invoke-Request @_params } } Export-ModuleMember Get-Section \ No newline at end of file diff --git a/functions/public/Get-Subnet.ps1 b/functions/public/Get-Subnet.ps1 index db4f155..71cbdb8 100644 --- a/functions/public/Get-Subnet.ps1 +++ b/functions/public/Get-Subnet.ps1 @@ -8,16 +8,14 @@ function Get-Subnet { [string] $CIDR, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionId")] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="ByVlanNumber")] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanId")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $SectionId, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionName")] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=3,ParameterSetName="ByVlanNumber")] @@ -26,25 +24,21 @@ function Get-Subnet { [string] $SectionName, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVrfId")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $VrfId, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanId")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $VlanId, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanNumber")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $VlanNumber, [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanNumber")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] - $VlanDomain, + [int] + $VlanDomainId, [parameter(Mandatory=$false,ParameterSetName="ByID")] [switch] $Slaves, @@ -55,7 +49,7 @@ function Get-Subnet { process { $_params = @{ Controller = [PS.IPAM.controllers]::subnets - Method = [PS.IPAM.methods]::GET + Method = "GET" Type = [PS.IPAM.types]::Subnetwork } switch ($PSCmdlet.ParameterSetName) { diff --git a/functions/public/Get-Tag.ps1 b/functions/public/Get-Tag.ps1 index 9936ce7..606131c 100644 --- a/functions/public/Get-Tag.ps1 +++ b/functions/public/Get-Tag.ps1 @@ -3,9 +3,8 @@ function Get-Tag { [OutputType([PS.IPAM.Tag])] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id, [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")] [ValidateNotNullOrEmpty()] @@ -19,7 +18,7 @@ function Get-Tag { process { $_params = @{ Controller = [PS.IPAM.controllers]::addresses - Method = [PS.IPAM.methods]::GET + Method = "GET" Type = [PS.IPAM.types]::tag } $_identifiers = @("tags") diff --git a/functions/public/Get-Vlan.ps1 b/functions/public/Get-Vlan.ps1 index 55e8d07..a6aa22f 100644 --- a/functions/public/Get-Vlan.ps1 +++ b/functions/public/Get-Vlan.ps1 @@ -3,29 +3,30 @@ function Get-Vlan { [OutputType([PS.IPAM.Vlan])] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByNumber")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Number, [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByL2Domain")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $L2DomainId, [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")] [ValidateNotNullOrEmpty()] [PS.IPAM.Subnetwork] - $SubnetObject + $SubnetObject, + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByDomainObject")] + [ValidateNotNullOrEmpty()] + [PS.IPAM.Domain] + $DomainObject ) process { $_params = @{ Controller = [PS.IPAM.controllers]::vlan - Method = [PS.IPAM.methods]::GET + Method = "GET" Type = [PS.IPAM.types]::Vlan } switch ($PSCmdlet.ParameterSetName) { @@ -46,6 +47,9 @@ function Get-Vlan { return $null } } + "DomainObject" { + Get-Vlan -L2DomainId $DomainObject.Id + } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Vrf.ps1 b/functions/public/Get-Vrf.ps1 index 7ab658b..9ff2c78 100644 --- a/functions/public/Get-Vrf.ps1 +++ b/functions/public/Get-Vrf.ps1 @@ -1,26 +1,23 @@ function Get-Vrf { [CmdletBinding(DefaultParameterSetName="ByID")] + [OutputType([PS.IPAM.Vrf])] param ( [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id ) process { - [string[]]$visiblePropertiesList = @('Id','Name','Description') - $visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList) - $_params = @{ - Controller = "vrf" + Controller = [PS.IPAM.controllers]::vrf Method = "GET" + Type = [PS.IPAM.types]::vrf } if ($Id) { $_identifiers = @($Id) } - $_params.Add("Identifiers",$_identifiers) + $_params.Add("Identifiers",$_identifiers) - Invoke-Request @_params | Select-Object @{n="id";e={$_.vrfId}},* | Select-Object -ExcludeProperty vrfId | ` - Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru + Invoke-Request @_params } } Export-ModuleMember -Function Get-Vrf \ No newline at end of file diff --git a/functions/public/New-Address.ps1 b/functions/public/New-Address.ps1 index b805b86..36069af 100644 --- a/functions/public/New-Address.ps1 +++ b/functions/public/New-Address.ps1 @@ -7,9 +7,8 @@ function New-Address { ValueFromPipelineByPropertyName=$true, HelpMessage="Id of subnet address belongs to", Position=0)] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $SubnetId, [parameter( Mandatory=$true, @@ -72,9 +71,8 @@ function New-Address { ValueFromPipelineByPropertyName=$true, HelpMessage="Id of subnet address belongs to", Position=7)] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $TagId, [parameter( Mandatory=$false, @@ -90,9 +88,8 @@ function New-Address { ValueFromPipelineByPropertyName=$true, HelpMessage="Id of PowerDNS PTR record", Position=7)] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $PTRId, [parameter( Mandatory=$false, @@ -117,9 +114,8 @@ function New-Address { ValueFromPipelineByPropertyName=$true, HelpMessage="Id of device address belongs to", Position=12)] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $DeviceId, [parameter( Mandatory=$false, @@ -137,7 +133,7 @@ function New-Address { ) process { $_params = @{ - Controller = "addresses" + Controller = [PS.IPAM.controllers]::addresses Method = "POST" } diff --git a/functions/public/New-Session.ps1 b/functions/public/New-Session.ps1 index 1757310..73fb82b 100644 --- a/functions/public/New-Session.ps1 +++ b/functions/public/New-Session.ps1 @@ -29,25 +29,30 @@ function New-Session { "Authorization" = "Basic $_auth" } - $_response = Invoke-RestMethod -Method Post -Uri $_uri -Headers $_headers -ErrorAction SilentlyContinue + $_response = Invoke-RestMethod -Method POST -Uri $_uri -Headers $_headers if ($_response.success -ne $true) { return $_response.error } - $script:ipamAuthType = "Credentials" - $script:ipamAuth = $true - $script:ipamToken = $_response.data.token - $script:ipamAppID = $AppID - $script:ipamURL = $URL - $script:ipamCredentials = $Credentials - $script:ipamExpires = Get-Date $_response.data.expires + $script:psipamSession = [PS.IPAM.Session]::new( + [ps.ipam.authType]::credentials, + $_response.data.token, + $AppID, + $URL, + (Get-Date $_response.data.expires), + $Credentials + ) + break } "Token" { - $script:ipamAuthType = "Token" - $script:ipamAuth = $true - $script:ipamToken = $Token - $script:ipamAppID = $AppID - $script:ipamURL = $URL - $script:ipamExpires = "Never" + $script:psipamSession = [PS.IPAM.Session]::new( + [ps.ipam.authType]::token, + $Token, + $AppID, + $URL, + $null, + $null + ) + break } } } diff --git a/functions/public/Remove-Address.ps1 b/functions/public/Remove-Address.ps1 index fba0892..536d14d 100644 --- a/functions/public/Remove-Address.ps1 +++ b/functions/public/Remove-Address.ps1 @@ -2,30 +2,23 @@ function Remove-Address { [CmdletBinding(DefaultParameterSetName="ByID")] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")] - [ValidateScript({ $_ -match "^\d+$" })] [ValidateNotNullOrEmpty()] - [string] + [int] $Id, - [parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByIP")] - [ValidateScript({[ipaddress] $_ })] + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")] [ValidateNotNullOrEmpty()] - [string] - $IP, - [parameter(Mandatory=$true,ValueFromPipeline=$true,Position=1,ParameterSetName="ByIP")] - [ValidateScript({ $_ -match "^\d+$" })] - [ValidateNotNullOrEmpty()] - [string] - $SubnetId + [PS.IPAM.Address] + $AddressObject ) process { $_params = @{ - Controller = "addresses" + Controller = [PS.IPAM.controllers]::addresses Method = "DELETE" } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($Id) } - "ByIP" { $_identifiers = @($IP,$SubnetId) } + "ByID" { $_identifiers = @($Id);break } + "ByAddressObject" { $_identifiers = @($AddressObject.Id);break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Set-Address.ps1 b/functions/public/Set-Address.ps1 index a9c0693..934de3d 100644 --- a/functions/public/Set-Address.ps1 +++ b/functions/public/Set-Address.ps1 @@ -1,127 +1,61 @@ function Set-Address { - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName="ById")] param ( - [parameter( - Mandatory=$true, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Id of subnet address belongs to", - Position=0)] - [ValidateScript({ $_ -match "^\d+$" })] + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Id of subnet address belongs to",Position=0,ParameterSetName="ById")] [ValidateNotNullOrEmpty()] - [string] + [int] $Id, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Defines if address is presented as gateway", - Position=1)] + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")] + [ValidateNotNullOrEmpty()] + [PS.IPAM.Address] + $AddressObject, + [parameter(Mandatory=$false,HelpMessage="Defines if address is presented as gateway",Position=1)] [bool] $Gateway, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Address description", - Position=2)] + [parameter(Mandatory=$false,HelpMessage="Address description",Position=2)] [ValidateNotNullOrEmpty()] [string] $Description, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Address hostname", - Position=3)] + [parameter(Mandatory=$false,HelpMessage="Address hostname",Position=3)] [ValidateNotNullOrEmpty()] [string] $Hostname, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Mac address", - Position=4)] + [parameter(Mandatory=$false,HelpMessage="Mac address",Position=4)] [ValidateScript({ $_.Replace(":","") -match "^$('([A-F0-9]{2})' * 6)$" })] [ValidateNotNullOrEmpty()] [string] $MAC, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Address owner", - Position=5)] + [parameter(Mandatory=$false,HelpMessage="Address owner",Position=5)] [ValidateNotNullOrEmpty()] [string] $Owner, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Id of subnet address belongs to", - Position=6)] - [ValidateScript({ $_ -match "^\d+$" })] + [parameter(Mandatory=$false,HelpMessage="Id of subnet address belongs to",Position=6)] [ValidateNotNullOrEmpty()] - [string] + [int] $TagId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls if PTR should not be created", - Position=7)] + [parameter(Mandatory=$false,HelpMessage="Controls if PTR should not be created",Position=7)] [bool] $PTRIgnore, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Id of PowerDNS PTR record", - Position=8)] - [ValidateScript({ $_ -match "^\d+$" })] + [parameter(Mandatory=$false,HelpMessage="Id of PowerDNS PTR record",Position=8)] [ValidateNotNullOrEmpty()] - [string] + [int] $PTRId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Note", - Position=9)] + [parameter(Mandatory=$false,HelpMessage="Note",Position=9)] [ValidateNotNullOrEmpty()] [string] $Note, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Exclude this address from status update scans (ping)", - Position=10)] + [parameter(Mandatory=$false,HelpMessage="Exclude this address from status update scans (ping)",Position=10)] [bool] $ExcludePing, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Id of device address belongs to", - Position=11)] - [ValidateScript({ $_ -match "^\d+$" })] + [parameter(Mandatory=$false,HelpMessage="Id of device address belongs to",Position=11)] [ValidateNotNullOrEmpty()] - [string] + [int] $DeviceId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Port", - Position=12)] + [parameter(Mandatory=$false,HelpMessage="Port",Position=12)] [ValidateNotNullOrEmpty()] [string] $Port, - - [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] + [parameter(Mandatory=$false)] [ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })] $CustomFields ) @@ -130,21 +64,25 @@ function Set-Address { Controller = "addresses" Method = "PATCH" } - $_identifiers = @($Id) + switch ($PSCmdlet.ParameterSetName) { + "ByID" { $_id = $Id;break } + "ByAddressObject" { $_id = $AddressObject.id;break } + } + $_identifiers = @($_id) $_params.Add("Identifiers",$_identifiers) $_body = @{ } - if ($Gateway) { $_body.Add("is_gateway", [int]$Gateway) } + if ($Gateway) { $_body.Add("is_gateway", $Gateway) } if ($Description) { $_body.Add("description", $Description) } if ($Hostname) { $_body.Add("hostname", $Hostname) } if ($MAC) { $_body.Add("mac", $MAC) } if ($Owner) { $_body.Add("owner", $Owner) } if ($TagId) { $_body.Add("tag", $TagId) } - if ($PTRIgnore) { $_body.Add("PTRignore", [int]$PTRIgnore) } + if ($PTRIgnore) { $_body.Add("PTRignore", $PTRIgnore) } if ($PTRId) { $_body.add("PTR", $PTRId)} if ($Note) { $_body.Add("note", $Note) } - if ($ExcludePing) { $_body.Add("excludePing", [int]$ExcludePing) } + if ($ExcludePing) { $_body.Add("excludePing", $ExcludePing) } if ($DeviceId) { $_body.Add("deviceId", $DeviceId) } if ($Port) { $_body.Add("port", $Port) } @@ -165,7 +103,7 @@ function Set-Address { Invoke-Request @_params } finally { - Get-Address -Id $Id + Get-Address -Id $_id } } } From 0742737f0d5af834c47550e39c718bc05eda1203 Mon Sep 17 00:00:00 2001 From: Arnike Date: Mon, 12 Dec 2022 18:57:51 +0300 Subject: [PATCH 8/9] Added Assign-Tag cmdlet --- ps.ipam.psd1 | Bin 3352 -> 3398 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/ps.ipam.psd1 b/ps.ipam.psd1 index 456cb9fd0f96d623b4003ac0b0bc7e0ff3498115..d81187c1cb5bb36c4308af0aa8ea84641edc40f8 100644 GIT binary patch delta 32 mcmbOsbxdl*3KnihhGHPhWJqVoo6O6mJoy6~*XB(uX&eBdmI;yo delta 16 YcmX>mHA8B{3YN)o>|C24u%vMS05zWlwg3PC From 9069989af3e15de5105b492d70655ed981d8ff94 Mon Sep 17 00:00:00 2001 From: Arnike Date: Mon, 12 Dec 2022 18:58:13 +0300 Subject: [PATCH 9/9] Fixes --- functions/public/Assign-Tag.ps1 | 33 ++++++ functions/public/Get-Address.ps1 | 10 +- functions/public/Get-Nameserver.ps1 | 6 +- functions/public/Get-Permissions.ps1 | 10 +- functions/public/Get-Section.ps1 | 4 +- functions/public/Get-Subnet.ps1 | 12 ++- functions/public/Get-SubnetUsage.ps1 | 3 +- functions/public/Get-Tag.ps1 | 1 + functions/public/New-Subnet.ps1 | 152 +++++++-------------------- functions/public/Remove-Address.ps1 | 4 +- functions/public/Set-Address.ps1 | 6 +- 11 files changed, 104 insertions(+), 137 deletions(-) create mode 100644 functions/public/Assign-Tag.ps1 diff --git a/functions/public/Assign-Tag.ps1 b/functions/public/Assign-Tag.ps1 new file mode 100644 index 0000000..7b609ab --- /dev/null +++ b/functions/public/Assign-Tag.ps1 @@ -0,0 +1,33 @@ +function Assign-Tag { + [CmdletBinding()] + param ( + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] + [ValidateNotNullOrEmpty()] + [PS.IPAM.Address] + $AddressObject, + [parameter(Mandatory=$true,Position=1)] + [ValidateNotNullOrEmpty()] + [PS.IPAM.Tag] + $Tag + ) + process { + $_params = @{ + Controller = [PS.IPAM.controllers]::addresses + Method = "PATCH" + } + $_id = $AddressObject.id + $_tagid = $Tag.id + + $_identifiers = @($_id) + + $_params.Add("Identifiers",$_identifiers) + + $_body = @{ } + $_body.Add("tag", $_tagid) + + $_params.Add("Params",$_body) + + Invoke-Request @_params + } +} +Export-ModuleMember -Function Assign-Tag \ No newline at end of file diff --git a/functions/public/Get-Address.ps1 b/functions/public/Get-Address.ps1 index 57c32cf..ecaf22e 100644 --- a/functions/public/Get-Address.ps1 +++ b/functions/public/Get-Address.ps1 @@ -36,10 +36,10 @@ function Get-Address { Type = [PS.IPAM.types]::address } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($id) } - "ByIP" { $_identifiers = ("search",$IP) } - "ByHostName" { $_identifiers = ("search_hostname",$HostName) } - "ByTag" { $_identifiers = ("tags",$TagId,[PS.IPAM.controllers]::addresses) } + "ByID" { $_identifiers = @($id); break } + "ByIP" { $_identifiers = ("search",$IP); break } + "ByHostName" { $_identifiers = ("search_hostname",$HostName); break } + "ByTag" { $_identifiers = ("tags",$TagId,[PS.IPAM.controllers]::addresses); break } "BySubnetId" { if ($IP) { $_identifiers = ($IP,$SubnetId) @@ -47,6 +47,7 @@ function Get-Address { $_params.Item("Controller") = [PS.IPAM.controllers]::subnets $_identifiers = ($SubnetId,[PS.IPAM.controllers]::addresses) } + break } "BySubnetCIDR" { $_params.Item("Controller") = [PS.IPAM.controllers]::subnets @@ -54,6 +55,7 @@ function Get-Address { if (!$_subnetId) { throw "Cannot find subnet!" } $_identifiers = ($_subnetId,[PS.IPAM.controllers]::addresses) + break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Nameserver.ps1 b/functions/public/Get-Nameserver.ps1 index 6e798fa..06fe325 100644 --- a/functions/public/Get-Nameserver.ps1 +++ b/functions/public/Get-Nameserver.ps1 @@ -11,12 +11,12 @@ function Get-Nameserver { $visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList) $_params = @{ - Controller = "tools" - SubController = "nameservers" + Controller = [PS.IPAM.controllers]::tools + SubController = [PS.IPAM.subcontrollers]::nameservers Method = "GET" } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_nameserverId = $Id } + "ByID" { $_nameserverId = $Id; break } } $_identifiers = @($_nameserverId) $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Permissions.ps1 b/functions/public/Get-Permissions.ps1 index d86b94c..2cdc0a4 100644 --- a/functions/public/Get-Permissions.ps1 +++ b/functions/public/Get-Permissions.ps1 @@ -41,10 +41,10 @@ function Get-Permissions { Method = "GET" } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($id) } - "ByIP" { $_identifiers = ("search",$IP) } - "ByHostName" { $_identifiers = ("search_hostname",$HostName) } - "ByTag" { $_identifiers = ("tags",$TagId,"addresses") } + "ByID" { $_identifiers = @($id); break } + "ByIP" { $_identifiers = ("search",$IP); break } + "ByHostName" { $_identifiers = ("search_hostname",$HostName); break } + "ByTag" { $_identifiers = ("tags",$TagId,"addresses"); break } "BySubnetId" { if ($IP) { $_identifiers = ($IP,$SubnetId) @@ -52,6 +52,7 @@ function Get-Permissions { $_params.Item("Controller") = "subnets" $_identifiers = ($SubnetId,"addresses") } + break } "BySubnetCIDR" { $_params.Item("Controller") = "subnets" @@ -59,6 +60,7 @@ function Get-Permissions { if (!$_subnetId) { throw "Cannot find subnet!" } $_identifiers = ($_subnetId,"addresses") + break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Section.ps1 b/functions/public/Get-Section.ps1 index f866064..16ae03c 100644 --- a/functions/public/Get-Section.ps1 +++ b/functions/public/Get-Section.ps1 @@ -18,8 +18,8 @@ function Get-Section { Type = [PS.IPAM.types]::Section } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($Id) } - "ByName" { $_identifiers = @($Name) } + "ByID" { $_identifiers = @($Id); break } + "ByName" { $_identifiers = @($Name); break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Subnet.ps1 b/functions/public/Get-Subnet.ps1 index 71cbdb8..814f3af 100644 --- a/functions/public/Get-Subnet.ps1 +++ b/functions/public/Get-Subnet.ps1 @@ -54,7 +54,7 @@ function Get-Subnet { } switch ($PSCmdlet.ParameterSetName) { "ByCIDR" { - $_identifiers = @("cidr",$CIDR) + $_identifiers = @("cidr",$CIDR); break } "ByID" { $_identifiers = @($Id) @@ -66,25 +66,29 @@ function Get-Subnet { $_identifiers += "slaves" } } + break } "BySectionId" { $_params.Item("Controller") = "sections" $_sectionId = $SectionId - $_identifiers = @($_sectionId,"subnets") + $_identifiers = @($_sectionId,"subnets") + break } "BySectionName" { $_params.Item("Controller") = "sections" $_sectionId = (Get-Section -Name $SectionName).id if (!$_sectionId) { throw "Cannot find section!" } - $_identifiers = @($_sectionId,"subnets") + $_identifiers = @($_sectionId,"subnets") + break } "ByVrfId" { $_params.Item("Controller") = "vrf" $_vrfId = $VrfId $_identifiers = @($_vrfId,"subnets") + break } "ByVlanId" { $_params.Item("Controller") = "vlan" @@ -95,6 +99,7 @@ function Get-Subnet { $_identifiers = @($_vlanId,"subnets") if ($_sectionId) { $_identifiers += $_sectionId } + break } "ByVlanNumber" { $_params.Item("Controller") = "vlan" @@ -111,6 +116,7 @@ function Get-Subnet { $_identifiers = @($_vlanId,"subnets") if ($_sectionId) { $_identifiers += $_sectionId } + break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-SubnetUsage.ps1 b/functions/public/Get-SubnetUsage.ps1 index 4cf1cbf..731de87 100644 --- a/functions/public/Get-SubnetUsage.ps1 +++ b/functions/public/Get-SubnetUsage.ps1 @@ -21,8 +21,9 @@ function Get-SubnetUsage { "ByCIDR" { $_subnetId = (Get-Subnet -CIDR $CIDR).id if (!$_subnetId) { throw "Cannot find subnet!" } + break } - "ByID" { $_subnetId = $Id } + "ByID" { $_subnetId = $Id; break } } $_identifiers = @($_subnetId,"usage") $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Tag.ps1 b/functions/public/Get-Tag.ps1 index 606131c..31fa28f 100644 --- a/functions/public/Get-Tag.ps1 +++ b/functions/public/Get-Tag.ps1 @@ -38,6 +38,7 @@ function Get-Tag { } else { return $null } + break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/New-Subnet.ps1 b/functions/public/New-Subnet.ps1 index 72db734..3987f74 100644 --- a/functions/public/New-Subnet.ps1 +++ b/functions/public/New-Subnet.ps1 @@ -11,146 +11,68 @@ function New-Subnet { [ValidateNotNullOrEmpty()] [string] $CIDR, - [parameter( - Mandatory=$true, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Section identifier", - Position=1)] - [ValidateScript({ $_ -match "^\d+$" })] + [parameter(Mandatory=$true,HelpMessage="Section identifier",Position=1)] + [ValidateNotNullOrEmpty()] + [int] + $SectionId, + [parameter(Mandatory=$false,HelpMessage="Subnet description",Position=2)] [ValidateNotNullOrEmpty()] [string] - $SectionId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Subnet description", - Position=2)] - [string] $Description, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Assigns subnet to VLAN", - Position=3)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Assigns subnet to VLAN",Position=3)] + [ValidateNotNullOrEmpty()] + [int] $VlanId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Assigns subnet to VRF", - Position=4)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Assigns subnet to VRF",Position=4)] + [ValidateNotNullOrEmpty()] + [int] $VrfId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Master subnet id for nested subnet", - Position=5)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Master subnet id for nested subnet",Position=5)] + [ValidateNotNullOrEmpty()] + [int] $MasterSubnetId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Id of nameserver to attach to subnet", - Position=6)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Id of nameserver to attach to subnet",Position=6)] + [ValidateNotNullOrEmpty()] + [int] $NameserverId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls weather subnet is displayed as IP address or Name in subnets menu", - Position=7)] + [parameter(Mandatory=$false,HelpMessage="Controls weather subnet is displayed as IP address or Name in subnets menu",Position=7)] [switch] $ShowName, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls if PTR records should be created for subnet", - Position=8)] + [parameter(Mandatory=$false,HelpMessage="Controls if PTR records should be created for subnet",Position=8)] [switch] $DNSRecursive, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls weather hostname DNS records are displayed", - Position=9)] + [parameter(Mandatory=$false,HelpMessage="Controls weather hostname DNS records are displayed",Position=9)] [switch] $DNSRecords, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls if IP requests are allowed for subnet", - Position=10)] + [parameter(Mandatory=$false,HelpMessage="Controls if IP requests are allowed for subnet",Position=10)] [switch] $AllowRequests, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls which scanagent to use for subnet (default id 1)", - Position=11)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Controls which scanagent to use for subnet (default id 1)",Position=11)] + [ValidateNotNullOrEmpty()] + [int] $ScanAgentId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls if new hosts should be discovered for new host scans", - Position=12)] + [parameter(Mandatory=$false,HelpMessage="Controls if new hosts should be discovered for new host scans",Position=12)] [switch] $DiscoverSubnet, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Marks subnet as used", - Position=12)] + [parameter(Mandatory=$false,HelpMessage="Marks subnet as used",Position=12)] [switch] $IsFull, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Assignes state (tag) to subnet (default: 1 Used)", - Position=12)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Assignes state (tag) to subnet (default: 1 Used)",Position=12)] + [ValidateNotNullOrEmpty()] + [int] $TagId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Subnet threshold", - Position=13)] - [ValidateScript({ $_ -match "^\d+$" -and $_ -le 100 -and $_ -ge 1 })] + [parameter(Mandatory=$false,HelpMessage="Subnet threshold",Position=13)] + [ValidateScript({ $_ -le 100 -and $_ -ge 1 })] + [ValidateNotNullOrEmpty()] + [int] $Threshold, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Location index", - Position=14)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Location index",Position=14)] + [ValidateNotNullOrEmpty()] + [int] $LocationId, - [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] [ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })] + [ValidateNotNullOrEmpty()] $CustomFields ) process { diff --git a/functions/public/Remove-Address.ps1 b/functions/public/Remove-Address.ps1 index 536d14d..07a5a07 100644 --- a/functions/public/Remove-Address.ps1 +++ b/functions/public/Remove-Address.ps1 @@ -17,8 +17,8 @@ function Remove-Address { } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($Id);break } - "ByAddressObject" { $_identifiers = @($AddressObject.Id);break } + "ByID" { $_identifiers = @($Id); break } + "ByAddressObject" { $_identifiers = @($AddressObject.Id); break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Set-Address.ps1 b/functions/public/Set-Address.ps1 index 934de3d..f47ef10 100644 --- a/functions/public/Set-Address.ps1 +++ b/functions/public/Set-Address.ps1 @@ -61,12 +61,12 @@ function Set-Address { ) process { $_params = @{ - Controller = "addresses" + Controller = [PS.IPAM.controllers]::addresses Method = "PATCH" } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_id = $Id;break } - "ByAddressObject" { $_id = $AddressObject.id;break } + "ByID" { $_id = $Id; break } + "ByAddressObject" { $_id = $AddressObject.id; break } } $_identifiers = @($_id)