-
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.
Get-TssSecretWebTemplate - new command to check Web Templates availab…
…le, endpoint used by WPF
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
docs/commands/secret-extensions/Get-TssSecretWebTemplate.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,58 @@ | ||
# Get-TssSecretWebTemplate | ||
|
||
## SYNOPSIS | ||
Get a list of Secret Templates valid for Web Password Filler | ||
|
||
## SYNTAX | ||
|
||
``` | ||
Get-TssSecretWebTemplate [-TssSession] <Session> [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
Get a list of Secret Templates valid for Web Password Filler | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
``` | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Get-TssSecretWebTemplate -TssSession $session | ||
``` | ||
|
||
Return list of Secret Templates that can be used by Web Password Filler | ||
|
||
## 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.SecretTemplates.Template | ||
## NOTES | ||
Requires TssSession object returned by New-TssSession | ||
## RELATED LINKS | ||
[https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-extensions/Get-TssSecretWebTemplate](https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-extensions/Get-TssSecretWebTemplate) | ||
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-extensions/Get-TssSecretWebTemplate.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-extensions/Get-TssSecretWebTemplate.ps1) | ||
61 changes: 61 additions & 0 deletions
61
src/functions/secret-extensions/Get-TssSecretWebTemplate.ps1
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,61 @@ | ||
function Get-TssSecretWebTemplate { | ||
<# | ||
.SYNOPSIS | ||
Get a list of Secret Templates valid for Web Password Filler | ||
.DESCRIPTION | ||
Get a list of Secret Templates valid for Web Password Filler | ||
.EXAMPLE | ||
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred | ||
Get-TssSecretWebTemplate -TssSession $session | ||
Return list of Secret Templates that can be used by Web Password Filler | ||
.LINK | ||
https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-extensions/Get-TssSecretWebTemplate | ||
.LINK | ||
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-extensions/Get-TssSecretWebTemplate.ps1 | ||
.NOTES | ||
Requires TssSession object returned by New-TssSession | ||
#> | ||
[CmdletBinding()] | ||
[OutputType('Thycotic.PowerShell.SecretTemplates.Template')] | ||
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 '10.9.000064' $PSCmdlet.MyInvocation | ||
$uri = $TssSession.ApiUrl, 'secret-extensions', 'web-secret-templates' -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 Secret Templates for web passwords" | ||
$err = $_ | ||
. $ErrorHandling $err | ||
} | ||
|
||
if ($restResponse.records) { | ||
[Thycotic.PowerShell.SecretTemplates.Template[]]$restResponse.records | ||
} | ||
} else { | ||
Write-Warning "No valid session found" | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/secret-extensions/Get-TssSecretWebTemplate.Tests.ps1
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,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.SecretTemplates.Template" -TestCases $commandDetails { | ||
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.SecretTemplates.Template' | ||
} | ||
} | ||
} |