Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get-SecretDependencyRunStatus - fixes #180
- Loading branch information
Showing
7 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
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
16 changes: 16 additions & 0 deletions
16
src/classes/secret-dependencies/TssSecretDependencyTaskProgress.class.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,16 @@ | ||
class TssSecretDependencyTaskProgress { | ||
[TssSecretDependencyTaskError[]] | ||
$Errors | ||
|
||
[boolean] | ||
$IsComplete | ||
|
||
[int] | ||
$PercentageComplete | ||
|
||
[string] | ||
$Status | ||
|
||
[string] | ||
$TaskIdentifier | ||
} |
7 changes: 7 additions & 0 deletions
7
src/classes/secret-dependencies/dependencies/TssSecretDependencyTaskError.class.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,7 @@ | ||
class TssSecretDependencyTaskError { | ||
[string] | ||
$ErrorMessage | ||
|
||
[string] | ||
$ItemName | ||
} |
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,27 @@ | ||
TOPIC | ||
This help topic describes the TssSecretDependencyTaskError class in the Thycotic.SecretServer module | ||
|
||
CLASS | ||
TssSecretDependencyTaskError | ||
|
||
INHERITANCE | ||
None | ||
|
||
DESCRIPTION | ||
The TssSecretDependencyTaskError class represents the TaskError object returned by Secret Server endpoint GET /secret-dependencies/run/{identifier} | ||
|
||
CONSTRUCTORS | ||
new() | ||
|
||
PROPERTIES | ||
ErrorMessage: string | ||
The error message | ||
|
||
ItemName: string | ||
The name of the item that had the error | ||
|
||
METHODS | ||
|
||
RELATED LINKS: | ||
TssSecretDependencyTaskProgress | ||
Get-TssSecretDependencyRunStatus |
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,35 @@ | ||
TOPIC | ||
This help topic describes the TssSecretDependencyTaskProgress class in the Thycotic.SecretServer module | ||
|
||
CLASS | ||
TssSecretDependencyTaskProgress | ||
|
||
INHERITANCE | ||
None | ||
|
||
DESCRIPTION | ||
The TssSecretDependencyTaskProgress class represents the TaskProgress object returned by Secret Server endpoint GET /secret-dependencies/run | ||
|
||
CONSTRUCTORS | ||
new() | ||
|
||
PROPERTIES | ||
Errors: TssSecretDependencyTaskError[] | ||
A list of errors for the task | ||
|
||
IsComplete: boolean | ||
True if the task is complete | ||
|
||
PercentageComplete: integer (int32) | ||
The estimated percentage complete of the task | ||
|
||
Status: string | ||
The current status of the task | ||
|
||
TaskIdentifier: string | ||
The task identifier | ||
|
||
METHODS | ||
|
||
RELATED LINKS: | ||
Get-TssSecretDependencyRunStatus |
70 changes: 70 additions & 0 deletions
70
src/functions/secret-dependencies/Get-SecretDependencyRunStatus.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,70 @@ | ||
function Get-SecretDependencyRunStatus { | ||
<# | ||
.SYNOPSIS | ||
Get Run status of a Secret Dependency identifier | ||
.DESCRIPTION | ||
Get Run status of a Secret Dependency identifier | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
$ident = Start-TssSecretDependency -TssSession $session -Id 46 | ||
Get-TssSecretDependencyRunStatus -TssSession $session -Identifier $run | ||
After starting a Secret's Dependency 46, get the status of that run | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/Get-TssSecretDependencyRunStatus | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-dependencies/Get-SecretDependencyRunStatus.ps1 | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[CmdletBinding()] | ||
[OutputType('TssSecretDependencyTaskProgress')] | ||
param ( | ||
# TssSession object created by New-TssSession for auth | ||
[Parameter(Mandatory,ValueFromPipeline,Position = 0)] | ||
[TssSession] | ||
$TssSession, | ||
|
||
# Identifier, output from Start-TssSecretDependency | ||
[Parameter(Mandatory,ValueFromPipeline)] | ||
[string[]] | ||
$Identifier | ||
) | ||
begin { | ||
$tssParams = $PSBoundParameters | ||
$invokeParams = . $GetInvokeTssParams $TssSession | ||
} | ||
|
||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { | ||
. $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation | ||
foreach ($run in $Identifier) { | ||
$restResponse = $null | ||
$uri = $TssSession.ApiUrl, 'secret-dependencies', 'run', $run -join '/' | ||
$invokeParams.Uri = $uri | ||
$invokeParams.Method = 'GET' | ||
|
||
Write-Verbose "Performing the operation $($invokeParams.Method) $uri with $body" | ||
try { | ||
$restResponse = . $InvokeApi @invokeParams | ||
} catch { | ||
Write-Warning "Issue getting run status on [$run]" | ||
$err = $_ | ||
. $ErrorHandling $err | ||
} | ||
|
||
if ($restResponse) { | ||
[TssSecretDependencyTaskProgress]$restResponse | ||
} | ||
} | ||
} else { | ||
Write-Warning "No valid session found" | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
tests/secret-dependencies/Get-SecretDependencyRunStatus.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,73 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
. ([IO.Path]::Combine([string]$PSScriptRoot, '..', 'constants.ps1')) | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'TssSession', 'Identifier' | ||
[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 | ||
} | ||
} | ||
Context "Command specific details" { | ||
It "$commandName should set OutputType to TssSecretDependencyTaskProgress" -TestCases $commandDetails { | ||
$_.OutputType.Name | Should -Be 'TssSecretDependencyTaskProgress' | ||
} | ||
} | ||
} | ||
Describe "$commandName functions" { | ||
Context "Checking" { | ||
BeforeAll { | ||
$session = [pscustomobject]@{ | ||
ApiVersion = 'api/v1' | ||
Take = 2147483647 | ||
SecretServer = 'http://alpha/' | ||
ApiUrl = 'http://alpha/api/v1' | ||
AccessToken = 'AgJf5YLChrisPine312UcBrM1s1KB2BGZ5Ufc4qLZ' | ||
RefreshToken = '9oacYeah0YqgBNg0L7VinDiesel6-Z9ITE51Humus' | ||
TokenType = 'bearer' | ||
ExpiresIn = 1199 | ||
} | ||
Mock -Verifiable -CommandName Invoke-RestMethod -ParameterFilter { $Uri -match '/version' } -MockWith { | ||
return @{ | ||
model = [pscustomobject]@{ | ||
Version = '10.9.000033' | ||
} | ||
} | ||
} | ||
|
||
[string]$guid = (New-Guid).Guid | ||
Mock -Verifiable -CommandName Invoke-RestMethod -ParameterFilter { $Uri -match "/secret-dependencies/run/$guid" } -MockWith { | ||
return [pscustomobject]@{ | ||
errors = $null | ||
isComplete = $false | ||
percentageComplete = 85 | ||
status = $null | ||
taskIdentifier = "$guid" | ||
} | ||
} | ||
$object = Get-SecretDependencyRunStatus -TssSession $session -Identifier $guid | ||
Assert-VerifiableMock | ||
} | ||
It "Should not be empty" { | ||
$object | Should -Not -BeNullOrEmpty | ||
} | ||
It "Should have property <_>" -TestCases 'IsComplete', 'TaskIdentifier' { | ||
$object[0].PSObject.Properties.Name | Should -Contain $_ | ||
} | ||
It "Should have property PercentageComplete equal 85" { | ||
$object.PercentageComplete | Should -Be 85 | ||
} | ||
It "Should have called Invoke-RestMethod 2 times" { | ||
Assert-MockCalled -CommandName Invoke-RestMethod -Times 2 -Scope Describe | ||
} | ||
} | ||
} |