Skip to content

Commit

Permalink
Get-SecretDependencyRunStatus - fixes #180
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed May 7, 2021
1 parent 2565995 commit c062da2
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Expand Up @@ -1540,5 +1540,48 @@
</TableControl>
</View>

<!-- Get-TssSecretDependencyRunStatus -->
<View>
<Name>TssSecretDependencyTaskProgress</Name>
<ViewSelectedBy>
<TypeName>TssSecretDependencyTaskProgress</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
</TableColumnHeader>
<TableColumnHeader>
</TableColumnHeader>
<TableColumnHeader>
</TableColumnHeader>
<TableColumnHeader>
</TableColumnHeader>
<TableColumnHeader>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>TaskIdentifier</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Status</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>PercentageComplete</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>IsComplete</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Errors</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
@@ -0,0 +1,16 @@
class TssSecretDependencyTaskProgress {
[TssSecretDependencyTaskError[]]
$Errors

[boolean]
$IsComplete

[int]
$PercentageComplete

[string]
$Status

[string]
$TaskIdentifier
}
@@ -0,0 +1,7 @@
class TssSecretDependencyTaskError {
[string]
$ErrorMessage

[string]
$ItemName
}
27 changes: 27 additions & 0 deletions src/en-us/about_tsssecretdependencytaskerror.help.txt
@@ -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
35 changes: 35 additions & 0 deletions src/en-us/about_tsssecretdependencytaskprogress.help.txt
@@ -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
@@ -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 tests/secret-dependencies/Get-SecretDependencyRunStatus.Tests.ps1
@@ -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
}
}
}

0 comments on commit c062da2

Please sign in to comment.