Skip to content

Commit 691bca1

Browse files
Add Rename-PASPlatform command with documentation and tests
1 parent 7ae6e5c commit 691bca1

5 files changed

Lines changed: 290 additions & 0 deletions

File tree

Tests/Rename-PASPlatform.Tests.ps1

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Describe $($PSCommandPath -Replace '.Tests.ps1') {
2+
3+
BeforeAll {
4+
#Get Current Directory
5+
$Here = Split-Path -Parent $PSCommandPath
6+
7+
#Assume ModuleName from Repository Root folder
8+
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf
9+
10+
#Resolve Path to Module Directory
11+
$ModulePath = Resolve-Path "$Here\..\$ModuleName"
12+
13+
#Define Path to Module Manifest
14+
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1"
15+
16+
if ( -not (Get-Module -Name $ModuleName -All)) {
17+
18+
Import-Module -Name "$ManifestPath" -ArgumentList $true -Force -ErrorAction Stop
19+
20+
}
21+
22+
$Script:RequestBody = $null
23+
$psPASSession = [ordered]@{
24+
BaseURI = 'https://SomeURL/SomeApp'
25+
User = $null
26+
ExternalVersion = [System.Version]'0.0'
27+
WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
28+
StartTime = $null
29+
ElapsedTime = $null
30+
LastCommand = $null
31+
LastCommandTime = $null
32+
LastCommandResults = $null
33+
}
34+
35+
New-Variable -Name psPASSession -Value $psPASSession -Scope Script -Force
36+
37+
}
38+
39+
40+
AfterAll {
41+
42+
$Script:RequestBody = $null
43+
44+
}
45+
46+
InModuleScope $(Split-Path (Split-Path (Split-Path -Parent $PSCommandPath) -Parent) -Leaf ) {
47+
48+
BeforeEach {
49+
Mock Invoke-PASRestMethod -MockWith { }
50+
51+
Rename-PASPlatform -ID 42 -Name 'NewPlatformName'
52+
}
53+
54+
Context 'Input' {
55+
56+
It 'sends request' {
57+
58+
Assert-MockCalled Invoke-PASRestMethod -Scope It
59+
60+
}
61+
62+
It 'sends request to expected endpoint' {
63+
64+
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {
65+
66+
$URI -eq "$($Script:psPASSession.BaseURI)/API/Platforms/targets/42"
67+
68+
} -Scope It
69+
70+
}
71+
72+
It 'uses expected method' {
73+
74+
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter { $Method -match 'PUT' } -Times 1 -Exactly -Scope It
75+
76+
}
77+
78+
It 'sends request with expected body' {
79+
80+
Assert-MockCalled Invoke-PASRestMethod -ParameterFilter {
81+
If ($null -ne $Body) {
82+
$($Body | ConvertFrom-Json | Select-Object -ExpandProperty Name) -eq 'NewPlatformName'
83+
}
84+
} -Scope It -Times 1
85+
86+
}
87+
88+
It 'throws error if version requirement not met' {
89+
$psPASSession.ExternalVersion = '1.0'
90+
{ Rename-PASPlatform -ID 42 -Name 'NewPlatformName' } | Should -Throw
91+
$psPASSession.ExternalVersion = '0.0'
92+
}
93+
94+
It 'throws error if run against Privilege Cloud' {
95+
$psPASSession.BaseURI = 'https://something.cyberark.cloud'
96+
{ Rename-PASPlatform -ID 42 -Name 'NewPlatformName' } | Should -Throw
97+
$psPASSession.BaseURI = 'https://SomeURL/SomeApp'
98+
}
99+
100+
}
101+
102+
Context 'Output' {
103+
104+
It 'provides no output' {
105+
Mock Invoke-PASRestMethod -MockWith { }
106+
107+
$response = Rename-PASPlatform -ID 42 -Name 'NewPlatformName'
108+
109+
$response | Should -BeNullOrEmpty
110+
111+
}
112+
113+
}
114+
115+
}
116+
117+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
category: PSPAS
3+
external help file: psPAS-help.xml
4+
Module Name: psPAS
5+
online version: https://pspas.pspete.dev/commands/Rename-PASPlatform
6+
schema: 2.0.0
7+
title: Rename-PASPlatform
8+
---
9+
10+
# Rename-PASPlatform
11+
12+
## SYNOPSIS
13+
Renames a target platform.
14+
15+
## SYNTAX
16+
17+
```
18+
Rename-PASPlatform -ID <Int32> -Name <String> [-WhatIf] [-Confirm] [<CommonParameters>]
19+
```
20+
21+
## DESCRIPTION
22+
Renames an existing target platform.
23+
24+
The user must be a member of the Vault Admins group.
25+
26+
This command is only applicable to Self-Hosted implementations.
27+
28+
## EXAMPLES
29+
30+
### EXAMPLE 1
31+
```
32+
Rename-PASPlatform -ID 42 -Name "NewPlatformName"
33+
```
34+
35+
Renames the target platform with ID 42 to "NewPlatformName"
36+
37+
### EXAMPLE 2
38+
```
39+
Get-PASPlatform -PlatformType Target | Where-Object {$_.Name -eq "OldName"} | Rename-PASPlatform -Name "NewName"
40+
```
41+
42+
Finds a target platform by name and renames it
43+
44+
## PARAMETERS
45+
46+
### -ID
47+
The unique ID of the platform to rename.
48+
49+
```yaml
50+
Type: Int32
51+
Parameter Sets: (All)
52+
Aliases:
53+
54+
Required: True
55+
Position: Named
56+
Default value: 0
57+
Accept pipeline input: True (ByPropertyName)
58+
Accept wildcard characters: False
59+
```
60+
61+
### -Name
62+
The new name for the platform.
63+
64+
Platform names must be unique across the system.
65+
66+
```yaml
67+
Type: String
68+
Parameter Sets: (All)
69+
Aliases:
70+
71+
Required: True
72+
Position: Named
73+
Default value: None
74+
Accept pipeline input: True (ByPropertyName)
75+
Accept wildcard characters: False
76+
```
77+
78+
### -WhatIf
79+
Shows what would happen if the cmdlet runs.
80+
The cmdlet is not run.
81+
82+
```yaml
83+
Type: SwitchParameter
84+
Parameter Sets: (All)
85+
Aliases: wi
86+
87+
Required: False
88+
Position: Named
89+
Default value: None
90+
Accept pipeline input: False
91+
Accept wildcard characters: False
92+
```
93+
94+
### -Confirm
95+
Prompts you for confirmation before running the cmdlet.
96+
97+
```yaml
98+
Type: SwitchParameter
99+
Parameter Sets: (All)
100+
Aliases: cf
101+
102+
Required: False
103+
Position: Named
104+
Default value: None
105+
Accept pipeline input: False
106+
Accept wildcard characters: False
107+
```
108+
109+
### CommonParameters
110+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
111+
112+
## INPUTS
113+
114+
## OUTPUTS
115+
116+
## NOTES
117+
Minimum version 15.0
118+
119+
Self-Hosted implementations only
120+
121+
## RELATED LINKS
122+
123+
[https://pspas.pspete.dev/commands/Rename-PASPlatform](https://pspas.pspete.dev/commands/Rename-PASPlatform)
124+
125+
[https://docs.cyberark.com/pam-self-hosted/latest/en/content/sdk/rest-api-update-target-platform.htm](https://docs.cyberark.com/pam-self-hosted/latest/en/content/sdk/rest-api-update-target-platform.htm)

docs/collections/_pages/commands.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ A psPAS command may not appear in the below list due to it not being explicitly
108108
[Activate target platform][Activate target platform] | [Enable-PASPlatform][Enable-PASPlatform]
109109
[Deactivate target platform][Deactivate target platform] | [Disable-PASPlatform][Disable-PASPlatform]
110110
[Delete target platform][Delete target platform] | [Remove-PASPlatform][Remove-PASPlatform]
111+
[Rename target platform][Rename target platform] | [Rename-PASPlatform][Rename-PASPlatform]
111112
[Get dependent platforms][Get dependent platforms] | [Get-PASPlatform][Get-PASPlatform]
112113
[Duplicate dependent platforms][Duplicate dependent platforms] | [Copy-PASPlatform][Copy-PASPlatform]
113114
[Delete dependent platform][Delete dependent platform] | [Remove-PASPlatform][Remove-PASPlatform]
@@ -409,6 +410,7 @@ A psPAS command may not appear in the below list due to it not being explicitly
409410
[Disable-PASPlatform]:/commands/Disable-PASPlatform
410411
[Enable-PASPlatform]:/commands/Enable-PASPlatform
411412
[Remove-PASPlatform]:/commands/Remove-PASPlatform
413+
[Rename-PASPlatform]:/commands/Rename-PASPlatform
412414
[Remove-PASGroup]:/commands/Remove-PASGroup
413415
[Add-PASOpenIDConnectProvider]:/commands/Add-PASOpenIDConnectProvider
414416
[Get-PASOpenIDConnectProvider]:/commands/Get-PASOpenIDConnectProvider
@@ -559,6 +561,7 @@ A psPAS command may not appear in the below list due to it not being explicitly
559561
[Activate target platform]:https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-activate-target-platform.htm
560562
[Deactivate target platform]:https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-deactivate-target-platform.htm
561563
[Delete target platform]:https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-delete-target-platform.htm
564+
[Rename target platform]:https://docs.cyberark.com/pam-self-hosted/latest/en/content/sdk/rest-api-update-target-platform.htm
562565
[Get dependent platforms]:https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-dependent-platforms.htm
563566
[Duplicate dependent platforms]:https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-duplicate-dependent-platforms.htm
564567
[Delete dependent platform]:https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-delete-dependent-platform.htm
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# .ExternalHelp psPAS-help.xml
2+
function Rename-PASPlatform {
3+
[CmdletBinding(SupportsShouldProcess)]
4+
param(
5+
[parameter(
6+
Mandatory = $true,
7+
ValueFromPipelinebyPropertyName = $true
8+
)]
9+
[int]$ID,
10+
11+
[parameter(
12+
Mandatory = $true,
13+
ValueFromPipelinebyPropertyName = $true
14+
)]
15+
[string]$Name
16+
)
17+
18+
begin {
19+
Assert-VersionRequirement -SelfHosted
20+
Assert-VersionRequirement -RequiredVersion 15.0
21+
}#begin
22+
23+
process {
24+
25+
#Create URL for request
26+
$URI = "$($psPASSession.BaseURI)/API/Platforms/targets/$ID"
27+
28+
#Get request parameters
29+
$boundParameters = $PSBoundParameters | Get-PASParameter -ParametersToRemove ID
30+
31+
$body = $boundParameters | ConvertTo-Json
32+
33+
if ($PSCmdlet.ShouldProcess($ID, "Update Target Platform Name")) {
34+
35+
#send request to web service
36+
Invoke-PASRestMethod -Uri $URI -Method PUT -Body $body
37+
38+
}
39+
40+
}#process
41+
42+
end { }#end
43+
44+
}

psPAS/psPAS.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
'Disable-PASPlatform',
190190
'Enable-PASPlatform',
191191
'Remove-PASPlatform',
192+
'Rename-PASPlatform',
192193
'Remove-PASGroup',
193194
'Get-PASAllowedReferrer',
194195
'Add-PASAllowedReferrer',

0 commit comments

Comments
 (0)