Skip to content

Commit

Permalink
Search-SecretPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton authored May 30, 2021
1 parent c73537f commit b980a3d
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/collections/_abouttopics/about_tsssecretpolicy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
category: secret-policy
title: "TssSecretPolicy"
last_modified_at: 2021-05-30T00:00:00-00:00
---

# TOPIC
This help topic describes the TssSecretPolicy class in the Thycotic.SecretServer module

# CLASS
TssSecretPolicy

# INHERITANCE
None

# DESCRIPTION
The TssSecretPolicy class represents the SecretPolicyModel object returned by Secret Server endpoint GET /secret-policy/search

# CONSTRUCTORS
new()

# PROPERTIES
Active: boolean
Whether or not the Secret Policy is Active

SecretPolicyDescription: string
The Description of the Secret Policy

SecretPolicyId: integer (int32)
The Id of the Secret Policy

SecretPolicyName: string
The Name of the Secret Policy

# METHODS

# RELATED LINKS:
Search-TssSecretPolicy
33 changes: 33 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -1826,5 +1826,38 @@
</TableControl>
</View>

<!-- TssSecretPolicy -->
<View>
<Name>TssSecretPolicy</Name>
<ViewSelectedBy>
<TypeName>TssSecretPolicy</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
</TableColumnHeader>
<TableColumnHeader>
</TableColumnHeader>
<TableColumnHeader>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>SecretPolicyId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>SecretPolicyName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Active</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
13 changes: 13 additions & 0 deletions src/classes/secret-policy/TssSecretPolicy.class.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class TssSecretPolicy {
[boolean]
$Active

[string]
$SecretPolicyDescription

[int]
$SecretPolicyId

[string]
$SecretPolicyName
}
32 changes: 32 additions & 0 deletions src/en-us/about_tsssecretpolicy.help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
TOPIC
This help topic describes the TssSecretPolicy class in the Thycotic.SecretServer module

CLASS
TssSecretPolicy

INHERITANCE
None

DESCRIPTION
The TssSecretPolicy class represents the SecretPolicyModel object returned by Secret Server endpoint GET /secret-policy/search

CONSTRUCTORS
new()

PROPERTIES
Active: boolean
Whether or not the Secret Policy is Active

SecretPolicyDescription: string
The Description of the Secret Policy

SecretPolicyId: integer (int32)
The Id of the Secret Policy

SecretPolicyName: string
The Name of the Secret Policy

METHODS

RELATED LINKS:
Search-TssSecretPolicy
88 changes: 88 additions & 0 deletions src/functions/secret-policy/Search-SecretPolicy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
function Search-SecretPolicy {
<#
.SYNOPSIS
Search Secret Policies
.DESCRIPTION
Search Secret Policies
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/Search-TssSecretPolicy
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-policy/Search-SecretPolicy.ps1
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssSecretPolicy -TssSession $session -PolicyName 'heartbeat'
Search for Secret Policies with names matching "heartbeat"
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('TssSecretPolicy')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Secret Policy names (contains)
[string]
$PolicyName,

# Include inactive policies in search results
[switch]
$IncludeInactive,

# Sort by specific property, default SecretPolicyName
[string]
$SortBy = 'SecretPolicyName'
)
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, 'secret-policy', 'search' -join '/'
$uri = $uri, "sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?'
$invokeParams.Method = 'GET'

$filters = @()
switch ($tssParams.Keys) {
'PolicyName' { $filters += "filter.secretPolicyName=$PolicyName" }
'IncludeInactive' { $filters += "filter.includeInactive=$([boolean]$IncludeInactive)" }
}
if ($filters) {
$uriFilter = $filters -join '&'
Write-Verbose "Filters: $uriFilter"
$uri = $uri, $uriFilter -join '&'
}
$invokeParams.Uri = $uri

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 SecretPolicy found"
}
if ($restResponse.records) {
[TssSecretPolicy[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/secret-policy/Search-SecretPolicy.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'PolicyName', 'IncludeInactive', '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 TssSecretPolicy" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'TssSecretPolicy'
}
}
}

0 comments on commit b980a3d

Please sign in to comment.