Skip to content

Commit

Permalink
Find-Report - new command
Browse files Browse the repository at this point in the history
fixes #3
  • Loading branch information
wsmelton committed Jul 3, 2021
1 parent bf80e3c commit 9087705
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 2 deletions.
30 changes: 30 additions & 0 deletions docs/about_topics/reports/about_tssreportlookup.md
@@ -0,0 +1,30 @@
---
title: "TssReportLookup"
---

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

# CLASS
TssReportLookup

# INHERITANCE
None

# DESCRIPTION
The TssReportLookup class represents the ReportLookup object returned by Secret Server endpoint GET /reports/lookup.

# CONSTRUCTORS
new()

# PROPERTIES
Id: integer (int32)
Report ID

Value: string
Report name

# METHODS

# RELATED LINKS:
Find-TssReport
127 changes: 127 additions & 0 deletions docs/commands/reports/Find-TssReport.md
@@ -0,0 +1,127 @@
# Find-TssReport

## SYNOPSIS
Find a report.

## SYNTAX

```
Find-TssReport [-TssSession] <TssSession> [-CategoryId <Int32>] [-IncludeInactive] [-Name <String>]
[-SearchText <String>] [<CommonParameters>]
```

## DESCRIPTION
Find a report.

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Find-TssReport -TssSession $session -CategoryId 1234
```

Return a list of Reports found in Category ID 1234.

### EXAMPLE 2
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Find-TssReport -TssSession $session -SearchText secret
```

Return a list of Reports found with "secret" in the name.

## PARAMETERS

### -TssSession
TssSession object created by New-TssSession for auth

```yaml
Type: TssSession
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -CategoryId
Category ID tp search

```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
```

### -IncludeInactive
Include Inactive Reports

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```

### -Name
Name of Report

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -SearchText
Search text

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

## OUTPUTS

### TssReportLookup
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/Find-TssReport](https://thycotic-ps.github.io/thycotic.secretserver/commands/Find-TssReport)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/reports/Find-Report.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/reports/Find-Report.ps1)

27 changes: 27 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Expand Up @@ -1971,5 +1971,32 @@
</TableControl>
</View>


<!-- TssReportLookup -->
<View>
<Name>TssReportLookup</Name>
<ViewSelectedBy>
<TypeName>TssReportLookup</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>ReportName</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
9 changes: 9 additions & 0 deletions src/Thycotic.SecretServer.Types.ps1xml
Expand Up @@ -250,4 +250,13 @@
</AliasProperty>
</Members>
</Type>
<Type>
<Name>TssReportLookup</Name>
<Members>
<AliasProperty>
<Name>ReportName</Name>
<ReferencedMemberName>Value</ReferencedMemberName>
</AliasProperty>
</Members>
</Type>
</Types>
7 changes: 7 additions & 0 deletions src/classes/reports/TssReportLookup.class.ps1
@@ -0,0 +1,7 @@
class TssReportLookup {
[int]
$Id

[string]
$Value
}
26 changes: 26 additions & 0 deletions src/en-us/about_tssreportlookup.help.txt
@@ -0,0 +1,26 @@
TOPIC
This help topic describes the TssReportLookup class in the Thycotic.SecretServer module

CLASS
TssReportLookup

INHERITANCE
None

DESCRIPTION
The TssReportLookup class represents the ReportLookup object returned by Secret Server endpoint GET /reports/lookup.

CONSTRUCTORS
new()

PROPERTIES
Id: integer (int32)
Report ID

Value: string
Report name

METHODS

RELATED LINKS:
Find-TssReport
102 changes: 102 additions & 0 deletions src/functions/reports/Find-Report.ps1
@@ -0,0 +1,102 @@
function Find-Report {
<#
.SYNOPSIS
Find a report.
.DESCRIPTION
Find a report.
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Find-TssReport -TssSession $session -CategoryId 1234
Return a list of Reports found in Category ID 1234.
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Find-TssReport -TssSession $session -SearchText secret
Return a list of Reports found with "secret" in the name.
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/Find-TssReport
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/reports/Find-Report.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('TssReportLookup')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory, ValueFromPipeline, Position = 0)]
[TssSession]
$TssSession,

# Category ID tp search
[int]
$CategoryId,

# Include Inactive Reports
[switch]
$IncludeInactive,

# Name of Report
[string]
$Name,

# Search text
[string]
$SearchText
)
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
$uri = $TssSession.ApiUrl, 'reports', 'lookup' -join '/'
$uri = $uri, "&take=$($TssSession.Take)" -join '?'
$invokeParams.Method = 'GET'

$filters = @()
switch ($tssParams.Keys) {
'CategoryId' {
$filters += "filter.categoryId=$CategoryId"
}
'IncludeInactive' {
$filters += "filter.includeInactive=$([boolean]$IncludeInactive)"
}
'Name' {
$filters += "filter.reportName=$Name"
}
'SearchText' {
$filters += "filter.searchText=$SearchText"
}
}
$uriFilter = $filters -join '&'
Write-Verbose "Filters: $uriFilter"
$uri = $uri, $uriFilter -join '&'

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

if ($restResponse.records) {
[TssReportLookup[]]$restResponse.records
}
} else {
Write-Warning 'No valid session found'
}
}
}
2 changes: 0 additions & 2 deletions src/functions/secrets/Find-Secret.ps1
Expand Up @@ -241,9 +241,7 @@ function Find-Secret {
$uri = $uri, $uriFilter -join '&'
}


$invokeParams.Uri = $uri

$invokeParams.Method = 'GET'
Write-Verbose "$($invokeParams.Method) $uri"
try {
Expand Down
24 changes: 24 additions & 0 deletions tests/reports/Find-Report.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'CategoryId', 'IncludeInactive', 'Name', 'SearchText', '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 TssReportLookup" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'TssReportLookup'
}
}
}

0 comments on commit 9087705

Please sign in to comment.