diff --git a/src/functions/Disable-TssSecret.ps1 b/src/functions/Disable-TssSecret.ps1 index 96bdfde5..b3ebe58d 100644 --- a/src/functions/Disable-TssSecret.ps1 +++ b/src/functions/Disable-TssSecret.ps1 @@ -6,15 +6,6 @@ .DESCRIPTION Disables a secret from Secret Server - .PARAMETER TssSession - TssSession object created by New-TssSession - - .PARAMETER Id - Secret ID to disable (mark inactive) - - .PARAMETER Raw - Output the raw response from the REST API endpoint - .EXAMPLE PS C:\> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred PS C:\> Disable-TssSecret -Id 93 @@ -26,19 +17,19 @@ #> [cmdletbinding(SupportsShouldProcess)] param( - # TssSession object passed for auth info + # TssSession object created by New-TssSession for auth [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [TssSession]$TssSession, - # Delete only specific Secret, Secret Id + # Secret ID to disable (mark inactive) [Parameter(Mandatory,ValueFromPipelineByPropertyName)] [Alias("SecretId")] [int[]] $Id, - # output the raw response from the API endpoint + # Output the raw response from the REST API endpoint [switch] $Raw ) @@ -58,7 +49,13 @@ $invokeParams.Method = 'DELETE' if (-not $PSCmdlet.ShouldProcess("$($invokeParams.Method) $uri")) { return } - $restResponse = Invoke-TssRestApi @invokeParams + try { + $restResponse = Invoke-TssRestApi @invokeParams + } catch { + Write-Warning "Issue disabling secret [$secret]" + $err = $_.ErrorDetails.Message + Write-Error $err + } if ($tssParams['Raw']) { return $restResponse diff --git a/src/functions/Get-TssFolder.ps1 b/src/functions/Get-TssFolder.ps1 index 65d9a0dc..a94bfc86 100644 --- a/src/functions/Get-TssFolder.ps1 +++ b/src/functions/Get-TssFolder.ps1 @@ -6,21 +6,6 @@ .DESCRIPTION Get a folder(s) from Secret Server - .PARAMETER TssSession - TssSession object created by New-TssSession - - .PARAMETER Id - Folder ID to retrieve, accepts an array of IDs - - .PARAMETER Recurse - Retrieve all child folders within the requested folder - - .PARAMETER IncludeTemplates - Include allowable Secret Templates of the requested folder - - .PARAMETER Raw - Output the raw response from the REST API endpoint - .EXAMPLE PS C:\> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred PS C:\> Get-TssFolder -TssSession $session -Id 4 @@ -45,31 +30,31 @@ [cmdletbinding()] [OutputType('TssFolder')] param( - # TssSession object passed for auth info + # TssSession object created by New-TssSession for auth [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [TssSession]$TssSession, - # Return only specific Secret, Secret Id + # Folder ID to retrieve [Parameter(Mandatory,ValueFromPipelineByPropertyName)] [Alias("FolderId")] [int[]] $Id, - # get all children folders + # Retrieve all child folders within the requested folder [Parameter(ParameterSetName = 'filter')] [Alias("GetAllChildren")] [switch] $Recurse, - # Get associated templates + # Include allowable Secret Templates of the requested folder [Parameter(ParameterSetName = 'filter')] [Alias("IncludeAssociatedTemplates")] [switch] $IncludeTemplates, - # output the raw response from the API endpoint + # Output the raw response from the REST API endpoint [switch] $Raw ) @@ -89,7 +74,13 @@ $invokeParams.Method = 'GET' $invokeParams.PersonalAccessToken = $TssSession.AccessToken - $restResponse = Invoke-TssRestApi @invokeParams + try { + $restResponse = Invoke-TssRestApi @invokeParams + } catch { + Write-Warning "Issue getting folder [$folder]" + $err = $_.ErrorDetails.Message + Write-Error $err + } if ($tssParams['Raw']) { return $restResponse diff --git a/src/functions/Get-TssSecret.ps1 b/src/functions/Get-TssSecret.ps1 index f3669510..be78e36d 100644 --- a/src/functions/Get-TssSecret.ps1 +++ b/src/functions/Get-TssSecret.ps1 @@ -6,18 +6,6 @@ .DESCRIPTION Get a secret(s) from Secret Server - .PARAMETER TssSession - TssSession object created by New-TssSession - - .PARAMETER Id - Secret ID to retrieve, accepts an array of IDs - - .PARAMETER Comment - Comment to provide for restricted secret (Require Comment is enabled) - - .PARAMETER Raw - Output the raw response from the REST API endpoint - .EXAMPLE PS C:\> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred PS C:\> Get-TssSecret -TssSession $session -Id 93 @@ -43,23 +31,23 @@ [cmdletbinding()] [OutputType('TssSecret')] param( - # TssSession object passed for auth info + # TssSession object created by New-TssSession for auth [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [TssSession]$TssSession, - # Return only specific Secret, Secret Id + # Secret ID to retrieve [Parameter(Mandatory,ValueFromPipelineByPropertyName)] [Alias("SecretId")] [int[]] $Id, - # Provide comment for restricted secret + # Comment to provide for restricted secret (Require Comment is enabled) [string] $Comment, - # output the raw response from the API endpoint + # Output the raw response from the REST API endpoint [switch] $Raw ) @@ -86,7 +74,13 @@ } $invokeParams.PersonalAccessToken = $TssSession.AccessToken - $restResponse = Invoke-TssRestApi @invokeParams + try { + $restResponse = Invoke-TssRestApi @invokeParams + } catch { + Write-Warning "Issue getting secret [$secret]" + $err = $_.ErrorDetails.Message + Write-Error $err + } if ($tssParams['Raw']) { return $restResponse diff --git a/src/functions/Get-TssSecretTemplate.ps1 b/src/functions/Get-TssSecretTemplate.ps1 index 01685df3..2903c016 100644 --- a/src/functions/Get-TssSecretTemplate.ps1 +++ b/src/functions/Get-TssSecretTemplate.ps1 @@ -6,15 +6,6 @@ .DESCRIPTION Get a secret template(s) from Secret Server - .PARAMETER TssSession - TssSession object created by New-TssSession - - .PARAMETER Id - Secret template ID to retrieve, accepts an array of IDs - - .PARAMETER Raw - Output the raw response from the REST API endpoint - .EXAMPLE PS C:\> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred PS C:\> Get-TssSecretTemplate -Id 93 @@ -26,19 +17,19 @@ #> [cmdletbinding()] param( - # TssSession object passed for auth info + # TssSession object created by New-TssSession for auth [Parameter(Mandatory, ValueFromPipeline, Position = 0)] [TssSession]$TssSession, - # Return only specific Secret, Secret Id + # Secret template ID to retrieve [Parameter(Mandatory,ValueFromPipelineByPropertyName)] [Alias("TemplateId")] [int[]] $Id, - # output the raw response from the API endpoint + # Output the raw response from the REST API endpoint [switch] $Raw ) @@ -57,7 +48,13 @@ $invokeParams.PersonalAccessToken = $TssSession.AccessToken Write-Verbose "$($invokeParas.Method) $uri with $body" - $restResponse = Invoke-TssRestApi @invokeParams + try { + $restResponse = Invoke-TssRestApi @invokeParams + } catch { + Write-Warning "Issue getting template [$template]" + $err = $_.ErrorDetails.Message + Write-Error $err + } if ($tssParams['Raw']) { return $restResponse diff --git a/src/functions/Invoke-TssRestApi.ps1 b/src/functions/Invoke-TssRestApi.ps1 index b6b5c9c1..55c24484 100644 --- a/src/functions/Invoke-TssRestApi.ps1 +++ b/src/functions/Invoke-TssRestApi.ps1 @@ -13,27 +13,25 @@ #> [Cmdletbinding()] param( - # The REST API Url + # Secret Server REST API URL [Parameter(Mandatory,ValueFromPipelineByPropertyName)] [Alias('Url')] [uri] $Uri, - # A Personal Access Token + # Valid Access Token issued by Secret Server [Parameter(ValueFromPipelineByPropertyName)] [Alias('PAT')] [string] $PersonalAccessToken, - # Specifies the method used for the web request + # Method used for the web request, supported by Secret Server [Parameter(ValueFromPipelineByPropertyName)] [ValidateSet('GET','DELETE', 'PATCH', 'POST', 'PUT')] [string] $Method, # Specifies the body of the request. - # If this value is a string, it will be passed as-is - # Otherwise, this value will be converted into JSON. [Parameter(ValueFromPipelineByPropertyName)] [Object] $Body, @@ -43,12 +41,12 @@ [string] $ContentType = 'application/json', - # Specifies the headers of the web request. Enter a hash table or dictionary. + # Header of the web request. Enter a hash table or dictionary. [System.Collections.IDictionary] [Alias('Header')] $Headers, - # Indicates that the cmdlet uses the credentials of the current user to send the web request (winauth). + # Indicates using the credentials of the current user to send the web request (winauth). [Alias('UseDefaultCredential')] [switch] $UseDefaultCredentials, @@ -69,7 +67,7 @@ [switch] $ProxyUseDefaultCredentials, - # The typename of the results. + # Output a custom type name for the results. [Parameter(ValueFromPipelineByPropertyName)] [string[]] $PSTypeName, @@ -83,7 +81,7 @@ [string[]] $RemoveProperty, - # If provided, will expand a given property returned from the REST api. + # Expand a given property from an object [string] $ExpandProperty ) diff --git a/src/functions/New-TssSession.ps1 b/src/functions/New-TssSession.ps1 index 68a014b4..9f1441e8 100644 --- a/src/functions/New-TssSession.ps1 +++ b/src/functions/New-TssSession.ps1 @@ -41,9 +41,7 @@ [cmdletbinding(SupportsShouldProcess)] param( # Secret Server URL - [Parameter(ParameterSetName = 'New', - Mandatory, - HelpMessage = 'URL for Secret Server, e.g. https://vault.company.com/SecretServer')] + [Parameter(ParameterSetName = 'New',Mandatory)] [Parameter(ParameterSetName = 'tss', Mandatory)] [Alias('Server')] @@ -70,8 +68,6 @@ begin { $invokeParams = . $GetInvokeTssParams $PSBoundParameters $newTssParams = . $GetNewTssParams $PSBoundParameters - - # $TssSession = [TssSession]::new() } process { diff --git a/src/functions/Search-TssSecret.ps1 b/src/functions/Search-TssSecret.ps1 index d1dc6080..9f9bba5b 100644 --- a/src/functions/Search-TssSecret.ps1 +++ b/src/functions/Search-TssSecret.ps1 @@ -6,36 +6,6 @@ .DESCRIPTION Search for secrets using various filters provided by each parameter - .PARAMETER TssSession - TssSession object created by New-TssSession - - .PARAMETER FolderId - Folder ID to search, allows multiple - - .PARAMETER SecretTemplateId - Template ID to search, allows multiple - - .PARAMETER SiteId - Site ID to filter on, allows multiple - - .PARAMETER HeartbeatStatus - Heartbeat status to filter on - - .PARAMETER SearchField - Field to filter on - - .PARAMETER SearchText - Field value to filter on - - .PARAMETER SearchSlug - Slug name of field to filter on - - .PARAMETER IncludeInactive - Include inactive or disabled Secrets - - .PARAMETER Raw - Output the raw response from the REST API endpoint - .EXAMPLE PS C:\> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred PS C:\> Search-TssSecret -TssSession $session -FolderId 50 @@ -59,7 +29,7 @@ #> [cmdletbinding(DefaultParameterSetName = "filter")] param( - # TssSession object passed for auth info + # TssSession object created by New-TssSession for auth [Parameter(Mandatory, ValueFromPipeline, Position = 0)] @@ -87,27 +57,29 @@ [string] $HeartbeatStatus, + # Search text of a specific field [Parameter(ParameterSetName = "field")] [string] $SearchField, - # Search text value for field + # Search text of the provided field [Parameter(ParameterSetName = "field")] [string] $SearchText, - # Field-slug to search. This Roverride SearchField. + # Field slug to search + # This overrides the SearchField [Parameter(ParameterSetName = "field")] [string] $SearchSlug, - # Include inactive or disabled secrets + # Include inactive/disabled secrets [Parameter(ParameterSetName = "field")] [Parameter(ParameterSetName = "filter")] [switch] $IncludeInactive, - # output the raw response from the API endpoint + # Output the raw response from the REST API endpoint [switch] $Raw ) @@ -139,7 +111,13 @@ $invokeParams.Method = 'GET' Write-Verbose "$($invokeParams.Method) $uri with $body" - $restResponse = Invoke-TssRestApi @invokeParams + try { + $restResponse = Invoke-TssRestApi @invokeParams + } catch { + Write-Warning "Issue on search request" + $err = $_.ErrorDetails.Message + Write-Error $err + } if ($searchParams['Raw']) { return $restResponse