-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search-TssRpcPasswordType - closes #149
- Loading branch information
Showing
7 changed files
with
363 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
docs/collections/_abouttopics/about_tsspasswordtypesummary.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |