Skip to content

Commit

Permalink
Get-TssEventPipelineRun - new command
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Aug 4, 2021
1 parent 1d6d493 commit 80ff0c2
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 5 deletions.
73 changes: 73 additions & 0 deletions docs/commands/event-pipeline/Get-TssEventPipelineRun.md
@@ -0,0 +1,73 @@
# Get-TssEventPipelineRun

## SYNOPSIS
Get all of the runs for an Event Pipeline

## SYNTAX

```
Get-TssEventPipelineRun [-TssSession] <Session> -Id <Int32[]> [<CommonParameters>]
```

## DESCRIPTION
Get all of the runs for an Event Pipeline

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssEventPipelineRun -TssSession $session -Id 42
```

Outputs the Activity details for Event Pipeline 42

## 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
```

### -Id
Short description for parameter

```yaml
Type: Int32[]
Parameter Sets: (All)
Aliases: EventPipelineId

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
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

### Thycotic.PowerShell.EventPipeline.RunView
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/event-pipeline/Get-TssEventPipelineRun](https://thycotic-ps.github.io/thycotic.secretserver/commands/event-pipeline/Get-TssEventPipelineRun)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/event-pipeline/Get-TssEventPipelineRun.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/event-pipeline/Get-TssEventPipelineRun.ps1)

58 changes: 58 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Expand Up @@ -2334,5 +2334,63 @@
</TableControl>
</View>

<!-- Thycotic.PowerShell.EventPipeline.RunView -->
<View>
<Name>EventPipeline.RunView</Name>
<ViewSelectedBy>
<TypeName>Thycotic.PowerShell.EventPipeline.RunView</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>EventPipelineId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>EventPipelinePolicyRunId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>EntityTypeName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ItemName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ItemId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Status</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>QueuedDate</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>StartDate</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>EndDate</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
3 changes: 2 additions & 1 deletion src/Thycotic.SecretServer.psd1
Expand Up @@ -158,7 +158,8 @@
'Search-TssEventPipeline',
'Enable-TssEventPipeline',
'Disable-TssEventPipeline',
'Get-TssEventPipeline'
'Get-TssEventPipeline',
'Get-TssEventPipelineRun'
)
Description = 'PowerShell Tools for Thycotic Secret Server'
Guid = 'e6b56c5f-41ac-4ba4-8b88-2c063f683176'
Expand Down
27 changes: 27 additions & 0 deletions src/Thycotic.SecretServer/classes/event-pipeline/RunView.cs
@@ -0,0 +1,27 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using Thycotic.PowerShell.Enums;

namespace Thycotic.PowerShell.EventPipeline
{
public class RunView
{
public string Description { get; set; }
public string Duration { get; set; }
public DateTime? EndDate { get; set; }
public string EntityTypeName { get; set; }
public DateTime? EventDateTime { get; set; }
public string EventDetails { get; set; }
public string EventName { get; set; }
public int EventPipelineId { get; set; }
public string EventPipelinePolicyRunId { get; set; }
public int ItemId { get; set; }
public string ItemName { get; set; }
public string Name { get; set; }
public DateTime? QueuedDate { get; set; }
public DateTime? StartDate { get; set; }
public EventPipelineStatus Status { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Thycotic.SecretServer/enums/EventPipelineStatus.cs
@@ -0,0 +1,16 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.Enums
{
public enum EventPipelineStatus {
Failed,
Success,
Skipped,
Processing,
Pending,
Scheduled
}
}
74 changes: 74 additions & 0 deletions src/functions/event-pipeline/Get-TssEventPipelineRun.ps1
@@ -0,0 +1,74 @@
function Get-TssEventPipelineRun {
<#
.SYNOPSIS
Get all of the runs for an Event Pipeline
.DESCRIPTION
Get all of the runs for an Event Pipeline
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssEventPipelineRun -TssSession $session -Id 42
Outputs the Activity details for Event Pipeline 42
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/event-pipeline/Get-TssEventPipelineRun
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/event-pipeline/Get-TssEventPipelineRun.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.EventPipeline.RunView')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession,

# Short description for parameter
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias("EventPipelineId")]
[int[]]
$Id
)
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 ($pipeline in $Id) {
$restResponse = $null
$uri = $TssSession.ApiUrl, 'event-pipeline', 'runs' -join '/'
$uri = $uri, "sortBy[0].direction=asc&sortBy[0].name=eventPipelineId&take=$($TssSession.Take)" -join '?'

$uriFilter = "filter.eventPipelineId=$pipeline" -join '&'
$uri = $uri, $uriFilter -join '&'

$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "Performing the operation $($invokeParams.Method) $uri"
try {
$restResponse = . $InvokeApi @invokeParams
} catch {
Write-Warning "Issue getting Activity for Event Pipeline [$pipeline]"
$err = $_
. $ErrorHandling $err
}

if ($restResponse.records) {
[Thycotic.PowerShell.EventPipeline.RunView[]]$restResponse.records
}
}
} else {
Write-Warning "No valid session found"
}
}
}
7 changes: 3 additions & 4 deletions src/functions/event-pipeline/Search-TssEventPipeline.ps1
Expand Up @@ -69,7 +69,6 @@ function Search-TssEventPipeline {
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
$restResponse = $null
$uri = $TssSession.ApiUrl, 'event-pipeline', 'summaries' -join '/'
$uri = $uri, "sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?'

Expand All @@ -92,7 +91,7 @@ function Search-TssEventPipeline {
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "Performing the operation $($invokeParams.Method) $uri with $body"
Write-Verbose "Performing the operation $($invokeParams.Method) $uri"
try {
$restResponse = . $InvokeApi @invokeParams
} catch {
Expand All @@ -103,9 +102,9 @@ function Search-TssEventPipeline {

if ($restResponse.records) {
[Thycotic.PowerShell.EventPipeline.Summary[]]$restResponse.records
} else {
Write-Warning "No valid session found"
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/event-pipeline/Get-TssEventPipelineRun.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'Id'
[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 Thycotic.PowerShell.EventPipeline.RunView" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.EventPipeline.RunView'
}
}
}

0 comments on commit 80ff0c2

Please sign in to comment.