Skip to content

Commit

Permalink
Show-TssListCurrentUser - new command to retrieve the Lists the curre…
Browse files Browse the repository at this point in the history
…nt user session can access
  • Loading branch information
wsmelton committed Nov 6, 2021
1 parent 1d8bdba commit 05c32ef
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 17 deletions.
98 changes: 81 additions & 17 deletions .vscode/tss.code-snippets
Expand Up @@ -711,26 +711,90 @@
"tss basic begin": {
"prefix": "tssbegin",
"body": [
" [CmdletBinding()]",
" [OutputType('${1:Class name}')]",
" param (",
" # TssSession object created by New-TssSession for authentication",
" [Parameter(Mandatory, ValueFromPipeline, Position = 0)]",
" [Thycotic.PowerShell.Authentication.Session]",
" \\$TssSession,",
"[CmdletBinding()]",
"[OutputType('${1:Class name}')]",
"param (",
" # TssSession object created by New-TssSession for authentication",
" [Parameter(Mandatory, ValueFromPipeline, Position = 0)]",
" [Thycotic.PowerShell.Authentication.Session]",
" \\$TssSession,",
"",
" # ${2:Description}",
" [Parameter(Mandatory, ValueFromPipelineByPropertyName)]",
" [Alias('${3:Alias}')]",
" [int[]]",
" \\$${4:Parameter},",
")",
"begin {",
" \\$tssParams = \\$PSBoundParameters",
" \\$invokeParams = . \\$GetInvokeApiParams \\$TssSession",
"}"
],
"description": "tss basic begin"
},
"tss basic process": {
"prefix": "tssprocbasic",
"body": [
"process {",
" Get-TssInvocation \\$PSCmdlet.MyInvocation",
" if (\\$tssParams.ContainsKey('TssSession') -and \\$TssSession.IsValidSession()) {",
" Compare-TssVersion \\$TssSession '11.0.000005' \\$PSCmdlet.MyInvocation",
" \\$uri = \\$TssSession.ApiUrl, ${1:Endpoint} -join '/'",
" \\$invokeParams.Uri = \\$uri",
" \\$invokeParams.Method = '${2:METHOD}'",
"",
" # ${2:Description}",
" [Parameter(Mandatory, ValueFromPipelineByPropertyName)]",
" [Alias('${3:Alias}')]",
" [int[]]",
" \\$${4:Parameter},",
" )",
" begin {",
" \\$tssParams = \\$PSBoundParameters",
" \\$invokeParams = . \\$GetInvokeApiParams \\$TssSession",
" Write-Verbose \"Performing the operation \\$(\\$invokeParams.Method) \\$(\\$invokeParams.Uri)\"",
" try {",
" \\$apiResponse = Invoke-TssApi @invokeParams",
" \\$restResponse = . \\$ProcessResponse \\$apiResponse",
" } catch {",
" Write-Warning \"Issue getting ${3:object description}\"",
" \\$err = \\$_",
" . \\$ErrorHandling \\$err",
" }",
"",
" if (\\$restResponse) {",
" [${4:Class name}[]]\\$restResponse",
" }",
" } else {",
" Write-Warning \"No valid session found\"",
" }",
" }"
],
"description": "tss basic begin"
"description": "tss basic process"
},
"tss process foreach loop": {
"prefix": "tssprocforeach",
"body": [
"process {",
" Get-TssInvocation \\$PSCmdlet.MyInvocation",
" if (\\$tssParams.ContainsKey('TssSession') -and \\$TssSession.IsValidSession()) {",
" Compare-TssVersion \\$TssSession '11.0.000005' \\$PSCmdlet.MyInvocation",
" foreach (\\$${2:variable name} in \\$${1:Parameter Name}) {",
" \\$uri = \\$TssSession.ApiUrl, ${3:endpoint}, \\$${2} -join '/'",
" \\$invokeParams.Uri = \\$uri",
" \\$invokeParams.Method = '${4:METHOD}'",
"",
" Write-Verbose \"Performing the operation \\$(\\$invokeParams.Method) \\$(\\$invokeParams.Uri)\"",
" try {",
" \\$apiResponse = Invoke-TssApi @invokeParams",
" \\$restResponse = . \\$ProcessResponse \\$apiResponse",
" } catch {",
" Write-Warning \"Issue getting ${5:Object name} [\\$${2}]\"",
" \\$err = \\$_",
" . \\$ErrorHandling \\$err",
" }",
"",
" if (\\$restResponse) {",
" [${6:Class Name}[]]\\$restResponse",
" }",
" }",
" } else {",
" Write-Warning \"No valid session found\"",
" }",
" }"
],
"description": "tss process foreach loop"
},
"tss process block - body required": {
"prefix": "tssprocbody",
Expand Down
58 changes: 58 additions & 0 deletions docs/commands/lists/Show-TssListCurrentUser.md
@@ -0,0 +1,58 @@
# Show-TssListCurrentUser

## SYNOPSIS
Return a list of the Lists for the current user

## SYNTAX

```
Show-TssListCurrentUser [-TssSession] <Session> [<CommonParameters>]
```

## DESCRIPTION
Return a list of the Lists for the current user

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Show-TssListCurrentUser -TssSession $session
```

Returns the list of Lists the current connected user can access

## 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
```

### 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.SummaryList
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS

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

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

13 changes: 13 additions & 0 deletions src/Thycotic.SecretServer/classes/lists/SummaryList.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 SummaryList
{
public Guid CategorizedListId { get; set; }
public string Name { get; set;}
}
}
61 changes: 61 additions & 0 deletions src/functions/lists/Show-TssListCurrentUser.ps1
@@ -0,0 +1,61 @@
function Show-TssListCurrentUser {
<#
.SYNOPSIS
Return a list of the Lists for the current user
.DESCRIPTION
Return a list of the Lists for the current user
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Show-TssListCurrentUser -TssSession $session
Returns the list of Lists the current connected user can access
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/lists/Show-TssListCurrentUser
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/lists/Show-TssListCurrentUser.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.Lists.SummaryList')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory, ValueFromPipeline, Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
Get-TssInvocation $PSCmdlet.MyInvocation
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
Compare-TssVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'lists', 'summary' -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 current user's List"
$err = $_
. $ErrorHandling $err
}

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

0 comments on commit 05c32ef

Please sign in to comment.