Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
284 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
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,10 @@ | ||
class TssReportCategory { | ||
# Category Id | ||
[int]$ReportCategoryId = -1 | ||
# Category name | ||
[string]$ReportCategoryName | ||
# Category description | ||
[string]$ReportCategoryDescription | ||
# Sort Order of category appearance | ||
[int]$SortOrder | ||
} |
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,22 @@ | ||
TOPIC | ||
This help topic describes the TssReportCategory class in the Thycotic.SecretServer module | ||
|
||
CLASS | ||
TssReportCategory | ||
|
||
INHERITANCE | ||
None | ||
|
||
DESCRIPTION | ||
The TssReportCategory class represents the ReportCategory object returned by Secret Server endpoint /reports/categories | ||
|
||
CONSTRUCTORS | ||
new() | ||
|
||
PROPERTIES | ||
Documented in the REST API doc for Secret Server, see ReportCategory definition | ||
|
||
METHODS | ||
|
||
RELATED LINKS: | ||
Get-TssReportCategory |
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,109 @@ | ||
function Get-TssReportCategory { | ||
<# | ||
.SYNOPSIS | ||
Get report categories | ||
.DESCRIPTION | ||
Get a report category by Id or list all | ||
.EXAMPLE | ||
PS C:\> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
PS C:\> Get-TssReportCategory -TssSession $session -Id 26 | ||
Returns Report Category details for 26 | ||
.EXAMPLE | ||
PS C:\> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
PS C:\> Get-TssReportCategory -TssSession $session | ||
Returns a list of all categories | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[CmdletBinding()] | ||
[OutputType('TssReportCategory')] | ||
param ( | ||
# TssSession object created by New-TssSession for auth | ||
[Parameter(Mandatory, | ||
ValueFromPipeline, | ||
Position = 0)] | ||
[TssSession]$TssSession, | ||
|
||
# Report Category Id, returns all if not provided | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[Alias("ReportCategoryId")] | ||
[int[]] | ||
$Id, | ||
|
||
# Return list of all categories | ||
[Parameter()] | ||
[switch] | ||
$All, | ||
|
||
# Output the raw response from the API endpoint | ||
[switch] | ||
$Raw | ||
) | ||
begin { | ||
$tssParams = . $GetParams $PSBoundParameters 'Get-TssReportCategory' | ||
$invokeParams = @{ } | ||
} | ||
|
||
process { | ||
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" | ||
if ($tssParams.Contains('TssSession') -and $TssSession.IsValidSession()) { | ||
if ($tssParams['Id']) { | ||
foreach ($reportCategory in $Id) { | ||
$restResponse = $null | ||
$uri = $TssSession.ApiUrl, 'reports/categories', $reportCategory.ToString() -join '/' | ||
$invokeParams.Uri = $uri | ||
$invokeParams.Method = 'GET' | ||
|
||
$invokeParams.PersonalAccessToken = $TssSession.AccessToken | ||
Write-Verbose "$($invokeParams.Method) $uri" | ||
try { | ||
$restResponse = Invoke-TssRestApi @invokeParams | ||
} catch { | ||
Write-Warning "Issue getting details on [$reportCategory]" | ||
$err = $_.ErrorDetails.Message | ||
Write-Error $err | ||
} | ||
|
||
if ($tssParams['Raw']) { | ||
return $restResponse | ||
} | ||
if ($restResponse) { | ||
. $GetTssReportCategoryObject $restResponse | ||
} | ||
} | ||
} | ||
if ($tssParams['All']) { | ||
$restResponse = $null | ||
$uri = $TssSession.ApiUrl, 'reports/categories' -join '/' | ||
$invokeParams.Uri = $uri | ||
$invokeParams.Method = 'GET' | ||
|
||
$invokeParams.PersonalAccessToken = $TssSession.AccessToken | ||
Write-Verbose "$($invokeParams.Method) $uri" | ||
try { | ||
$restResponse = Invoke-TssRestApi @invokeParams | ||
} catch { | ||
Write-Warning "Issue getting details on [$reportCategory]" | ||
$err = $_.ErrorDetails.Message | ||
Write-Error $err | ||
} | ||
|
||
if ($tssParams['Raw']) { | ||
return $restResponse | ||
} | ||
if ($restResponse) { | ||
. $GetTssReportCategoryObject $restResponse.model -All:$All | ||
} | ||
|
||
} | ||
} 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,40 @@ | ||
<# | ||
.Synopsis | ||
Creates a TssReportCategory class in the Thycotic.SecretServer module. | ||
.Description | ||
Creates an instance of the TssReportCategory class to output the ReportCategory object | ||
#> | ||
param( | ||
[pscustomobject]$Object, | ||
[switch]$All | ||
) | ||
|
||
begin { | ||
$Properties = $Object[0].PSObject.Properties.Name | ||
} | ||
|
||
process { | ||
$outObject = @() | ||
foreach ($s in $Object) { | ||
$outCat = [TssReportCategory]::new() | ||
if ($PSBoundParameters['All']) { | ||
foreach ($sProp in $Properties) { | ||
switch ($sProp) { | ||
'Id' { $outCat.ReportCategoryId = $s.$sProp } | ||
'Name' { $outCat.ReportCategoryName = $s.$sProp } | ||
'Description' { $outCat.ReportCategoryDescription = $s.$sProp } | ||
} | ||
} | ||
} else { | ||
foreach ($sProp in $Properties) { | ||
if ($sProp -in $outCat.PSObject.Properties.Name) { | ||
$outCat.$sProp = $s.$sProp | ||
} else { | ||
Write-Warning "Property $sProp does not exist in the TssReportCategory class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose" | ||
} | ||
} | ||
} | ||
$outObject += $outCat | ||
} | ||
return $outObject | ||
} |
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,53 @@ | ||
BeforeDiscovery { | ||
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf | ||
. ([IO.Path]::Combine([string]$PSScriptRoot, '..', 'constants.ps1')) | ||
} | ||
Describe "$commandName verify parameters" { | ||
BeforeDiscovery { | ||
[object[]]$knownParameters = 'TssSession', 'Id', 'All', 'Raw' | ||
[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 parmaeters" -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 TssReportCategory" -TestCases $commandDetails { | ||
$_.OutputType.Name | Should -Be 'TssReportCategory' | ||
} | ||
} | ||
} | ||
Describe "$commandName works" { | ||
BeforeDiscovery { | ||
$session = New-TssSession -SecretServer $ss -Credential $ssCred | ||
$objectId = Get-TssReportCategory -TssSession $session -Id 4 | ||
$objectAll = Get-TssReportCategory -TssSession $session -All | ||
$session.SessionExpire() | ||
$props = 'CategoryId', 'Name', 'Description' | ||
} | ||
Context "Checking Id" -Foreach @{object = $objectId} { | ||
It "Should not be empty" { | ||
$object | Should -Not -BeNullOrEmpty | ||
} | ||
It "Should output <_> property" -TestCases $props { | ||
$object.PSObject.Properties.Name | Should -Contain $_ | ||
} | ||
} | ||
Context "Checking All" -Foreach @{object = $objectAll} { | ||
It "Should not be empty" { | ||
$object | Should -Not -BeNullOrEmpty | ||
} | ||
It "Should contain more than one object" { | ||
$object.Count | Should -BeGreaterThan 1 | ||
} | ||
It "Should output <_> property" -TestCases $props { | ||
$object[0].PSObject.Properties.Name | Should -Contain $_ | ||
} | ||
} | ||
} |