Base
This commit is contained in:
@@ -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)")
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
19
functions/private/Test-Session.ps1
Normal file
19
functions/private/Test-Session.ps1
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
68
functions/public/Get-Address.ps1
Normal file
68
functions/public/Get-Address.ps1
Normal file
@@ -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
|
||||
@@ -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
|
||||
Export-ModuleMember -Function Get-FirstFreeIP
|
||||
@@ -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
|
||||
Export-ModuleMember -Function Get-L2Domain
|
||||
@@ -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
|
||||
Export-ModuleMember -Function Get-Nameserver
|
||||
@@ -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
|
||||
@@ -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
|
||||
Export-ModuleMember -Function Get-Permissions
|
||||
@@ -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
|
||||
Export-ModuleMember Get-Section
|
||||
@@ -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
|
||||
Export-ModuleMember Get-Subnet
|
||||
@@ -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
|
||||
Export-ModuleMember -Function Get-SubnetUsage
|
||||
37
functions/public/Get-Tag.ps1
Normal file
37
functions/public/Get-Tag.ps1
Normal file
@@ -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
|
||||
@@ -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
|
||||
Export-ModuleMember -Function Get-Vlan
|
||||
@@ -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
|
||||
Export-ModuleMember -Function Get-Vrf
|
||||
@@ -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
|
||||
Export-ModuleMember -Function New-Address
|
||||
@@ -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
|
||||
Export-ModuleMember -Function New-FirstFreeIP
|
||||
@@ -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
|
||||
53
functions/public/New-Session.ps1
Normal file
53
functions/public/New-Session.ps1
Normal file
@@ -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
|
||||
@@ -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
|
||||
Export-ModuleMember -Function New-Subnet
|
||||
@@ -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
|
||||
Export-ModuleMember Remove-Address
|
||||
@@ -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
|
||||
Export-ModuleMember -Function Set-Address
|
||||
Reference in New Issue
Block a user