Skip to content

Commit

Permalink
Get-TssListCategory - new command to return the categories on a List
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Oct 22, 2021
1 parent 7310b22 commit d3cce97
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 0 deletions.
81 changes: 81 additions & 0 deletions docs/commands/lists/Get-TssListCategory.md
@@ -0,0 +1,81 @@
# Get-TssListCategory

## SYNOPSIS
Return a list of categories availabe for the provided List ID

## SYNTAX

```
Get-TssListCategory [-TssSession] <Session> -Id <String[]> [<CommonParameters>]
```

## DESCRIPTION
Return a list of categories availabe for the provided List ID

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssListCategory -TssSession $session -Id df0b8746-581f-4ac2-a9b2-5a2b7a679f3e
```

Return categories for the provided ID

### EXAMPLE 2
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssList -TssSession $session -SearchText "Servers" | Get-TssListCategory -TssSession $session
```

Return categories for Lists with the name "Servers"

## PARAMETERS

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

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

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

### -Id
Short description for parameter

```yaml
Type: String[]
Parameter Sets: (All)
Aliases: CategorizedListId

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
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

### Thycotic.PowerShell.Lists.Category
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/lists/Get-TssListCategory](https://thycotic-ps.github.io/thycotic.secretserver/commands/lists/Get-TssListCategory)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/lists/Get-TssListCategory.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/lists/Get-TssListCategory.ps1)

13 changes: 13 additions & 0 deletions src/Thycotic.SecretServer/classes/lists/Category.cs
@@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.Lists
{
public class Category
{
public string CategorizedListId { get; set; }
public string CategoryName { get; set; }
}
}
80 changes: 80 additions & 0 deletions src/functions/lists/Get-TssListCategory.ps1
@@ -0,0 +1,80 @@
function Get-TssListCategory {
<#
.SYNOPSIS
Return a list of categories availabe for the provided List ID
.DESCRIPTION
Return a list of categories availabe for the provided List ID
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssListCategory -TssSession $session -Id df0b8746-581f-4ac2-a9b2-5a2b7a679f3e
Return categories for the provided ID
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssList -TssSession $session -SearchText "Servers" | Get-TssListCategory -TssSession $session
Return categories for Lists with the name "Servers"
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/lists/Get-TssListCategory
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/lists/Get-TssListCategory.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.Lists.Category')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession,

# Short description for parameter
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias('CategorizedListId')]
[string[]]
$Id
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
Compare-TssVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
foreach ($list in $Id) {
$uri = $TssSession.ApiUrl, 'lists', $list, 'categories' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "Performing the operation $($invokeParams.Method) $($invokeParams.Uri)"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting List [$list] categories"
$err = $_
. $ErrorHandling $err
}

if ($restResponse.records) {
foreach ($record in $restResponse.records) {
[Thycotic.PowerShell.Lists.Category]@{
CategorizedListId = $list
CategoryName = $record
}
}
}
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/lists/Get-TssListCategory.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'Id'
[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 Thycotic.PowerShell.Lists.Category" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.Lists.Category'
}
}
}

0 comments on commit d3cce97

Please sign in to comment.