Skip to content

Commit

Permalink
Search-TssAutoExportStorage - new command
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Aug 23, 2021
1 parent 10f04c2 commit 40aa723
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 4 deletions.
Expand Up @@ -52,7 +52,7 @@ Requires TssSession object returned by New-TssSession

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/configuration/Get-TssConfigurationSecretIndexer](https://thycotic-ps.github.io/thycotic.secretserver/commands/configuration/Get-TssConfigurationSecretIndexer)
[https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Get-TssConfigurationSecretIndexer](https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Get-TssConfigurationSecretIndexer)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configuration/Get-TssConfigurationSecretIndexer.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configuration/Get-TssConfigurationSecretIndexer.ps1)
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Get-TssConfigurationSecretIndexer.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Get-TssConfigurationSecretIndexer.ps1)

58 changes: 58 additions & 0 deletions docs/commands/configurations/Search-TssAutoExportStorage.md
@@ -0,0 +1,58 @@
# Search-TssAutoExportStorage

## SYNOPSIS
Search list of items in Automatic Export Storage

## SYNTAX

```
Search-TssAutoExportStorage [-TssSession] <Session> [<CommonParameters>]
```

## DESCRIPTION
Search list of items in Automatic Export Storage

## EXAMPLES

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

Returns a list of items in Automatic Export Storage

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

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Search-TssAutoExportStorage](https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Search-TssAutoExportStorage)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Search-TssAutoExportStorage.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Search-TssAutoExportStorage.ps1)

@@ -0,0 +1,16 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.Configuration
{
public class AutomaticExportItem
{
public int AutoExportConfigurationId {get;set;}
public bool CanDownload {get;set;}
public string Filename {get;set;}
public int Id {get;set;}
public DateTime? StorageDate {get;set;}
}
}
Expand Up @@ -13,10 +13,10 @@ function Get-TssConfigurationSecretIndexer {
Return configuration of the Secret Search Indexer
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/configuration/Get-TssConfigurationSecretIndexer
https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Get-TssConfigurationSecretIndexer
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configuration/Get-TssConfigurationSecretIndexer.ps1
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Get-TssConfigurationSecretIndexer.ps1
.NOTES
Requires TssSession object returned by New-TssSession
Expand Down
65 changes: 65 additions & 0 deletions src/functions/configurations/Search-TssAutoExportStorage.ps1
@@ -0,0 +1,65 @@
function Search-TssAutoExportStorage {
<#
.SYNOPSIS
Search list of items in Automatic Export Storage
.DESCRIPTION
Search list of items in Automatic Export Storage
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/configurations/Search-TssAutoExportStorage
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/configurations/Search-TssAutoExportStorage.ps1
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Search-TssAutoExportStorage -TssSession $session
Returns a list of items in Automatic Export Storage
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.Configuration.AutomaticExportItem')]
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, 'configuration', 'auto-export-storage' -join '/'
$uri = $uri, "sortBy[0].direction=desc&sortBy[0].name=Id&take=$($TssSession.Take)" -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 on search request"
$err = $_
. $ErrorHandling $err
}

if ($restResponse.records.Count -le 0 -and $restResponse.records.Length -eq 0) {
Write-Warning "No AutomaticStorage found"
}
if ($restResponse.records) {
[Thycotic.PowerShell.Configuration.AutomaticExportItem[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/configurations/Search-TssAutoExportStorage.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'SortBy'
[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.Configuration.AutomaticExportItem" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.Configuration.AutomaticExportItem'
}
}
}

0 comments on commit 40aa723

Please sign in to comment.