Skip to content

Commit

Permalink
Get-TssSecretState - closes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Mar 4, 2021
1 parent af9e621 commit 357df13
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/classes/secrets/TssSecretDetailState.class.ps1
@@ -0,0 +1,56 @@
class TssSecretDetailState {
[string[]]
$Actions

[string]
$CheckedOutUserDisplayName

[int]
$CheckedOutUserId

[int]
$CheckOutIntervalMinutes

[int]
$CheckOutMinutesRemaining

[int]
$FolderId

[string]
$FolderName

[int]
$Id

[boolean]
$IsActive

[boolean]
$IsCheckedOut

[boolean]
$IsCheckedOutByCurrentUser

[boolean]
$PasswordChangePending

[string]
$Role

[string]
$SecretName

[ValidateSet('None','RequiresApproval','RequiresCheckout','RequiresComment','RequiresDoubleLockPassword','CreateDoubleLockPassword','DoubleLockNoAccess','CannotView','RequiresUndelete','RequiresCheckoutPendingRPC','RequiresCheckoutAndComment')]
[string]
$SecretState

[System.String[]] GetActions() {
if ($this.Actions) {
$sortedActions = $this.Actions | Sort-Object
return $sortedActions
} else {
return "No Actions found"
}
}
}
67 changes: 67 additions & 0 deletions src/en-us/about_tsssecretdetailstate.help.txt
@@ -0,0 +1,67 @@
TOPIC
This help topic describes the TssSecretDetailState class in the Thycotic.SecretServer module

CLASS
TssSecretDetailActionType

INHERITANCE
None

DESCRIPTION
The TssSecretDetailActionType class represents the SecretDetao;StateViewModel returned by Secret Server endpoint GET /secrets/{id}/state

CONSTRUCTORS
new()

PROPERTIES
Actions [TssSecretDetailActionType]
Allowed actions for the current user

CheckedOutUserDisplayName
Display Name of User that has the secret checked out

CheckedOutUserId
User Secret is checked out to

CheckOutIntervalMinutes
Number of minutes before checkout

CheckOutMinutesRemaining
Minutes remaining in check out

FolderId
Folder Id

FolderName
Folder Name

Id
Secret Id

IsActive
Active

IsCheckedOut
Is the Secret checked out

IsCheckedOutByCurrentUser
Indicates whether the Secret is checked out by the current user

PasswordChangePending
Pending Password change on secret indicator

Role
Role that current user has on Secret

SecretName
Secret Name

SecretState
Current State of the Secret

METHODS
[System.String[]] GetActions()
Returns the Actions, sorted

RELATED LINKS:
Get-TssSecretState
67 changes: 67 additions & 0 deletions src/functions/secrets/Get-SecretState.ps1
@@ -0,0 +1,67 @@
function Get-SecretState {
<#
.SYNOPSIS
Get details on state of the Secret
.DESCRIPTION
Get details on state (requires checkout, restricted actions, etc) of the Secret
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssSecretState -TssSession $session -Id 42
Add minimum example for each parameter
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/Get-TssSecretState
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('TssSecretDetailState')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[TssSession]
$TssSession,

# Short description for parameter
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias("SecretId")]
[int[]]
$Id
)
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
foreach ($secret in $Id) {
$restResponse = $null
$uri = $TssSession.ApiUrl, 'secrets', $secret, 'state' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "Performing the operation $($invokeParams.Method) $uri"
try {
$restResponse = Invoke-TssRestApi @invokeParams
} catch {
Write-Warning "Issue getting state for secret [$secret]"
$err = $_
. $ErrorHandling $err
}

if ($restResponse) {
. $TssSecretDetailStateObject $restResponse
}
}
} else {
Write-Warning "No valid session found"
}
}
}
27 changes: 27 additions & 0 deletions src/parts/TssSecretDetailStateObject.ps1
@@ -0,0 +1,27 @@
<#
.Synopsis
Creates a TssSecretDetailState object
#>
param(
[pscustomobject]$Object
)

begin {
$Properties = $Object[0].PSObject.Properties.Name
}

process {
$outObject = @()
foreach ($p in $Object) {
$currentObject = [TssSecretDetailState]::new()
foreach ($pProp in $Properties) {
if ($pProp -in $currentObject.PSObject.Properties.Name) {
$currentObject.$pProp = $p.$pProp
} else {
Write-Warning "Property $pProp does not exist in the TssSecretDetailState class.thycotic-ps/thycotic.secretserver/issues/new/choose"
}
}
$outObject += $currentObject
}
return $outObject
}
25 changes: 25 additions & 0 deletions tests/secrets/Get-TssSecretState.Tests.ps1
@@ -0,0 +1,25 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
. ([IO.Path]::Combine([string]$PSScriptRoot, '..', 'constants.ps1'))
}
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 TssSecretDetailState" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'TssSecretDetailState'
}
}
}

0 comments on commit 357df13

Please sign in to comment.