Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update-TssSecretAccessRequest - new command
- Loading branch information
Showing
7 changed files
with
315 additions
and
8 deletions.
There are no files selected for viewing
166 changes: 166 additions & 0 deletions
166
docs/commands/secret-access-requests/Update-TssSecretAccessRequest.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
# Update-TssSecretAccessRequest | ||
|
||
## SYNOPSIS | ||
Update a Access Request for the current user | ||
|
||
## SYNTAX | ||
|
||
``` | ||
Update-TssSecretAccessRequest [-TssSession] <Session> -RequestId <Int32> -Status <SecretAccessStatus> | ||
[-StartDate <String>] [-ExpirationDate <String>] [-Response <String>] [-WhatIf] [-Confirm] | ||
[<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
Update a Access Request for the current user | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
``` | ||
session = New-TssSession -SecretServer https://alpha -Credential ssCred | ||
Update-TssSecretAccessRequest -TssSession $session -RequestId | ||
``` | ||
|
||
Update ... | ||
|
||
## PARAMETERS | ||
|
||
### -TssSession | ||
TssSession object created by New-TssSession for authentication | ||
|
||
```yaml | ||
Type: Session | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 1 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -RequestId | ||
Secret Access Request Id | ||
|
||
```yaml | ||
Type: Int32 | ||
Parameter Sets: (All) | ||
Aliases: SecretAccessRequestId | ||
|
||
Required: True | ||
Position: Named | ||
Default value: 0 | ||
Accept pipeline input: True (ByPropertyName) | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -Status | ||
Set the status desired (Pending, Approved, Denied, Canceled) | ||
|
||
```yaml | ||
Type: SecretAccessStatus | ||
Parameter Sets: (All) | ||
Aliases: | ||
Accepted values: Approved, Canceled, Denied, Pending | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -StartDate | ||
Start date, defaults to now (current datetime) | ||
|
||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: [datetime]::Now | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -ExpirationDate | ||
Expiration date | ||
|
||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -Response | ||
Response or comment | ||
|
||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -WhatIf | ||
Shows what would happen if the cmdlet runs. | ||
The cmdlet is not run. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: wi | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -Confirm | ||
Prompts you for confirmation before running the cmdlet. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Aliases: cf | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### CommonParameters | ||
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). | ||
|
||
## INPUTS | ||
|
||
## OUTPUTS | ||
|
||
## NOTES | ||
Requires TssSession object returned by New-TssSession | ||
|
||
## RELATED LINKS | ||
|
||
[https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-access-requests/Update-TssSecretAccessRequest](https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-access-requests/Update-TssSecretAccessRequest) | ||
|
||
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-access-requests/Update-TssSecretAccessRequest.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-access-requests/Update-TssSecretAccessRequest.ps1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Thycotic.SecretServer/enums/secret-access-requests/SecretAccessStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Management.Automation; | ||
using System.Management.Automation.Runspaces; | ||
|
||
namespace Thycotic.PowerShell.Enums | ||
{ | ||
public enum SecretAccessStatus | ||
{ | ||
Approved, | ||
Canceled, | ||
Denied, | ||
Pending | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/functions/secret-access-requests/Update-TssSecretAccessRequest.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
function Update-TssSecretAccessRequest { | ||
<# | ||
.SYNOPSIS | ||
Update a Access Request for the current user | ||
.DESCRIPTION | ||
Update a Access Request for the current user | ||
.EXAMPLE | ||
session = New-TssSession -SecretServer https://alpha -Credential ssCred | ||
Update-TssSecretAccessRequest -TssSession $session -RequestId | ||
Update ... | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-access-requests/Update-TssSecretAccessRequest | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-access-requests/Update-TssSecretAccessRequest.ps1 | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[cmdletbinding(SupportsShouldProcess)] | ||
param( | ||
# TssSession object created by New-TssSession for authentication | ||
[Parameter(Mandatory, ValueFromPipeline, Position = 0)] | ||
[Thycotic.PowerShell.Authentication.Session] | ||
$TssSession, | ||
|
||
# Secret Access Request Id | ||
[Parameter(Mandatory, ValueFromPipelineByPropertyName)] | ||
[Alias('SecretAccessRequestId')] | ||
[int] | ||
$RequestId, | ||
|
||
# Set the status desired (Pending, Approved, Denied, Canceled) | ||
[Parameter(Mandatory)] | ||
[Thycotic.PowerShell.Enums.SecretAccessStatus] | ||
$Status, | ||
|
||
# Start date, defaults to now (current datetime) | ||
[string] | ||
$StartDate = [datetime]::Now, | ||
|
||
# Expiration date | ||
[string] | ||
$ExpirationDate, | ||
|
||
# Response or comment | ||
[string] | ||
$Response | ||
) | ||
begin { | ||
$updateParams = $PSBoundParameters | ||
$invokeParams = . $GetInvokeApiParams $TssSession | ||
} | ||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
if ($updateParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { | ||
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation | ||
$restResponse = $null | ||
$uri = $TssSession.ApiUrl, 'secret-access-requests' -join '/' | ||
$invokeParams.Uri = $uri | ||
$invokeParams.Method = 'PUT' | ||
|
||
if ($Status -eq 'Denied' -and (-not $updateParams.ContainsKey('Response'))) { | ||
Write-Warning 'A response is required when request has been denied' | ||
return | ||
} | ||
if ($Status -eq 'Approved' -and (-not $updateParams.ContainsKey('ExpirationDate'))) { | ||
Write-Warning 'A start and expiration date must be provided when Approving the request.' | ||
return | ||
} | ||
$updateBody = @{} | ||
$updateBody.Add('startDate',[datetime]$StartDate) | ||
switch ($updateParams.Keys){ | ||
'RequestId' { $updateBody.Add('secretAccessRequestId',$RequestId) } | ||
'Status' { $updateBody.Add('status',[string]$Status) } | ||
'ExpirationDate' { $updateBody.Add('expirationDate',[datetime]$ExpirationDate) } | ||
'Response' { $updateBody.Add('responseComment',$Response) } | ||
} | ||
$invokeParams.Body = $updateBody | ConvertTo-Json | ||
if ($PSCmdlet.ShouldProcess("Secret Access Request: $RequestId", "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)")) { | ||
Write-Verbose "$($invokeParams.Method) $uri with: `n$($invokeParams.Body)" | ||
try { | ||
$apiResponse = Invoke-TssApi @invokeParams | ||
$restResponse = . $ProcessResponse $apiResponse | ||
} catch { | ||
Write-Warning "Issue updating Secret Access Request [$RequestId]" | ||
$err = $_ | ||
. $ErrorHandling $err | ||
} | ||
|
||
if ($restResponse) { | ||
Write-Verbose "Secret Access Request [$RequestId] updated successfully" | ||
} else { | ||
Write-Warning "Secret Access Request [$RequestId] was not updated, see previous output for errors" | ||
} | ||
} | ||
} else { | ||
Write-Warning 'No valid session found' | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/secret-access-requests/Update-TssSecretAccessRequest.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'TssSession','RequestId','Status','StartDate','ExpirationDate','Response' | ||
[object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys | ||
[object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function') | ||
$unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru | ||
} | ||
Context "Verify parameters" -Foreach @{currentParams = $currentParams } { | ||
It "$commandName should contain <_> parameter" -TestCases $knownParameters { | ||
$_ -in $currentParams | Should -Be $true | ||
} | ||
It "$commandName should not contain parameter: <_>" -TestCases $unknownParameters { | ||
$_ | Should -BeNullOrEmpty | ||
} | ||
} | ||
} |