-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.ps1
123 lines (116 loc) · 5.41 KB
/
link.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
function ConvertTo-Link {
[CmdletBinding()]
Param(
[parameter(Position=0,ValueFromPipeline=$true)] [xml] $InputObject
)
Begin {
}
Process {
$InputObject |
? { $_.object -and $_.object.type -and $_.object.id } |
% {
# object id
$local:id = $_.object.id | ConvertTo-ObjectPath
# child objects
$_.object.object |
? { $_.type -and $_.id -and $_.link } |
% {
$local:out = $local:id | Join-LinkPath -LinkName $_.link -Link ($_.id | ConvertTo-ObjectPath)
$local:out.PSObject.TypeNames.Insert(0, "SSO.Link")
if($_.enabled) {
$local:out = $local:out | Add-Member -MemberType NoteProperty -Name "Enabled" -Value $_.enabled -PassThru
}
if($_.index) {
$local:out = $local:out | Add-Member -MemberType NoteProperty -Name "Index" -Value ($_.index | ConvertTo-ObjectPath) -PassThru
}
$local:out = $local:out | Add-Member -MemberType MemberSet -Name "PSStandardMembers" -Value (NewDefaultDisplayPropertySet "Value","Enabled","Index") -Force -PassThru
$local:out
}
}
}
}
function Get-Link {
[CmdletBinding(DefaultParameterSetName="Link")]
Param(
[Parameter(ValueFromPipeline=$true,Mandatory=$true)] [PSTypeName("SSO.ObjectPath")] $InputObject,
[Parameter()] [AllowNull()] [string] $LinkName = $null,
[Parameter(ParameterSetName="Link",Position=0)] [AllowNull()] [PSTypeName("SSO.ObjectPath")] $Link = $null,
[Parameter(ParameterSetName="LinkValue",Mandatory=$true)] [string] $LinkType,
[Parameter(ParameterSetName="LinkValue",Position=0)] [AllowNull()] [string[]] $LinkValue = $null,
[Parameter()] [PSTypeName("Context")] $Context = (GetContext)
)
Begin {
}
Process {
$InputObject | Select-LinkPath $PSBoundParameters | Invoke-Api -Method Get -Context $Context | ConvertTo-Link
}
}
<#
.SYNOPSIS Select Link property from input pipeline
#>
function Select-Link {
[CmdletBinding()]
Param(
[Parameter(Position=0,ValueFromPipeline=$true,Mandatory=$true)] [PSTypeName("SSO.LinkPath")] $InputObject,
[Parameter(ParameterSetName="Id")] [switch] $Id,
[Parameter(ParameterSetName="Link")] [switch] $Link,
[Parameter(ParameterSetName="Index")] [switch] $Index
)
Process {
$InputObject | % {
if($Id) { New-ObjectPath -Type $_.Type -Value $_.Id }
elseif($Link) { $_.Link }
elseif($Index) { $_.Index }
}
}
}
function Set-Link {
[CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName="Link")]
Param(
[Parameter(ValueFromPipeline=$true,Mandatory=$true)] [PSTypeName("SSO.ObjectPath")] $InputObject,
[Parameter()] [AllowNull()] [string] $LinkName = $null,
[Parameter(ParameterSetName="Link",Position=0)] [AllowNull()] [PSTypeName("SSO.ObjectPath")] $Link = $null,
[Parameter(ParameterSetName="LinkValue",Mandatory=$true)] [string] $LinkType,
[Parameter(ParameterSetName="LinkValue",Position=0)] [AllowNull()] [string[]] $LinkValue = $null,
[parameter()] [switch] $Enabled,
[parameter()] [hashtable] $Attributes = $null,
[Parameter()] [PSTypeName("Context")] $Context = (GetContext)
)
Begin {
}
Process {
$InputObject | Select-LinkPath $PSBoundParameters | Invoke-Api -Method Put -Body (ConvertTo-Form $PSBoundParameters) -Context $Context | ConvertTo-Link
}
}
function Add-Link {
[CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName="Link")]
Param(
[Parameter(ValueFromPipeline=$true,Mandatory=$true)] [PSTypeName("SSO.ObjectPath")] $InputObject,
[Parameter()] [AllowNull()] [string] $LinkName = $null,
[Parameter(ParameterSetName="Link",Position=0)] [AllowNull()] [PSTypeName("SSO.ObjectPath")] $Link = $null,
[Parameter(ParameterSetName="LinkValue",Mandatory=$true)] [string] $LinkType,
[Parameter(ParameterSetName="LinkValue",Position=0)] [AllowNull()] [string[]] $LinkValue = $null,
[parameter()] [switch] $Enabled,
[parameter()] [hashtable] $Attributes = $null,
[Parameter()] [PSTypeName("Context")] $Context = (GetContext)
)
Begin {
}
Process {
$InputObject | Select-LinkPath $PSBoundParameters | Invoke-Api -Method Post -Body (ConvertTo-Form $PSBoundParameters) -Context $Context | ConvertTo-Link
}
}
function Remove-Link {
[CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName="Link")]
Param(
[Parameter(ValueFromPipeline=$true,Mandatory=$true)] [PSTypeName("SSO.ObjectPath")] $InputObject,
[Parameter()] [AllowNull()] [string] $LinkName = $null,
[Parameter(ParameterSetName="Link",Position=0)] [AllowNull()] [PSTypeName("SSO.ObjectPath")] $Link = $null,
[Parameter(ParameterSetName="LinkValue",Mandatory=$true)] [string] $LinkType,
[Parameter(ParameterSetName="LinkValue",Position=0)] [AllowNull()] [string[]] $LinkValue = $null,
[Parameter()] [PSTypeName("Context")] $Context = (GetContext)
)
Process {
$InputObject | Select-LinkPath $PSBoundParameters | Invoke-Api -Method Delete -Context $Context
}
}