Skip to content

Commit

Permalink
Search-TssRpcPasswordType - closes #149
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Apr 26, 2021
1 parent b7e96f1 commit 5f99639
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/_data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ abouttopics:

- title: "RPC"
children:
- title: "TssPasswordTypeSummary"
url: /abouttopics/about_tsspasswordtypesummary
- title: "TssSecretRpcAssociated"
url: /abouttopics/about_tsssecretrpcassociated

Expand Down
65 changes: 65 additions & 0 deletions docs/collections/_abouttopics/about_tsspasswordtypesummary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
category: rpc, secrets
title: "TssPasswordTypeSummary"
last_modified_at: 2021-04-25T00:00:00-00:00
---

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

# CLASS
TssPasswordTypeSummary

# INHERITANCE
None

# DESCRIPTION
The TssPasswordTypeSummary class represents the PasswordTypeSummary object returned by Secret Server endpoint GET /remote-password-changing/password-types

# CONSTRUCTORS
new()

# PROPERTIES
Active: boolean
Whether the Password Type is Active

CanEdit: boolean
Whether the Password Type can be edited

HasCommands: boolean
Whether Commands Exist

HeartbeatScriptId: integer (int32)
Heartbeat Script Id

IgnoreSSL: boolean
Whether Password Type ignores SSL warnings

IsWeb: boolean
Whether Is Web

Name: string
Password Type Name

PasswordTypeId: integer (int32)
Password Type Id

RequiredEdition: string
Required Edition (Standard, Legacy)

RpcScriptId: integer (int32)
RPC Script Id

RunnerType: RunnerType
Runner Type

ScanItemTemplateId: integer (int32)
Scan Template Id

UseSSL: boolean
Whether Password Type uses SSL

# METHODS

# RELATED LINKS:
Search-TssRpcPasswordType
3 changes: 3 additions & 0 deletions docs/collections/_pages/abouttopics.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ About topics cover the [PowerShell classes](https://docs.microsoft.com/en-us/pow

**Class** | **Thycotic.SecretServer Command** |
--------------------------------- | -------------------------------------------------- |
[TssPasswordTypeSummary] | [Search-TssRpcPasswordType]
[TssSecretRpcAssociated] | [Get-TssSecretRpcAssociated]

## Secret Templates
Expand Down Expand Up @@ -186,7 +187,9 @@ About topics cover the [PowerShell classes](https://docs.microsoft.com/en-us/pow
[Get-TssConfiguration]:/thycotic.secretserver/commands/Get-TssConfiguration
[Get-TssDistributedEngineSite]:/thycotic.secretserver/commands/Get-TssDistributedEngineSite
[Get-TssSecretRpcAssociated]:/thycotic.secretserver/commands/Get-TssSecretRpcAssociated
[Search-TssRpcPasswordType]:/thycotic.secretserver/commands/Search-TssRpcPasswordType

[TssPasswordTypeSummary]:/thycotic.secretserver/abouttopics/about_tsspasswordtypesumamry
[TssSecretRpcAssociated]:/thycotic.secretserver/abouttopics/about_tsssecretrpcassociated
[TssSiteSummary]:/thycotic.secretserver/abouttopics/about_tsssitesummary
[TssSiteMetrics]:/thycotic.secretserver/abouttopics/about_tsssitemetrics
Expand Down
40 changes: 40 additions & 0 deletions src/classes/rpc/TssPasswordTypeSummary.class.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class TssPasswordTypeSummary {
[boolean]
$Active

[boolean]
$CanEdit

[boolean]
$HasCommands

[int]
$HeartbeatScriptId

[boolean]
$IgnoreSsl

[boolean]
$IsWeb

[string]
$Name

[int]
$PasswordTypeId

[string]
$RequiredEdition

[int]
$RpcScriptId

[string]
$RunnerType

[int]
$ScanItemTemplateId

[boolean]
$UseSsl
}
59 changes: 59 additions & 0 deletions src/en-us/about_tsspasswordtypesummary.help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
TOPIC
This help topic describes the TssPasswordTypeSummary class in the Thycotic.SecretServer module

CLASS
TssPasswordTypeSummary

INHERITANCE
None

DESCRIPTION
The TssPasswordTypeSummary class represents the PasswordTypeSummary object returned by Secret Server endpoint GET /remote-password-changing/password-types

CONSTRUCTORS
new()

PROPERTIES
Active: boolean
Whether the Password Type is Active

CanEdit: boolean
Whether the Password Type can be edited

HasCommands: boolean
Whether Commands Exist

HeartbeatScriptId: integer (int32)
Heartbeat Script Id

IgnoreSSL: boolean
Whether Password Type ignores SSL warnings

IsWeb: boolean
Whether Is Web

Name: string
Password Type Name

PasswordTypeId: integer (int32)
Password Type Id

RequiredEdition: string
Required Edition (Standard, Legacy, Null)

RpcScriptId: integer (int32)
RPC Script Id

RunnerType: RunnerType
Runner Type

ScanItemTemplateId: integer (int32)
Scan Template Id

UseSSL: boolean
Whether Password Type uses SSL

METHODS

RELATED LINKS:
Search-TssRpcPasswordType
92 changes: 92 additions & 0 deletions src/functions/secrets/Search-RpcPasswordType.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
function Search-RpcPasswordType {
<#
.SYNOPSIS
List available Password Types
.DESCRIPTION
List available Password Types
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/Search-TssRpcPasswordType
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secrets/Search-RpcPasswordType.ps1
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssRpcPasswordType -TssSession $session -SearchTerm Directory -IncludeInactive
List Password Types that are inactive and have "Directory" in the name
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('TssPasswordTypeSummary')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Search based on text in Name
[Alias("SearchTerm")]
[string]
$SearchText,

# Include inactive objects
[boolean]
$IncludeInactive,

# 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, 'remote-password-changing', 'password-types' -join '/'
$uri = $uri, "sortBy[0].direction=asc&sortBy[0].name=$SortBy&take=$($TssSession.Take)" -join '?'

$filters = @()
if ($tssParams.ContainsKey('SearchText')) {
$filters += "filter.searchTerm=$SearchText"
}
if ($tssParams.ContainsKey('IncludeInactive')) {
$filters += "filter.includeInactive=$([boolean]$IncludeInactive)"
}
if ($filters) {
$uriFilter = $filters -join '&'
Write-Verbose "Filters: $uriFilter"
$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 on search request"
$err = $_
. $ErrorHandling $err
}

if ($restResponse.records.Count -le 0 -and $restResponse.records.Length -eq 0) {
Write-Warning "No RpcPasswordType found"
}
if ($restResponse.records) {
[TssPasswordTypeSummary[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
}
}
}
102 changes: 102 additions & 0 deletions tests/rpc/Search-RpcPasswordType.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
. ([IO.Path]::Combine([string]$PSScriptRoot, '..', 'constants.ps1'))
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'SearchText', '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 TssPasswordTypeSummary" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'TssPasswordTypeSummary'
}
}
}
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.000000'
}
}
}

Mock -Verifiable -CommandName Invoke-RestMethod -ParameterFilter { $Uri -match '/remote-password-changing/password-types' } -MockWith {
return [pscustomobject]@{
records = @(
[pscustomobject]@{
active = $true
canEdit = $false
hasCommands = $false
heartbeatScriptId = 0
ignoreSSL = $false
isWeb = $false
name = "Password Type 1"
passwordTypeId = 1
requiredEdition = $null
rpcScriptId = 1
runnerType = 'Standard'
scanItemTemplateId = 1
useSSL = $false
}
[pscustomobject]@{
active = $true
canEdit = $false
hasCommands = $false
heartbeatScriptId = 0
ignoreSSL = $false
isWeb = $false
name = "Password Type 2"
passwordTypeId = 2
requiredEdition = $null
rpcScriptId = 1
runnerType = 'Standard'
scanItemTemplateId = 1
useSSL = $false
}
)
}
}
$object = Search-RpcPasswordType -TssSession $session -SearchText 'Password'
Assert-VerifiableMock
}
It "Should not be empty" {
$object | Should -Not -BeNullOrEmpty
}
It "Should contain 2 records" {
$object.Count | Should -Be 2
}
It "Should have property <_>" -TestCases 'Active', 'Name' {
$object[0].PSObject.Properties.Name | Should -Contain $_
}
It "Should have property Name equal 'Password Type 1'" {
$object[0].Name | Should -Be 'Password Type 1'
}
It "Should have called Invoke-RestMethod 2 times" {
Assert-MockCalled -CommandName Invoke-RestMethod -Times 2 -Scope Describe
}
}
}

0 comments on commit 5f99639

Please sign in to comment.