From ab76896845023cab4c99fc00e2407988afbf48c6 Mon Sep 17 00:00:00 2001 From: Shawn Melton <11204251+wsmelton@users.noreply.github.com> Date: Sun, 5 Sep 2021 20:00:39 -0500 Subject: [PATCH] Get-TssSecretPolicyStub - new command --- .../Get-TssSecretPolicyStub.md | 58 ++++++++++++++++++ .../Get-TssSecretPolicyStub.ps1 | 61 +++++++++++++++++++ .../Get-TssSecretPolicyStub.Tests.ps1 | 24 ++++++++ 3 files changed, 143 insertions(+) create mode 100644 docs/commands/secret-policies/Get-TssSecretPolicyStub.md create mode 100644 src/functions/secret-policies/Get-TssSecretPolicyStub.ps1 create mode 100644 tests/secret-policies/Get-TssSecretPolicyStub.Tests.ps1 diff --git a/docs/commands/secret-policies/Get-TssSecretPolicyStub.md b/docs/commands/secret-policies/Get-TssSecretPolicyStub.md new file mode 100644 index 00000000..45f78900 --- /dev/null +++ b/docs/commands/secret-policies/Get-TssSecretPolicyStub.md @@ -0,0 +1,58 @@ +# Get-TssSecretPolicyStub + +## SYNOPSIS +Get a stub object of a Secret Policy + +## SYNTAX + +``` +Get-TssSecretPolicyStub [-TssSession] [] +``` + +## DESCRIPTION +Get a stub object of a Secret Policy + +## EXAMPLES + +### EXAMPLE 1 +``` +$session = New-TssSession -SecretServer https://alpha -Credential $ssCred +Get-TssSecretPolicyStub -TssSession $session +``` + +Return an empty Secret Policy object + +## 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.SecretPolicies.Policy +## NOTES +Requires TssSession object returned by New-TssSession + +## RELATED LINKS + +[https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-policies/Get-TssSecretPolicyStub](https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-policies/Get-TssSecretPolicyStub) + +[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-policies/Get-TssSecretPolicyStub.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-policies/Get-TssSecretPolicyStub.ps1) + diff --git a/src/functions/secret-policies/Get-TssSecretPolicyStub.ps1 b/src/functions/secret-policies/Get-TssSecretPolicyStub.ps1 new file mode 100644 index 00000000..452bbb9c --- /dev/null +++ b/src/functions/secret-policies/Get-TssSecretPolicyStub.ps1 @@ -0,0 +1,61 @@ +function Get-TssSecretPolicyStub { + <# + .SYNOPSIS + Get a stub object of a Secret Policy + + .DESCRIPTION + Get a stub object of a Secret Policy + + .EXAMPLE + $session = New-TssSession -SecretServer https://alpha -Credential $ssCred + Get-TssSecretPolicyStub -TssSession $session + + Return an empty Secret Policy object + + .LINK + https://thycotic-ps.github.io/thycotic.secretserver/commands/secret-policies/Get-TssSecretPolicyStub + + .LINK + https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/secret-policies/Get-TssSecretPolicyStub.ps1 + + .NOTES + Requires TssSession object returned by New-TssSession + #> + [CmdletBinding()] + [OutputType('Thycotic.PowerShell.SecretPolicies.Policy')] + 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 { + Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)" + if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) { + . $CheckVersion $TssSession '11.0.000005' $PSCmdlet.MyInvocation + $uri = $TssSession.ApiUrl, 'secret-policy', 'stub' -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 Policy stub" + $err = $_ + . $ErrorHandling $err + } + + if ($restResponse) { + [Thycotic.PowerShell.SecretPolicies.Policy[]]$restResponse + } + } else { + Write-Warning "No valid session found" + } + } +} \ No newline at end of file diff --git a/tests/secret-policies/Get-TssSecretPolicyStub.Tests.ps1 b/tests/secret-policies/Get-TssSecretPolicyStub.Tests.ps1 new file mode 100644 index 00000000..cb43812e --- /dev/null +++ b/tests/secret-policies/Get-TssSecretPolicyStub.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.SecretPolicies.Policy" -TestCases $commandDetails { + $_.OutputType.Name | Should -Be 'Thycotic.PowerShell.SecretPolicies.Policy' + } + } +} \ No newline at end of file