Skip to content

Commit

Permalink
Search-WorkflowTemplate - new command
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Jun 11, 2021
1 parent 535eb9d commit 7a510d0
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Expand Up @@ -1891,5 +1891,47 @@
</TableControl>
</View>

<!-- TssWorkflowTemplateDetail -->
<View>
<Name>TssWorkflowTemplateDetail</Name>
<ViewSelectedBy>
<TypeName>TssWorkflowTemplateDetail</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>WorkflowTemplateId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>WorkflowType</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Description</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Active</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ExpirationMinutes</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
29 changes: 29 additions & 0 deletions src/classes/workflow-templates/TssWorkflowTemplateDetail.class.ps1
@@ -0,0 +1,29 @@
class TssWorkflowTemplateDetail {
[boolean]
$Active

[string]
$ConfigurationJson

[string]
$Description

[int]
$ExpirationMinutes

[string]
$Name

[boolean]
$Reusable

[string]
$TypeName

[int]
$WorkflowTemplateId

[ValidateSet('AccessRequest')]
[string]
$WorkflowType
}
47 changes: 47 additions & 0 deletions src/en-us/about_tssworkflowtemplatedetail.help.txt
@@ -0,0 +1,47 @@
TOPIC
This help topic describes the TssWorkflowTemplateDetail class in the Thycotic.SecretServer module

CLASS
TssWorkflowTemplateDetail

INHERITANCE
None

DESCRIPTION
The TssWorkflowTemplateDetail class represents the WorkflowTemplateDetailModel object returned by Secret Server endpoint GET /workflows/templates

CONSTRUCTORS
new()

PROPERTIES
Active: boolean
Active

ConfigurationJson: string
ConfigurationJson

Description: string
Description

ExpirationMinutes: integer (int32)
ExpirationMinutes

Name: string
Name

Reusable: boolean
Reusable

TypeName: string
TypeName

WorkflowTemplateId: integer (int32)
WorkflowTemplateId

WorkflowType: string
WorkflowType (AccessRequest)

METHODS

RELATED LINKS:
Search-TssWorkflowTemplate
80 changes: 80 additions & 0 deletions src/functions/workflow-templates/Search-WorkflowTemplate.ps1
@@ -0,0 +1,80 @@
function Search-WorkflowTemplate {
<#
.SYNOPSIS
Search Workflow Templates
.DESCRIPTION
Search Workflow Templates
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/Search-TssWorkflowTemplate
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/workflows/Search-WorkflowTemplate.ps1
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssWorkflowTemplate -TssSession $session -IncludeInactive
Search Workflow Templates and return those that are inactive in the results
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('TssWorkflowTemplateDetail')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Include inactive workflows
[switch]
$IncludeInactive,

# Workflow Type, default to AccessRequest (only type available at this time)
[Parameter()]
[ValidateSet('AccessRequest')]
[string]
$Type = 'AccessRequest',

# Sort by specific property, default Name
[string]
$SortBy = 'Name'
)
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
$restResponse = $null
$uri = $TssSession.ApiUrl, 'workflows', 'templates' -join '/'
$uri = $uri, "sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?'
$uri = $uri, "filter.includeInactive=$([boolean]$IncludeInactive)", "filter.workflowType=$Type" -join '&'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "Performing the operation $($invokeParams.Method) $uri"
try {
$restResponse = . $InvokeApi @invokeParams
} catch {
Write-Warning "Issue on search request"
$err = $_
. $ErrorHandling $err
}

if ($restResponse.records.Count -le 0 -and $restResponse.records.Length -eq 0) {
Write-Warning "No Workflow(s) found"
}
if ($restResponse.records) {
[TssWorkflowTemplateDetail[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/workflow-templates/Search-WorkflowTemplate.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'IncludeInactive', 'Type', 'SortBy'
[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 TssWorkflowTemplateDetail" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'TssWorkflowTemplateDetail'
}
}
}

0 comments on commit 7a510d0

Please sign in to comment.